Skip to content

Commit c33e323

Browse files
committed
MC-5691: Implement better developer error reporting
- Resolve issue with appearance switching on content types
1 parent 581eb07 commit c33e323

File tree

2 files changed

+45
-36
lines changed
  • app/code/Magento/PageBuilder/view/adminhtml/web

2 files changed

+45
-36
lines changed

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

Lines changed: 21 additions & 21 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: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export default class Preview {
4242
public placeholderCss: KnockoutObservable<object>;
4343
public isPlaceholderVisible: KnockoutObservable<boolean> = ko.observable(true);
4444
public isEmpty: KnockoutObservable<boolean> = ko.observable(true);
45+
public previewTemplate: KnockoutObservable<string> = ko.observable();
4546

4647
/**
4748
* @deprecated
@@ -83,25 +84,11 @@ export default class Preview {
8384
"visible": this.isEmpty,
8485
"empty-placeholder-background": this.isPlaceholderVisible,
8586
});
87+
this.previewTemplate(this.getPreviewTemplate());
8688
this.setupDataFields();
8789
this.bindEvents();
8890
}
8991

90-
/**
91-
* Retrieve the preview template
92-
*
93-
* @returns {string}
94-
*/
95-
get previewTemplate(): string {
96-
const appearance = this.parent.dataStore.get("appearance") ?
97-
this.parent.dataStore.get("appearance").toString() : undefined;
98-
99-
return appearanceConfig(
100-
this.config.name,
101-
appearance
102-
).preview_template;
103-
}
104-
10592
/**
10693
* Calls methods by event name.
10794
*
@@ -501,8 +488,15 @@ export default class Preview {
501488
this.updatePlaceholderVisibility(data);
502489
// Keep a reference to the display state in an observable for adding classes to the wrapper
503490
this.display(!!data.display);
491+
504492
},
505493
);
494+
495+
// If the appearance of the content type changes, update the preview template
496+
this.parent.dataStore.subscribe(() => {
497+
this.previewTemplate(this.getPreviewTemplate());
498+
}, "appearance");
499+
506500
if (this.parent instanceof ContentTypeCollection) {
507501
this.parent.children.subscribe(
508502
(children: any[]) => {
@@ -579,6 +573,21 @@ export default class Preview {
579573
return hasDataChanges;
580574
}
581575

576+
/**
577+
* Retrieve the preview template
578+
*
579+
* @returns {string}
580+
*/
581+
private getPreviewTemplate() {
582+
const appearance = this.parent.dataStore.get("appearance") ?
583+
this.parent.dataStore.get("appearance").toString() : undefined;
584+
585+
return appearanceConfig(
586+
this.config.name,
587+
appearance
588+
).preview_template;
589+
}
590+
582591
/**
583592
* Any hidden element should block drag / drop events from uploading images from the OS. We have to block this for
584593
* all elements as underlying elements could still receive the events if a parent is hidden.

0 commit comments

Comments
 (0)