Skip to content

Commit 28a4b63

Browse files
committed
MC-2333: UX Review
- Reworked block stage preview states
1 parent 2f9afaa commit 28a4b63

File tree

3 files changed

+55
-12
lines changed

3 files changed

+55
-12
lines changed

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

Lines changed: 26 additions & 6 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/template/content-type/block/default/preview.html

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,16 @@
88
<div class="pagebuilder-content-type pagebuilder-block" event="{ mouseover: onMouseOver, mouseout: onMouseOut }, mouseoverBubble: false">
99
<div attr="data.main.attributes" ko-style="data.main.style" css="data.main.css">
1010
<div if="displayPreview" class="rendered-content" html="data.main.html"></div>
11-
<div ifnot="displayPreview" class="pagebuilder-block-placeholder">
11+
<div if="displayPlaceholder" class="pagebuilder-block-placeholder">
1212
<span class="placeholder-text" text="placeholderText"/>
1313
</div>
1414
</div>
15+
<div data-role="spinner"
16+
class="admin__data-grid-loading-mask"
17+
if="loading">
18+
<div class="spinner">
19+
<span repeat="8"/>
20+
</div>
21+
</div>
1522
<render args="getOptions().template" />
1623
</div>

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

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ import BasePreview from "../preview";
1616

1717
export default class Preview extends BasePreview {
1818
public displayPreview: KnockoutObservable<boolean> = ko.observable(false);
19+
public displayPlaceholder: KnockoutObservable<boolean> = ko.observable(false);
20+
public loading: KnockoutObservable<boolean> = ko.observable(false);
1921
public placeholderText: KnockoutObservable<string>;
2022
private lastBlockId: number;
2123
private lastTemplate: string;
2224
private lastRenderedHtml: string;
2325
private messages = {
2426
NOT_SELECTED: $t("Empty Block"),
25-
LOADING: $t("Loading..."),
2627
UNKNOWN_ERROR: $t("An unknown error occurred. Please try again."),
2728
};
2829

@@ -68,20 +69,25 @@ export default class Preview extends BasePreview {
6869
if (this.lastRenderedHtml) {
6970
this.data.main.html(this.lastRenderedHtml);
7071
this.displayPreview(true);
72+
this.displayPlaceholder(false);
7173
}
72-
73-
return;
74+
}
75+
else {
76+
this.displayPreview(false);
77+
this.displayPlaceholder(true);
78+
this.placeholderText("");
7479
}
7580

76-
this.displayPreview(false);
7781

7882
if (!data.block_id || data.template.length === 0) {
83+
this.displayPreview(false);
84+
this.displayPlaceholder(true);
7985
this.placeholderText(this.messages.NOT_SELECTED);
8086

8187
return;
8288
}
8389

84-
this.placeholderText(this.messages.LOADING);
90+
this.loading(true);
8591

8692
const url = Config.getConfig("preview_url");
8793
const requestConfig = {
@@ -100,6 +106,8 @@ export default class Preview extends BasePreview {
100106
.done((response) => {
101107
// Empty content means something bad happened in the controller that didn't trigger a 5xx
102108
if (typeof response.data !== "object") {
109+
this.displayPreview(false);
110+
this.displayPlaceholder(true);
103111
this.placeholderText(this.messages.UNKNOWN_ERROR);
104112

105113
return;
@@ -110,8 +118,11 @@ export default class Preview extends BasePreview {
110118

111119
if (response.data.content) {
112120
this.displayPreview(true);
121+
this.displayPlaceholder(false);
113122
this.data.main.html(response.data.content);
114123
} else if (response.data.error) {
124+
this.displayPreview(false);
125+
this.displayPlaceholder(true);
115126
this.placeholderText(response.data.error);
116127
}
117128

@@ -120,7 +131,12 @@ export default class Preview extends BasePreview {
120131
this.lastRenderedHtml = response.data.content;
121132
})
122133
.fail(() => {
134+
this.displayPreview(false);
135+
this.displayPlaceholder(true);
123136
this.placeholderText(this.messages.UNKNOWN_ERROR);
137+
})
138+
.always(() => {
139+
this.loading(false);
124140
});
125141
}
126142
}

0 commit comments

Comments
 (0)