Skip to content

Commit fb94aeb

Browse files
author
Hwashiang Yu
committed
MC-4057: Fix attached mftf skipped tests
- Updated logic to check for panel state for onScroll event
1 parent 388ba66 commit fb94aeb

File tree

2 files changed

+53
-65
lines changed

2 files changed

+53
-65
lines changed

app/code/Magento/PageBuilder/view/adminhtml/web/js/panel.js

Lines changed: 29 additions & 35 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/panel.ts

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import {ContentType as GroupContentType} from "./panel/group/content-type";
2222
* @api
2323
*/
2424
export default class Panel implements PanelInterface {
25-
public stageReady: KnockoutObservable<boolean> = ko.observable(false);
2625
public groups: KnockoutObservableArray<any> = ko.observableArray([]);
2726
public searchResults: KnockoutObservableArray<any> = ko.observableArray([]);
2827
public isCollapsed: KnockoutObservable<boolean> = ko.observable(false);
@@ -53,13 +52,6 @@ export default class Panel implements PanelInterface {
5352
*/
5453
public afterRender(element: Element): void {
5554
this.element = element;
56-
this.stageReady.subscribe(
57-
(data: boolean) => {
58-
if (data) {
59-
this.onScroll();
60-
}
61-
},
62-
);
6355
}
6456

6557
/**
@@ -68,7 +60,7 @@ export default class Panel implements PanelInterface {
6860
public initListeners(): void {
6961
events.on("stage:" + this.id + ":readyAfter", () => {
7062
this.populateContentTypes();
71-
this.stageReady(true);
63+
this.onScroll();
7264
this.isVisible(true);
7365
});
7466
}
@@ -148,34 +140,36 @@ export default class Panel implements PanelInterface {
148140
const panel = $(this.element);
149141
const stage = panel.siblings(".pagebuilder-stage");
150142
$(window).scroll(function() {
151-
const panelOffsetTop = panel.offset().top;
152-
const stageOffsetTop = stage.offset().top;
153-
const panelHeight = panel.outerHeight();
154-
const stageHeight = stage.outerHeight();
155-
const currentPanelBottom = Math.round(panelOffsetTop + panel.outerHeight(true) - $(this).scrollTop());
156-
const currentStageBottom = Math.round(stageOffsetTop + stage.outerHeight(true) - $(this).scrollTop());
157-
const currentPanelTop = Math.round(panelOffsetTop - $(this).scrollTop());
158-
const currentStageTop = Math.round(stageOffsetTop - $(this).scrollTop());
159-
// When panel height is less than stage, begin stickiness
160-
if (panelHeight <= stageHeight && pageActions.hasClass("_fixed")) {
161-
const pageActionsHeight = pageActions.outerHeight() + 15;
162-
// When scroll reaches top of stage, stick panel to top
163-
if (currentStageTop <= pageActionsHeight) {
164-
// When panel reaches bottom of stage, stick panel to bottom of stage
165-
if (currentPanelBottom >= currentStageBottom && currentPanelTop <= pageActionsHeight) {
166-
self.isStickyBottom(true);
167-
self.isStickyTop(false);
143+
if (panel && panel.offset()) {
144+
const panelOffsetTop = panel.offset().top;
145+
const stageOffsetTop = stage.offset().top;
146+
const panelHeight = panel.outerHeight();
147+
const stageHeight = stage.outerHeight();
148+
const currentPanelBottom = Math.round(panelOffsetTop + panel.outerHeight(true) - $(this).scrollTop());
149+
const currentStageBottom = Math.round(stageOffsetTop + stage.outerHeight(true) - $(this).scrollTop());
150+
const currentPanelTop = Math.round(panelOffsetTop - $(this).scrollTop());
151+
const currentStageTop = Math.round(stageOffsetTop - $(this).scrollTop());
152+
// When panel height is less than stage, begin stickiness
153+
if (panelHeight <= stageHeight && pageActions.hasClass("_fixed")) {
154+
const pageActionsHeight = pageActions.outerHeight() + 15;
155+
// When scroll reaches top of stage, stick panel to top
156+
if (currentStageTop <= pageActionsHeight) {
157+
// When panel reaches bottom of stage, stick panel to bottom of stage
158+
if (currentPanelBottom >= currentStageBottom && currentPanelTop <= pageActionsHeight) {
159+
self.isStickyBottom(true);
160+
self.isStickyTop(false);
161+
} else {
162+
self.isStickyBottom(false);
163+
self.isStickyTop(true);
164+
}
168165
} else {
169166
self.isStickyBottom(false);
170-
self.isStickyTop(true);
167+
self.isStickyTop(false);
171168
}
172169
} else {
173170
self.isStickyBottom(false);
174171
self.isStickyTop(false);
175172
}
176-
} else {
177-
self.isStickyBottom(false);
178-
self.isStickyTop(false);
179173
}
180174
});
181175
}

0 commit comments

Comments
 (0)