Skip to content

Commit 214355f

Browse files
committed
Merge branch 'MC-1420' of github.com:magento-trigger/magento2-page-builder into MC-1420
2 parents 6d6869a + 2f9afaa commit 214355f

File tree

2 files changed

+43
-5
lines changed
  • app/code/Magento/PageBuilder/view/adminhtml/web

2 files changed

+43
-5
lines changed

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

Lines changed: 21 additions & 2 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/block/preview.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ import BasePreview from "../preview";
1717
export default class Preview extends BasePreview {
1818
public displayPreview: KnockoutObservable<boolean> = ko.observable(false);
1919
public placeholderText: KnockoutObservable<string>;
20+
private lastBlockId: number;
21+
private lastTemplate: string;
22+
private lastRenderedHtml: string;
2023
private messages = {
2124
NOT_SELECTED: $t("Empty Block"),
2225
LOADING: $t("Loading..."),
@@ -57,17 +60,29 @@ export default class Preview extends BasePreview {
5760
protected afterObservablesUpdated(): void {
5861
super.afterObservablesUpdated();
5962

60-
this.placeholderText(this.messages.LOADING);
61-
this.displayPreview(false);
62-
6363
const data = this.parent.dataStore.get();
6464

65+
// Only load if something changed
66+
if (this.lastBlockId === data.block_id && this.lastTemplate === data.template) {
67+
// The mass converter will have transformed the HTML property into a directive
68+
if (this.lastRenderedHtml) {
69+
this.data.main.html(this.lastRenderedHtml);
70+
this.displayPreview(true);
71+
}
72+
73+
return;
74+
}
75+
76+
this.displayPreview(false);
77+
6578
if (!data.block_id || data.template.length === 0) {
6679
this.placeholderText(this.messages.NOT_SELECTED);
6780

6881
return;
6982
}
7083

84+
this.placeholderText(this.messages.LOADING);
85+
7186
const url = Config.getConfig("preview_url");
7287
const requestConfig = {
7388
// Prevent caching
@@ -99,6 +114,10 @@ export default class Preview extends BasePreview {
99114
} else if (response.data.error) {
100115
this.placeholderText(response.data.error);
101116
}
117+
118+
this.lastBlockId = data.block_id;
119+
this.lastTemplate = data.template;
120+
this.lastRenderedHtml = response.data.content;
102121
})
103122
.fail(() => {
104123
this.placeholderText(this.messages.UNKNOWN_ERROR);

0 commit comments

Comments
 (0)