diff --git a/packages/dashboard/src/layout/LayoutUtils.test.ts b/packages/dashboard/src/layout/LayoutUtils.test.ts index 703ab11292..89213f4a36 100644 --- a/packages/dashboard/src/layout/LayoutUtils.test.ts +++ b/packages/dashboard/src/layout/LayoutUtils.test.ts @@ -24,11 +24,20 @@ function makeContentItem(type = 'root'): Partial { contentItems.splice(index, 1); } }), + replaceChild: jest.fn((oldChild, newChild) => { + const index = contentItems.indexOf(oldChild); + if (index >= 0) { + contentItems[index] = newChild; + } + }), isComponent: type === 'component', isColumn: type === 'column', isRow: type === 'row', isRoot: type === 'root', type, + layoutManager: { + createContentItem: ({ type: newType }) => makeContentItem(newType), + }, }; } diff --git a/packages/dashboard/src/layout/LayoutUtils.ts b/packages/dashboard/src/layout/LayoutUtils.ts index 779d41139b..1f03eff0a6 100644 --- a/packages/dashboard/src/layout/LayoutUtils.ts +++ b/packages/dashboard/src/layout/LayoutUtils.ts @@ -143,12 +143,18 @@ class LayoutUtils { const isCorrectType = !columnPreferred ? newParent.isColumn : newParent.isRow; + + // This is usually triggered because we hit a stack within the last row/column if (!isCorrectType) { - const inverseRowOrColConfig: ItemConfig = { - type: !columnPreferred ? 'column' : 'row', - }; - parent.addChild(inverseRowOrColConfig); - parent.removeChild(newParent, true); + const inverseRowOrColConfig = parent.layoutManager.createContentItem( + { + type: !columnPreferred ? 'column' : 'row', + height: newParent.config?.height, + width: newParent.config?.width, + }, + parent + ); + parent.replaceChild(newParent, inverseRowOrColConfig); parent.contentItems[parent.contentItems.length - 1].addChild(newParent); newParent = parent.contentItems[parent.contentItems.length - 1]; } diff --git a/packages/golden-layout/src/items/RowOrColumn.ts b/packages/golden-layout/src/items/RowOrColumn.ts index 315bd7b78a..42ea935a36 100644 --- a/packages/golden-layout/src/items/RowOrColumn.ts +++ b/packages/golden-layout/src/items/RowOrColumn.ts @@ -179,13 +179,18 @@ export default class RowOrColumn extends AbstractContentItem { /** * Replaces a child of this Row or Column with another contentItem * - * @param oldChild - * @param newChild + * @param oldChild The old child to replace + * @param newChild The new child to take the old child's place + * @param destroyOldChild If the old child should be destroyed or not */ - replaceChild(oldChild: AbstractContentItem, newChild: AbstractContentItem) { + replaceChild( + oldChild: AbstractContentItem, + newChild: AbstractContentItem, + destroyOldChild = false + ) { var size = oldChild.config[this._dimension]; - super.replaceChild(oldChild, newChild); newChild.config[this._dimension] = size; + super.replaceChild(oldChild, newChild, destroyOldChild); this.callDownwards('setSize'); this.emitBubblingEvent('stateChanged'); }