-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Dashboard] [Collapsable Panels] Switch to using props #200793
Merged
Heenawter
merged 12 commits into
elastic:main
from
Heenawter:kbn-grid-layout_switch-to-props_2024-11-19
Nov 21, 2024
Merged
Changes from 8 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
35aa800
First draft of switching to props - mostly working
Heenawter f62a397
Do some cleanup
Heenawter e810e07
Some more cleanup
Heenawter 3c1b04a
[CI] Auto-commit changed files from 'node scripts/notice'
kibanamachine 3f84aa2
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine 53684fc
Fix linting
Heenawter c7289cb
Memoize panel contents to reduce re-renders
Heenawter 190ea0c
Remove `EuiPanel` hover styles
Heenawter 62cd9e7
Merge branch 'main' into kbn-grid-layout_switch-to-props_2024-11-19
Heenawter c3664e6
Make things more efficient using `Profiler`
Heenawter 9f81efe
Merge branch 'kbn-grid-layout_switch-to-props_2024-11-19' of github.c…
Heenawter a8ea094
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
export interface DashboardGridData { | ||
w: number; | ||
h: number; | ||
x: number; | ||
y: number; | ||
i: string; | ||
} | ||
|
||
export interface MockedDashboardPanelMap { | ||
[key: string]: { id: string; gridData: DashboardGridData & { row: number } }; | ||
} | ||
|
||
export type MockedDashboardRowMap = Array<{ title: string; collapsed: boolean }>; | ||
|
||
export interface MockSerializedDashboardState { | ||
panels: MockedDashboardPanelMap; | ||
rows: MockedDashboardRowMap; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
import { cloneDeep } from 'lodash'; | ||
import { useMemo } from 'react'; | ||
import { BehaviorSubject } from 'rxjs'; | ||
|
||
import { | ||
MockSerializedDashboardState, | ||
MockedDashboardPanelMap, | ||
MockedDashboardRowMap, | ||
} from './types'; | ||
|
||
const DASHBOARD_GRID_COLUMN_COUNT = 48; | ||
const DEFAULT_PANEL_HEIGHT = 15; | ||
const DEFAULT_PANEL_WIDTH = DASHBOARD_GRID_COLUMN_COUNT / 2; | ||
|
||
export const useMockDashboardApi = ({ | ||
savedState, | ||
}: { | ||
savedState: MockSerializedDashboardState; | ||
}) => { | ||
const mockDashboardApi = useMemo(() => { | ||
return { | ||
viewMode: new BehaviorSubject('edit'), | ||
panels$: new BehaviorSubject<MockedDashboardPanelMap>(savedState.panels), | ||
rows$: new BehaviorSubject<MockedDashboardRowMap>(savedState.rows), | ||
removePanel: (id: string) => { | ||
const panels = { ...mockDashboardApi.panels$.getValue() }; | ||
delete panels[id]; // the grid layout component will handle compacting, if necessary | ||
mockDashboardApi.panels$.next(panels); | ||
}, | ||
replacePanel: (oldId: string, newId: string) => { | ||
const currentPanels = mockDashboardApi.panels$.getValue(); | ||
const otherPanels = { ...currentPanels }; | ||
const oldPanel = currentPanels[oldId]; | ||
delete otherPanels[oldId]; | ||
otherPanels[newId] = { id: newId, gridData: { ...oldPanel.gridData, i: newId } }; | ||
mockDashboardApi.panels$.next(otherPanels); | ||
}, | ||
addNewPanel: ({ id: newId }: { id: string }) => { | ||
// we are only implementing "place at top" here, for demo purposes | ||
const currentPanels = mockDashboardApi.panels$.getValue(); | ||
const otherPanels = { ...currentPanels }; | ||
for (const [id, panel] of Object.entries(currentPanels)) { | ||
const currentPanel = cloneDeep(panel); | ||
currentPanel.gridData.y = currentPanel.gridData.y + DEFAULT_PANEL_HEIGHT; | ||
otherPanels[id] = currentPanel; | ||
} | ||
mockDashboardApi.panels$.next({ | ||
...otherPanels, | ||
[newId]: { | ||
id: newId, | ||
gridData: { | ||
i: newId, | ||
row: 0, | ||
x: 0, | ||
y: 0, | ||
w: DEFAULT_PANEL_WIDTH, | ||
h: DEFAULT_PANEL_HEIGHT, | ||
}, | ||
}, | ||
}); | ||
}, | ||
canRemovePanels: () => true, | ||
}; | ||
// only run onMount | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, []); | ||
|
||
return mockDashboardApi; | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I modified this example to more similarly match how the Dashboard integration will work by adding a mock dashboard API. We use the
panels$
+rows$
behaviour subjects as our "source of truth" for the layout engine, so that we always stay in sync.