Skip to content

Commit 3a19e5a

Browse files
committed
PB-108: Static test fixes for column-group preview.ts errors
1 parent 0c63179 commit 3a19e5a

File tree

2 files changed

+62
-63
lines changed
  • app/code/Magento/PageBuilder/view/adminhtml/web

2 files changed

+62
-63
lines changed

app/code/Magento/PageBuilder/view/adminhtml/web/css/source/content-type/column-group/_default.less

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
&.no-column-line {
2828
.element-children {
29-
display:flex;
29+
display: flex;
3030
}
3131
}
3232

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

Lines changed: 61 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,10 @@ export default class Preview extends PreviewCollection {
141141
events.on("column-group:renderAfter", (args: ContentTypeAfterRenderEventParamsInterface) => {
142142
if (args.contentType.id === this.contentType.id) {
143143
if (!this.hasColumnLine(args.contentType)) {
144-
args.element.classList.add('no-column-line');
144+
args.element.classList.add("no-column-line");
145145
} else {
146-
args.element.classList.remove('no-column-line');
147-
args.element.classList.add('with-column-line');
146+
args.element.classList.remove("no-column-line");
147+
args.element.classList.add("with-column-line");
148148
}
149149
}
150150
});
@@ -157,63 +157,6 @@ export default class Preview extends PreviewCollection {
157157
);
158158
}
159159

160-
/**
161-
* @param {ContentTypeInterface | ContentTypeCollectionInterface} contentType
162-
* @private
163-
*/
164-
private hasColumnLine(contentType: ContentTypeInterface | ContentTypeCollectionInterface): boolean {
165-
const children = this.contentType.getChildren()();
166-
let hasColumnLine = false;
167-
if (children.length === 0) {
168-
//new column group, so it has a column line
169-
hasColumnLine = true;
170-
}
171-
children.forEach((child) => {
172-
if (child.config.name === "column-line") {
173-
hasColumnLine = true;
174-
}
175-
});
176-
return hasColumnLine;
177-
}
178-
179-
180-
/**
181-
* If the column group does not have a column line, move contents to a new column group with a column line
182-
*/
183-
private moveContentsToNewColumnGroup(): void {
184-
if (this.hasColumnLine(this.contentType)) {
185-
// This column-group already has a column line. Don't need to add one.
186-
return;
187-
}
188-
const indexToInsertNewColumnGroupAt = this.getCurrentIndexInParent()
189-
createContentType(
190-
Config.getContentTypeConfig("column-group"),
191-
this.contentType.parentContentType,
192-
this.contentType.stageId,
193-
).then((columnGroup: ContentTypeCollectionInterface ) => {
194-
this.contentType.parentContentType.addChild(columnGroup, indexToInsertNewColumnGroupAt);
195-
events.trigger(columnGroup.config.name + ":dropAfter", {id: columnGroup.id, columnGroup,
196-
columnGroupWithoutColumnLine: this.contentType});
197-
this.fireMountEvent(this.contentType, columnGroup);
198-
});
199-
}
200-
201-
/**
202-
* @private return index of current content type in parent
203-
*/
204-
private getCurrentIndexInParent(): number {
205-
let parentContentType = this.contentType.parentContentType;
206-
let currentIndex = 0;
207-
for (let sibling of this.contentType.parentContentType.getChildren()()) {
208-
if (sibling.id != this.contentType.id) {
209-
currentIndex++;
210-
continue;
211-
}
212-
break;
213-
}
214-
return currentIndex;
215-
}
216-
217160
/**
218161
* Handle user editing an instance
219162
*/
@@ -294,7 +237,7 @@ export default class Preview extends PreviewCollection {
294237
this.contentType.addChild(columns[0], 0);
295238
this.contentType.addChild(columns[1], 1);
296239
this.fireMountEvent(this.contentType, columns[0], columns[1]);
297-
},
240+
},
298241
);
299242
}
300243

@@ -305,7 +248,7 @@ export default class Preview extends PreviewCollection {
305248
this.contentType.stageId,
306249
).then((columnLine: ContentTypeCollectionInterface ) => {
307250
this.contentType.addChild(columnLine, 0);
308-
if (args.columnGroupWithoutColumnLine == undefined) {
251+
if (args.columnGroupWithoutColumnLine === undefined) {
309252
events.trigger(columnLine.config.name + ":dropAfter", {id: columnLine.id, columnLine});
310253
} else {
311254
// Move children of this column group without column line as descendant of new
@@ -674,6 +617,62 @@ export default class Preview extends PreviewCollection {
674617
}
675618
}
676619

620+
/**
621+
* @param {ContentTypeInterface | ContentTypeCollectionInterface} contentType
622+
* @private
623+
*/
624+
private hasColumnLine(contentType: ContentTypeInterface | ContentTypeCollectionInterface): boolean {
625+
const children = this.contentType.getChildren()();
626+
let hasColumnLine = false;
627+
if (children.length === 0) {
628+
// new column group, so it has a column line
629+
hasColumnLine = true;
630+
}
631+
children.forEach((child) => {
632+
if (child.config.name === "column-line") {
633+
hasColumnLine = true;
634+
}
635+
});
636+
return hasColumnLine;
637+
}
638+
639+
/**
640+
* If the column group does not have a column line, move contents to a new column group with a column line
641+
*/
642+
private moveContentsToNewColumnGroup(): void {
643+
if (this.hasColumnLine(this.contentType)) {
644+
// This column-group already has a column line. Don't need to add one.
645+
return;
646+
}
647+
const indexToInsertNewColumnGroupAt = this.getCurrentIndexInParent();
648+
createContentType(
649+
Config.getContentTypeConfig("column-group"),
650+
this.contentType.parentContentType,
651+
this.contentType.stageId,
652+
).then((columnGroup: ContentTypeCollectionInterface ) => {
653+
this.contentType.parentContentType.addChild(columnGroup, indexToInsertNewColumnGroupAt);
654+
events.trigger(columnGroup.config.name + ":dropAfter", {id: columnGroup.id, columnGroup,
655+
columnGroupWithoutColumnLine: this.contentType});
656+
this.fireMountEvent(this.contentType, columnGroup);
657+
});
658+
}
659+
660+
/**
661+
* @private return index of current content type in parent
662+
*/
663+
private getCurrentIndexInParent(): number {
664+
const parentContentType = this.contentType.parentContentType;
665+
let currentIndex = 0;
666+
for (const sibling of this.contentType.parentContentType.getChildren()()) {
667+
if (sibling.id !== this.contentType.id) {
668+
currentIndex++;
669+
continue;
670+
}
671+
break;
672+
}
673+
return currentIndex;
674+
}
675+
677676
/**
678677
* Fire the mount event for content types
679678
*

0 commit comments

Comments
 (0)