Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Layout shifts when opening and closing panels from a fresh state #2241

Merged
merged 2 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/dashboard/src/layout/LayoutUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,20 @@ function makeContentItem(type = 'root'): Partial<ContentItem> {
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),
},
};
}

Expand Down
16 changes: 11 additions & 5 deletions packages/dashboard/src/layout/LayoutUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down
13 changes: 9 additions & 4 deletions packages/golden-layout/src/items/RowOrColumn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down
Loading