Skip to content

Commit 01bb0f5

Browse files
committed
PB-108 retain column width when moving to another column line
1 parent 4f95ae0 commit 01bb0f5

File tree

2 files changed

+83
-14
lines changed
  • app/code/Magento/PageBuilder/view/adminhtml/web

2 files changed

+83
-14
lines changed

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

Lines changed: 45 additions & 7 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/column-line/preview.ts

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -340,16 +340,16 @@ export default class Preview extends PreviewCollection {
340340

341341
// Determine which old neighbour we should modify
342342
const oldWidth = sourceLinePreview.getResizeUtils().getColumnWidth(column);
343+
let direction = "+1";
343344

344345
// Retrieve the adjacent column either +1 or -1
345346
if (getAdjacentColumn(column, "+1")) {
346347
modifyOldNeighbour = getAdjacentColumn(column, "+1");
347348
} else if (getAdjacentColumn(column, "-1")) {
349+
direction = "-1";
348350
modifyOldNeighbour = getAdjacentColumn(column, "-1");
349351
}
350352

351-
// Set the column to it's smallest column width
352-
updateColumnWidth(column, this.resizeUtils.getSmallestColumnWidth());
353353
// Modify the old neighbour
354354
let oldNeighbourWidth = 100;
355355
if (modifyOldNeighbour) {
@@ -378,19 +378,50 @@ export default class Preview extends PreviewCollection {
378378

379379
});
380380
} else {
381-
// @todo evaluate if this else is needed
382381
moveContentType(column, movePosition.insertIndex, this.contentType);
383382
if (modifyOldNeighbour) {
384383
updateColumnWidth(modifyOldNeighbour, oldNeighbourWidth);
385384
}
386-
const newNeighbourWidth = this.resizeUtils.getAcceptedColumnWidth(
385+
let newNeighbourWidth = this.resizeUtils.getAcceptedColumnWidth(
387386
(this.resizeUtils.getColumnWidth(movePosition.affectedColumn) -
388-
this.resizeUtils.getSmallestColumnWidth()).toString(),
387+
oldWidth).toString(),
389388
);
389+
let newNeighbour = movePosition.affectedColumn;
390+
let totalWidthAdjusted = 0;
391+
let newNeighbourIndex = getColumnIndexInLine(newNeighbour);
392+
updateColumnWidth(column, oldWidth);
393+
while (true) {
394+
//take width from all neighbours in one direction till the entire width is obtained
395+
if (newNeighbourWidth <= 0) {
396+
newNeighbourWidth = this.resizeUtils.getSmallestColumnWidth();
397+
let originalWidthOfNeighbour = this.resizeUtils.getColumnWidth(newNeighbour);
398+
updateColumnWidth(newNeighbour, newNeighbourWidth);
399+
totalWidthAdjusted += (originalWidthOfNeighbour - newNeighbourWidth);
400+
} else {
401+
updateColumnWidth(newNeighbour, newNeighbourWidth);
402+
break;
403+
}
390404

391-
// Reduce the affected columns width by the smallest column width
392-
updateColumnWidth(movePosition.affectedColumn, newNeighbourWidth);
405+
newNeighbour = getAdjacentColumn(newNeighbour, direction);
406+
if (!newNeighbour) {
407+
updateColumnWidth(column, oldWidth - totalWidthAdjusted);
408+
break;
409+
}
410+
let neighbourExistingWidth = this.resizeUtils.getColumnWidth(newNeighbour);
411+
newNeighbourWidth = neighbourExistingWidth - (oldWidth - totalWidthAdjusted);
412+
if (newNeighbourWidth < 0.001) {
413+
newNeighbourWidth = 0;
414+
}
393415

416+
}
417+
let totalWidth = 0;
418+
this.contentType.children().forEach((column: ContentTypeCollectionInterface<ColumnPreview>) => {
419+
totalWidth += this.resizeUtils.getColumnWidth(column);
420+
});
421+
if (totalWidth > 100) {
422+
//take extra width from newly moved column
423+
updateColumnWidth(column, this.resizeUtils.getColumnWidth(column) - (totalWidth - 100));
424+
}
394425
}
395426

396427
}

0 commit comments

Comments
 (0)