Skip to content

Commit

Permalink
[Dashboard][Collapsable Panels] Fix bug on layout update (elastic#2…
Browse files Browse the repository at this point in the history
…02049)

## Summary

When the `layout` prop updates, we cannot assume that it is "safe" (i.e.
we cannot assume it has no floating panels and/or colliding panels).
Because of this, we need to resolve each grid row when this prop
changes. When I added this in
elastic#200793, I accidentally only
**compacted** the rows, which did not account for possible collisions
that the Dashboard's panel placement strategies do not account for. This
PR fixes that by calling `resolveGridRow` (which compacts **and**
detects collisions) instead of just `compactGridRow` (which, as the name
suggests, only compacts the rows)

**Before:**

https://github.com/user-attachments/assets/bcea4efd-35fa-425d-ac04-41434ffaa810

**After:**

https://github.com/user-attachments/assets/6cd205c6-d1d5-4a97-8d14-425c2a4bbeda

### Checklist

- [x] The PR description includes the appropriate Release Notes section,
and the correct `release_note:*` label is applied per the
[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

### Identify risks

There are no risks to this PR, since all work is contained in the
`examples` plugin.

(cherry picked from commit 57b8bda)
  • Loading branch information
Heenawter committed Nov 27, 2024
1 parent 654ea79 commit 7dd6369
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 119 deletions.
4 changes: 2 additions & 2 deletions packages/kbn-grid-layout/grid/grid_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { GridLayoutData, GridSettings } from './types';
import { useGridLayoutEvents } from './use_grid_layout_events';
import { useGridLayoutState } from './use_grid_layout_state';
import { isLayoutEqual } from './utils/equality_checks';
import { compactGridRow } from './utils/resolve_grid_row';
import { resolveGridRow } from './utils/resolve_grid_row';

interface GridLayoutProps {
layout: GridLayoutData;
Expand Down Expand Up @@ -53,7 +53,7 @@ export const GridLayout = ({
* so, we need to loop through each row and ensure it is compacted
*/
newLayout.forEach((row, rowIndex) => {
newLayout[rowIndex] = compactGridRow(row);
newLayout[rowIndex] = resolveGridRow(row);
});
gridLayoutStateManager.gridLayout$.next(newLayout);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-grid-layout/grid/utils/resolve_grid_row.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const getKeysInOrder = (rowData: GridRowData, draggedId?: string): string[] => {
});
};

export const compactGridRow = (originalLayout: GridRowData) => {
const compactGridRow = (originalLayout: GridRowData) => {
const nextRowData = { ...originalLayout, panels: { ...originalLayout.panels } };
// compact all vertical space.
const sortedKeysAfterMove = getKeysInOrder(nextRowData);
Expand Down
116 changes: 0 additions & 116 deletions packages/kbn-grid-layout/grid/utils/run_panel_placement.ts

This file was deleted.

0 comments on commit 7dd6369

Please sign in to comment.