From 8881a3919c3de25a26d4cef3861939953e39a01c Mon Sep 17 00:00:00 2001 From: Hannah Mudge Date: Mon, 3 Mar 2025 11:02:34 -0700 Subject: [PATCH 1/8] Store rows in object instead of array --- examples/grid_example/public/app.tsx | 26 +++++---- .../public/logs_dashboard_panels.json | 58 +++++++++---------- .../public/serialized_grid_layout.ts | 12 ++-- examples/grid_example/public/types.ts | 6 +- examples/grid_example/public/utils.ts | 25 ++++---- .../kbn-grid-layout/grid/drag_preview.tsx | 6 +- .../kbn-grid-layout/grid/grid_layout.tsx | 31 +++++----- .../drag_handle/use_drag_handle_api.tsx | 6 +- .../grid/grid_panel/grid_panel.tsx | 26 ++++----- .../grid/grid_panel/resize_handle.tsx | 38 ++++++------ .../grid/grid_row/delete_grid_row_modal.tsx | 22 ++++--- .../grid/grid_row/grid_row.tsx | 48 +++++++-------- .../grid/grid_row/grid_row_header.tsx | 26 ++++----- .../grid/grid_row/grid_row_title.tsx | 24 ++++---- .../private/kbn-grid-layout/grid/types.ts | 14 +++-- .../grid/use_grid_layout_events/index.ts | 9 ++- .../state_manager_actions.ts | 42 +++++++------- .../grid/use_grid_layout_state.ts | 12 ++-- .../grid/utils/equality_checks.ts | 12 ++-- .../grid/utils/resolve_grid_row.ts | 17 ++++-- .../grid/utils/row_management.ts | 6 +- .../data_controls/initialize_data_control.ts | 4 +- 22 files changed, 244 insertions(+), 226 deletions(-) diff --git a/examples/grid_example/public/app.tsx b/examples/grid_example/public/app.tsx index 4ea2e4ed7bf42..0b51915012acd 100644 --- a/examples/grid_example/public/app.tsx +++ b/examples/grid_example/public/app.tsx @@ -8,9 +8,11 @@ */ import deepEqual from 'fast-deep-equal'; +import { cloneDeep } from 'lodash'; import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'; import ReactDOM from 'react-dom'; import { Subject, combineLatest, debounceTime, map, skip, take } from 'rxjs'; +import { v4 as uuidv4 } from 'uuid'; import { EuiBadge, @@ -88,8 +90,8 @@ export const GridExample = ({ const currentPanel = panels[panelId]; const savedPanel = savedState.current.panels[panelId]; panelsAreEqual = deepEqual( - { row: 0, ...currentPanel.gridData }, - { row: 0, ...savedPanel.gridData } + { row: 'first', ...currentPanel.gridData }, + { row: 'first', ...savedPanel.gridData } ); } const hasChanges = !(panelsAreEqual && deepEqual(rows, savedState.current.rows)); @@ -147,15 +149,17 @@ export const GridExample = ({ ); const addNewSection = useCallback(() => { - mockDashboardApi.rows$.next([ - ...mockDashboardApi.rows$.getValue(), - { - title: i18n.translate('examples.gridExample.defaultSectionTitle', { - defaultMessage: 'New collapsible section', - }), - collapsed: false, - }, - ]); + const rows = cloneDeep(mockDashboardApi.rows$.getValue()); + const id = uuidv4(); + rows[id] = { + id, + order: Object.keys(rows).length, + title: i18n.translate('examples.gridExample.defaultSectionTitle', { + defaultMessage: 'New collapsible section', + }), + collapsed: false, + }; + mockDashboardApi.rows$.next(rows); // scroll to bottom after row is added layoutUpdated$.pipe(skip(1), take(1)).subscribe(() => { diff --git a/examples/grid_example/public/logs_dashboard_panels.json b/examples/grid_example/public/logs_dashboard_panels.json index 29d63baa2d33b..3b5522975db7c 100644 --- a/examples/grid_example/public/logs_dashboard_panels.json +++ b/examples/grid_example/public/logs_dashboard_panels.json @@ -1004,7 +1004,7 @@ "w": 48, "h": 17, "i": "4", - "row": 1 + "row": "second" }, "explicitInput": { "id": "4", @@ -1035,7 +1035,7 @@ "w": 18, "h": 8, "i": "05da0d2b-0145-4068-b21c-00be3184d465", - "row": 1 + "row": "second" }, "explicitInput": { "id": "05da0d2b-0145-4068-b21c-00be3184d465", @@ -1073,7 +1073,7 @@ "w": 18, "h": 16, "i": "b7da9075-4742-47e3-b4f8-fc9ba82de74c", - "row": 1 + "row": "second" }, "explicitInput": { "id": "b7da9075-4742-47e3-b4f8-fc9ba82de74c", @@ -1111,7 +1111,7 @@ "w": 12, "h": 16, "i": "5c409557-644d-4c05-a284-ffe54bb28db0", - "row": 1 + "row": "second" }, "explicitInput": { "id": "5c409557-644d-4c05-a284-ffe54bb28db0", @@ -1234,7 +1234,7 @@ "w": 6, "h": 8, "i": "af4b5c07-506e-44c2-b2bb-2113d0c5b274", - "row": 1 + "row": "second" }, "explicitInput": { "id": "af4b5c07-506e-44c2-b2bb-2113d0c5b274", @@ -1400,7 +1400,7 @@ "w": 6, "h": 8, "i": "d42c4870-c028-4d8a-abd0-0effbc190ce3", - "row": 1 + "row": "second" }, "explicitInput": { "id": "d42c4870-c028-4d8a-abd0-0effbc190ce3", @@ -1520,7 +1520,7 @@ "w": 6, "h": 8, "i": "4092d42c-f93b-4c71-a6db-8f12abf12791", - "row": 1 + "row": "second" }, "explicitInput": { "id": "4092d42c-f93b-4c71-a6db-8f12abf12791", @@ -1641,7 +1641,7 @@ "w": 30, "h": 15, "i": "15", - "row": 2 + "row": "third" }, "explicitInput": { "id": "15", @@ -1887,7 +1887,7 @@ "w": 18, "h": 8, "i": "4e64d6d7-4f92-4d5e-abbb-13796604db30", - "row": 2 + "row": "third" }, "explicitInput": { "id": "4e64d6d7-4f92-4d5e-abbb-13796604db30v", @@ -1925,7 +1925,7 @@ "w": 6, "h": 7, "i": "ddce4ad8-6a82-44f0-9995-57f46f153f50", - "row": 2 + "row": "third" }, "explicitInput": { "id": "ddce4ad8-6a82-44f0-9995-57f46f153f50", @@ -2120,7 +2120,7 @@ "w": 6, "h": 7, "i": "a2884704-db3b-4b92-a19a-cdfe668dec39", - "row": 2 + "row": "third" }, "explicitInput": { "id": "a2884704-db3b-4b92-a19a-cdfe668dec39", @@ -2315,7 +2315,7 @@ "w": 6, "h": 7, "i": "529eec49-10e2-4a40-9c77-5c81f4eb3943", - "row": 2 + "row": "third" }, "explicitInput": { "id": "529eec49-10e2-4a40-9c77-5c81f4eb3943", @@ -2510,7 +2510,7 @@ "w": 48, "h": 12, "i": "1d5f0b3f-d9d2-4b26-997b-83bc5ca3090b", - "row": 2 + "row": "third" }, "explicitInput": { "id": "1d5f0b3f-d9d2-4b26-997b-83bc5ca3090b", @@ -2905,7 +2905,7 @@ "w": 48, "h": 15, "i": "9f79ecca-123f-4098-a658-6b0e998da003", - "row": 3 + "row": "fourth" }, "explicitInput": { "id": "9f79ecca-123f-4098-a658-6b0e998da003", @@ -2922,7 +2922,7 @@ "w": 24, "h": 9, "i": "7", - "row": 3 + "row": "fourth" }, "explicitInput": { "id": "7", @@ -3161,7 +3161,7 @@ "w": 24, "h": 11, "i": "10", - "row": 3 + "row": "fourth" }, "explicitInput": { "id": "10", @@ -3346,7 +3346,7 @@ "w": 24, "h": 22, "i": "23", - "row": 3 + "row": "fourth" }, "explicitInput": { "id": "23", @@ -3371,7 +3371,7 @@ "w": 24, "h": 22, "i": "31", - "row": 3 + "row": "fourth" }, "explicitInput": { "id": "31", @@ -3388,7 +3388,7 @@ "w": 24, "h": 8, "i": "6afc61f7-e2d5-45a3-9e7a-281160ad3eb9", - "row": 3 + "row": "fourth" }, "explicitInput": { "id": "6afc61f7-e2d5-45a3-9e7a-281160ad3eb9", @@ -3420,7 +3420,7 @@ "w": 8, "h": 8, "i": "392b4936-f753-47bc-a98d-a4e41a0a4cd4", - "row": 3 + "row": "fourth" }, "explicitInput": { "id": "392b4936-f753-47bc-a98d-a4e41a0a4cd4", @@ -3485,7 +3485,7 @@ "w": 8, "h": 4, "i": "9271deff-5a61-4665-83fc-f9fdc6bf0c0b", - "row": 3 + "row": "fourth" }, "explicitInput": { "id": "9271deff-5a61-4665-83fc-f9fdc6bf0c0b", @@ -3613,7 +3613,7 @@ "w": 8, "h": 4, "i": "aa591c29-1a31-4ee1-a71d-b829c06fd162", - "row": 3 + "row": "fourth" }, "explicitInput": { "id": "aa591c29-1a31-4ee1-a71d-b829c06fd162", @@ -3777,7 +3777,7 @@ "w": 8, "h": 4, "i": "b766e3b8-4544-46ed-99e6-9ecc4847e2a2", - "row": 3 + "row": "fourth" }, "explicitInput": { "id": "b766e3b8-4544-46ed-99e6-9ecc4847e2a2", @@ -3905,7 +3905,7 @@ "w": 8, "h": 4, "i": "2e33ade5-96e5-40b4-b460-493e5d4fa834", - "row": 3 + "row": "fourth" }, "explicitInput": { "id": "2e33ade5-96e5-40b4-b460-493e5d4fa834", @@ -4069,7 +4069,7 @@ "w": 24, "h": 8, "i": "086ac2e9-dd16-4b45-92b8-1e43ff7e3f65", - "row": 3 + "row": "fourth" }, "explicitInput": { "id": "086ac2e9-dd16-4b45-92b8-1e43ff7e3f65", @@ -4190,7 +4190,7 @@ "w": 24, "h": 28, "i": "fb86b32f-fb7a-45cf-9511-f366fef51bbd", - "row": 3 + "row": "fourth" }, "explicitInput": { "id": "fb86b32f-fb7a-45cf-9511-f366fef51bbd", @@ -4500,7 +4500,7 @@ "w": 24, "h": 11, "i": "0cc42484-16f7-42ec-b38c-9bf8be69cde7", - "row": 3 + "row": "fourth" }, "explicitInput": { "id": "0cc42484-16f7-42ec-b38c-9bf8be69cde7", @@ -4643,7 +4643,7 @@ "w": 12, "h": 11, "i": "5d53db36-2d5a-4adc-af7b-cec4c1a294e0", - "row": 3 + "row": "fourth" }, "explicitInput": { "id": "5d53db36-2d5a-4adc-af7b-cec4c1a294e0", @@ -4773,7 +4773,7 @@ "w": 12, "h": 11, "i": "ecd89a7c-9124-4472-bdc6-9bdbd70d45d5", - "row": 3 + "row": "fourth" }, "explicitInput": { "id": "ecd89a7c-9124-4472-bdc6-9bdbd70d45d5", diff --git a/examples/grid_example/public/serialized_grid_layout.ts b/examples/grid_example/public/serialized_grid_layout.ts index e5664bd1f22e5..38000e20d74ef 100644 --- a/examples/grid_example/public/serialized_grid_layout.ts +++ b/examples/grid_example/public/serialized_grid_layout.ts @@ -28,10 +28,10 @@ export function setSerializedGridLayout(state: MockSerializedDashboardState) { const initialState: MockSerializedDashboardState = { panels: logsPanels, - rows: [ - { title: 'Request Sizes', collapsed: false }, - { title: 'Visitors', collapsed: false }, - { title: 'Response Codes', collapsed: false }, - { title: 'Entire Flights Dashboard', collapsed: true }, - ], + rows: { + first: { id: 'first', order: 0, title: 'Request Sizes', collapsed: false }, + second: { id: 'second', order: 1, title: 'Visitors', collapsed: false }, + third: { id: 'third', order: 2, title: 'Response Codes', collapsed: false }, + fourth: { id: 'fourth', order: 3, title: 'Entire Flights Dashboard', collapsed: true }, + }, }; diff --git a/examples/grid_example/public/types.ts b/examples/grid_example/public/types.ts index 705b652e3d6bf..038736dd64669 100644 --- a/examples/grid_example/public/types.ts +++ b/examples/grid_example/public/types.ts @@ -26,7 +26,7 @@ export interface DashboardGridData { interface DashboardPanelState { type: string; - gridData: DashboardGridData & { row?: number }; + gridData: DashboardGridData & { row?: string }; explicitInput: Partial & { id: string }; version?: string; } @@ -35,7 +35,9 @@ export interface MockedDashboardPanelMap { [key: string]: DashboardPanelState; } -export type MockedDashboardRowMap = Array<{ title: string; collapsed: boolean }>; +export type MockedDashboardRowMap = { + [id: string]: { id: string; order: number; title: string; collapsed: boolean }; +}; export interface MockSerializedDashboardState { panels: MockedDashboardPanelMap; diff --git a/examples/grid_example/public/utils.ts b/examples/grid_example/public/utils.ts index 8c9db472cffa7..b40f0f846f08c 100644 --- a/examples/grid_example/public/utils.ts +++ b/examples/grid_example/public/utils.ts @@ -15,10 +15,11 @@ export const gridLayoutToDashboardPanelMap = ( layout: GridLayoutData ): { panels: MockedDashboardPanelMap; rows: MockedDashboardRowMap } => { const panels: MockedDashboardPanelMap = {}; - const rows: MockedDashboardRowMap = []; - layout.forEach((row, rowIndex) => { - rows.push({ title: row.title, collapsed: row.isCollapsed }); - Object.values(row.panels).forEach((panelGridData) => { + const rows: MockedDashboardRowMap = {}; + Object.entries(layout).forEach(([rowId, row]) => { + const { panels: rowPanels, isCollapsed, ...rest } = row; // drop panels + rows[rowId] = { ...rest, collapsed: isCollapsed }; + Object.values(rowPanels).forEach((panelGridData) => { panels[panelGridData.id] = { ...panelState[panelGridData.id], gridData: { @@ -27,7 +28,7 @@ export const gridLayoutToDashboardPanelMap = ( x: panelGridData.column, w: panelGridData.width, h: panelGridData.height, - row: rowIndex, + row: rowId, }, }; }); @@ -42,15 +43,19 @@ export const dashboardInputToGridLayout = ({ panels: MockedDashboardPanelMap; rows: MockedDashboardRowMap; }): GridLayoutData => { - const layout: GridLayoutData = []; - - rows.forEach((row) => { - layout.push({ title: row.title, isCollapsed: row.collapsed, panels: {} }); + const layout: GridLayoutData = {}; + Object.values(rows).forEach((row) => { + const { collapsed, ...rest } = row; + layout[row.id] = { + ...rest, + panels: {}, + isCollapsed: collapsed, + }; }); Object.keys(panels).forEach((panelId) => { const gridData = panels[panelId].gridData; - layout[gridData.row ?? 0].panels[panelId] = { + layout[gridData.row ?? 'first'].panels[panelId] = { id: panelId, row: gridData.y, column: gridData.x, diff --git a/src/platform/packages/private/kbn-grid-layout/grid/drag_preview.tsx b/src/platform/packages/private/kbn-grid-layout/grid/drag_preview.tsx index 0d34c33b674fe..dd489bdc915be 100644 --- a/src/platform/packages/private/kbn-grid-layout/grid/drag_preview.tsx +++ b/src/platform/packages/private/kbn-grid-layout/grid/drag_preview.tsx @@ -13,7 +13,7 @@ import { combineLatest, skip } from 'rxjs'; import { css } from '@emotion/react'; import { useGridLayoutContext } from './use_grid_layout_context'; -export const DragPreview = React.memo(({ rowIndex }: { rowIndex: number }) => { +export const DragPreview = React.memo(({ rowId }: { rowId: string }) => { const { gridLayoutStateManager } = useGridLayoutContext(); const dragPreviewRef = useRef(null); @@ -29,10 +29,10 @@ export const DragPreview = React.memo(({ rowIndex }: { rowIndex: number }) => { .subscribe(([activePanel, proposedGridLayout]) => { if (!dragPreviewRef.current) return; - if (!activePanel || !proposedGridLayout?.[rowIndex].panels[activePanel.id]) { + if (!activePanel || !proposedGridLayout?.[rowId].panels[activePanel.id]) { dragPreviewRef.current.style.display = 'none'; } else { - const panel = proposedGridLayout[rowIndex].panels[activePanel.id]; + const panel = proposedGridLayout[rowId].panels[activePanel.id]; dragPreviewRef.current.style.display = 'block'; dragPreviewRef.current.style.gridColumnStart = `${panel.column + 1}`; dragPreviewRef.current.style.gridColumnEnd = `${panel.column + 1 + panel.width}`; diff --git a/src/platform/packages/private/kbn-grid-layout/grid/grid_layout.tsx b/src/platform/packages/private/kbn-grid-layout/grid/grid_layout.tsx index 9dd0a2d44d7a3..f5d9a78ee2329 100644 --- a/src/platform/packages/private/kbn-grid-layout/grid/grid_layout.tsx +++ b/src/platform/packages/private/kbn-grid-layout/grid/grid_layout.tsx @@ -8,9 +8,10 @@ */ import classNames from 'classnames'; +import deepEqual from 'fast-deep-equal'; import { cloneDeep } from 'lodash'; import React, { useEffect, useMemo, useRef, useState } from 'react'; -import { combineLatest, distinctUntilChanged, map, pairwise, skip } from 'rxjs'; +import { combineLatest, distinctUntilChanged, pairwise, skip } from 'rxjs'; import { css } from '@emotion/react'; @@ -20,7 +21,7 @@ import { GridAccessMode, GridLayoutData, GridSettings, UseCustomDragHandle } fro import { GridLayoutContext, GridLayoutContextType } from './use_grid_layout_context'; import { useGridLayoutState } from './use_grid_layout_state'; import { isLayoutEqual } from './utils/equality_checks'; -import { resolveGridRow } from './utils/resolve_grid_row'; +import { getRowKeysInOrder, resolveGridRow } from './utils/resolve_grid_row'; export type GridLayoutProps = { layout: GridLayoutData; @@ -50,10 +51,7 @@ export const GridLayout = ({ accessMode, }); - const [rowCount, setRowCount] = useState( - gridLayoutStateManager.gridLayout$.getValue().length - ); - + const [rowIdsInOrder, setRowIdsInOrder] = useState(() => getRowKeysInOrder(layout)); /** * Update the `gridLayout$` behaviour subject in response to the `layout` prop changing */ @@ -64,8 +62,8 @@ export const GridLayout = ({ * the layout sent in as a prop is not guaranteed to be valid (i.e it may have floating panels) - * so, we need to loop through each row and ensure it is compacted */ - newLayout.forEach((row, rowIndex) => { - newLayout[rowIndex] = resolveGridRow(row); + Object.entries(newLayout).forEach(([rowId, row]) => { + newLayout[rowId] = resolveGridRow(row); }); gridLayoutStateManager.gridLayout$.next(newLayout); } @@ -82,12 +80,13 @@ export const GridLayout = ({ */ const rowCountSubscription = gridLayoutStateManager.gridLayout$ .pipe( - skip(1), // we initialized `rowCount` above, so skip the initial emit - map((newLayout) => newLayout.length), - distinctUntilChanged() + skip(1), + distinctUntilChanged((prevLayout, newLayout) => { + return deepEqual(Object.keys(prevLayout), Object.keys(newLayout)); + }) ) - .subscribe((newRowCount) => { - setRowCount(newRowCount); + .subscribe((newLayout) => { + setRowIdsInOrder(getRowKeysInOrder(newLayout)); }); /** @@ -158,9 +157,9 @@ export const GridLayout = ({ styles.hasExpandedPanel, ]} > - {Array.from({ length: rowCount }, (_, rowIndex) => { - return ; - })} + {rowIdsInOrder.map((rowId) => ( + + ))} diff --git a/src/platform/packages/private/kbn-grid-layout/grid/grid_panel/drag_handle/use_drag_handle_api.tsx b/src/platform/packages/private/kbn-grid-layout/grid/grid_panel/drag_handle/use_drag_handle_api.tsx index a2e3c632d1364..b3470018cd5b3 100644 --- a/src/platform/packages/private/kbn-grid-layout/grid/grid_panel/drag_handle/use_drag_handle_api.tsx +++ b/src/platform/packages/private/kbn-grid-layout/grid/grid_panel/drag_handle/use_drag_handle_api.tsx @@ -20,17 +20,17 @@ export interface DragHandleApi { export const useDragHandleApi = ({ panelId, - rowIndex, + rowId, }: { panelId: string; - rowIndex: number; + rowId: string; }): DragHandleApi => { const { useCustomDragHandle } = useGridLayoutContext(); const startInteraction = useGridLayoutEvents({ interactionType: 'drag', panelId, - rowIndex, + rowId, }); const removeEventListenersRef = useRef<(() => void) | null>(null); diff --git a/src/platform/packages/private/kbn-grid-layout/grid/grid_panel/grid_panel.tsx b/src/platform/packages/private/kbn-grid-layout/grid/grid_panel/grid_panel.tsx index c29a9ccae1bd4..f78d3976e610c 100644 --- a/src/platform/packages/private/kbn-grid-layout/grid/grid_panel/grid_panel.tsx +++ b/src/platform/packages/private/kbn-grid-layout/grid/grid_panel/grid_panel.tsx @@ -20,20 +20,20 @@ import { ResizeHandle } from './resize_handle'; export interface GridPanelProps { panelId: string; - rowIndex: number; + rowId: string; } -export const GridPanel = React.memo(({ panelId, rowIndex }: GridPanelProps) => { +export const GridPanel = React.memo(({ panelId, rowId }: GridPanelProps) => { const { gridLayoutStateManager, useCustomDragHandle, renderPanelContents } = useGridLayoutContext(); const { euiTheme } = useEuiTheme(); - const dragHandleApi = useDragHandleApi({ panelId, rowIndex }); + const dragHandleApi = useDragHandleApi({ panelId, rowId }); /** Set initial styles based on state at mount to prevent styles from "blipping" */ const initialStyles = useMemo(() => { const initialPanel = (gridLayoutStateManager.proposedGridLayout$.getValue() ?? - gridLayoutStateManager.gridLayout$.getValue())[rowIndex].panels[panelId]; + gridLayoutStateManager.gridLayout$.getValue())[rowId].panels[panelId]; return css` position: relative; height: calc( @@ -48,7 +48,7 @@ export const GridPanel = React.memo(({ panelId, rowIndex }: GridPanelProps) => { grid-row-start: ${initialPanel.row + 1}; grid-row-end: ${initialPanel.row + 1 + initialPanel.height}; `; - }, [gridLayoutStateManager, rowIndex, panelId]); + }, [gridLayoutStateManager, rowId, panelId]); useEffect( () => { @@ -60,8 +60,8 @@ export const GridPanel = React.memo(({ panelId, rowIndex }: GridPanelProps) => { ]) .pipe(skip(1)) // skip the first emit because the `initialStyles` will take care of it .subscribe(([activePanel, gridLayout, proposedGridLayout]) => { - const ref = gridLayoutStateManager.panelRefs.current[rowIndex][panelId]; - const panel = (proposedGridLayout ?? gridLayout)[rowIndex].panels[panelId]; + const ref = gridLayoutStateManager.panelRefs.current[rowId][panelId]; + const panel = (proposedGridLayout ?? gridLayout)[rowId]?.panels[panelId]; if (!ref || !panel) return; const currentInteractionEvent = gridLayoutStateManager.interactionEvent$.getValue(); @@ -128,9 +128,9 @@ export const GridPanel = React.memo(({ panelId, rowIndex }: GridPanelProps) => { */ const expandedPanelSubscription = gridLayoutStateManager.expandedPanelId$.subscribe( (expandedPanelId) => { - const ref = gridLayoutStateManager.panelRefs.current[rowIndex][panelId]; + const ref = gridLayoutStateManager.panelRefs.current[rowId][panelId]; const gridLayout = gridLayoutStateManager.gridLayout$.getValue(); - const panel = gridLayout[rowIndex].panels[panelId]; + const panel = gridLayout[rowId].panels[panelId]; if (!ref || !panel) return; if (expandedPanelId && expandedPanelId === panelId) { @@ -160,17 +160,17 @@ export const GridPanel = React.memo(({ panelId, rowIndex }: GridPanelProps) => { return (
{ - if (!gridLayoutStateManager.panelRefs.current[rowIndex]) { - gridLayoutStateManager.panelRefs.current[rowIndex] = {}; + if (!gridLayoutStateManager.panelRefs.current[rowId]) { + gridLayoutStateManager.panelRefs.current[rowId] = {}; } - gridLayoutStateManager.panelRefs.current[rowIndex][panelId] = element; + gridLayoutStateManager.panelRefs.current[rowId][panelId] = element; }} css={initialStyles} className="kbnGridPanel" > {!useCustomDragHandle && } {panelContents} - +
); }); diff --git a/src/platform/packages/private/kbn-grid-layout/grid/grid_panel/resize_handle.tsx b/src/platform/packages/private/kbn-grid-layout/grid/grid_panel/resize_handle.tsx index ccb264d2294e1..8fb0254bccba4 100644 --- a/src/platform/packages/private/kbn-grid-layout/grid/grid_panel/resize_handle.tsx +++ b/src/platform/packages/private/kbn-grid-layout/grid/grid_panel/resize_handle.tsx @@ -15,27 +15,25 @@ import { i18n } from '@kbn/i18n'; import { useGridLayoutEvents } from '../use_grid_layout_events'; -export const ResizeHandle = React.memo( - ({ rowIndex, panelId }: { rowIndex: number; panelId: string }) => { - const startInteraction = useGridLayoutEvents({ - interactionType: 'resize', - panelId, - rowIndex, - }); +export const ResizeHandle = React.memo(({ rowId, panelId }: { rowId: string; panelId: string }) => { + const startInteraction = useGridLayoutEvents({ + interactionType: 'resize', + panelId, + rowId, + }); - return ( -