Skip to content

Commit 6aae682

Browse files
authored
Merge pull request #393 from magento-obsessive-owls/PB-419
[Owls] PB-419: Resolve BiC change within content type toolbar
2 parents 3c58e51 + 594daf4 commit 6aae682

File tree

2 files changed

+104
-1
lines changed
  • app/code/Magento/PageBuilder/view/adminhtml/web

2 files changed

+104
-1
lines changed

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

Lines changed: 53 additions & 0 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: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import "../binding/sortable";
1414
import "../binding/sortable-children";
1515
import ContentTypeCollection from "../content-type-collection";
1616
import ContentTypeCollectionInterface from "../content-type-collection.types";
17-
import ContentTypeConfigInterface from "../content-type-config.types";
17+
import ContentTypeConfigInterface, {ConfigFieldInterface} from "../content-type-config.types";
1818
import createContentType from "../content-type-factory";
1919
import ContentTypeMenu from "../content-type-menu";
2020
import Edit from "../content-type-menu/edit";
@@ -46,6 +46,13 @@ export default class Preview implements PreviewInterface {
4646
public isPlaceholderVisible: KnockoutObservable<boolean> = ko.observable(true);
4747
public isEmpty: KnockoutObservable<boolean> = ko.observable(true);
4848

49+
/**
50+
* Provide preview data as an object which can be queried
51+
*
52+
* @deprecated please use getOptionValue directly
53+
*/
54+
public previewData: {[key: string]: KnockoutObservable<any>} = {};
55+
4956
/**
5057
* Fields that should not be considered when evaluating whether an object has been configured.
5158
*
@@ -82,6 +89,7 @@ export default class Preview implements PreviewInterface {
8289
"empty-placeholder-background": this.isPlaceholderVisible,
8390
});
8491
this.bindEvents();
92+
this.populatePreviewData();
8593
}
8694

8795
/**
@@ -144,6 +152,15 @@ export default class Preview implements PreviewInterface {
144152
this.contentType.dataStore.set(key, value);
145153
}
146154

155+
/**
156+
* Retrieve the value for an option
157+
*
158+
* @param key
159+
*/
160+
public getOptionValue(key: string) {
161+
return this.contentType.dataStore.get(key);
162+
}
163+
147164
/**
148165
* Set state based on mouseover event for the preview
149166
*
@@ -581,4 +598,37 @@ export default class Preview implements PreviewInterface {
581598

582599
this.isPlaceholderVisible(paddingBottom + paddingTop + minHeight >= 130);
583600
}
601+
602+
/**
603+
* Populate the preview data with calls to the supported getOptionValue method
604+
*
605+
* @deprecated this function is only included to preserve backwards compatibility, use getOptionValue directly
606+
*/
607+
private populatePreviewData(): void {
608+
if (this.config.fields) {
609+
_.each(this.config.fields, (fields) => {
610+
_.keys(fields).forEach((key: string) => {
611+
this.previewData[key] = ko.observable("");
612+
});
613+
});
614+
}
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+
);
633+
}
584634
}

0 commit comments

Comments
 (0)