Skip to content

Commit 5eac7d3

Browse files
committed
PB-419: Resolve BiC change within content type toolbar
- Update observables on data changes
1 parent c74de06 commit 5eac7d3

File tree

2 files changed

+38
-13
lines changed
  • app/code/Magento/PageBuilder/view/adminhtml/web

2 files changed

+38
-13
lines changed

app/code/Magento/PageBuilder/view/adminhtml/web/js/content-type/preview.js

Lines changed: 18 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/code/Magento/PageBuilder/view/adminhtml/web/ts/js/content-type/preview.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export default class Preview implements PreviewInterface {
5151
*
5252
* @deprecated please use getOptionValue directly
5353
*/
54-
public previewData = {};
54+
public previewData: {[key: string]: KnockoutObservable<any>} = {};
5555

5656
/**
5757
* Fields that should not be considered when evaluating whether an object has been configured.
@@ -605,16 +605,30 @@ export default class Preview implements PreviewInterface {
605605
* @deprecated this function is only included to preserve backwards compatibility, use getOptionValue directly
606606
*/
607607
private populatePreviewData(): void {
608-
const response: {[key: string]: () => any} = {};
609608
if (this.config.fields) {
610609
_.each(this.config.fields, (fields) => {
611610
_.keys(fields).forEach((key: string) => {
612-
response[key] = () => {
613-
return this.getOptionValue(key);
614-
};
611+
this.previewData[key] = ko.observable("");
615612
});
616613
});
617614
}
618-
this.previewData = response;
615+
616+
// Subscribe to this content types data in the store
617+
this.contentType.dataStore.subscribe(
618+
(data: DataObject) => {
619+
_.forEach(data, (value, key) => {
620+
const optionValue = this.getOptionValue(key);
621+
if (ko.isObservable(this.previewData[key])) {
622+
this.previewData[key](optionValue);
623+
} else {
624+
if (_.isArray(optionValue)) {
625+
this.previewData[key] = ko.observableArray(optionValue);
626+
} else {
627+
this.previewData[key] = ko.observable(optionValue);
628+
}
629+
}
630+
});
631+
},
632+
);
619633
}
620634
}

0 commit comments

Comments
 (0)