Skip to content

Commit

Permalink
chore(contentful): new content cloners
Browse files Browse the repository at this point in the history
  • Loading branch information
dpinol committed Apr 27, 2020
1 parent 791c3ac commit 7b2d549
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ ij_typescript_use_double_quotes = false

[*.md]
trim_trailing_whitespace = false

[*.snap]
trim_trailing_whitespace = false
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"eslint-plugin-react": "^7.19.0",
"eslint-plugin-react-hooks": "^3.0.0",
"eslint_d": "^8.1.1",
"jest": "^25.2.7",
"jest": "^25.3.0",
"jest-each": "^25.1.0",
"lerna": "^3.19.0",
"prettier": "^2.0.4",
Expand Down
18 changes: 18 additions & 0 deletions packages/botonic-plugin-contentful/src/cms/contents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ export class Button extends Content {
}
return undefined
}

cloneWithText(newText: string): this {
const clone = shallowClone(this)
;(clone as any).text = newText
return clone
}
}

export class StartUp extends MessageContent {
Expand Down Expand Up @@ -177,6 +183,12 @@ export class Carousel extends MessageContent {
validate(): string | undefined {
return Content.validateContents(this.elements)
}

cloneWithElements(elements: Element[]): this {
const clone = shallowClone(this)
;(clone as any).elements = elements
return clone
}
}

/** Part of a carousel */
Expand All @@ -196,6 +208,12 @@ export class Element extends Content {
validate(): string | undefined {
return Content.validateContents(this.buttons)
}

cloneWithButtons(buttons: Button[]): this {
const clone = shallowClone(this)
;(clone as any).buttons = buttons
return clone
}
}

export class Image extends MessageContent {
Expand Down

0 comments on commit 7b2d549

Please sign in to comment.