Skip to content

Commit 043ddc2

Browse files
authored
[Dashboards as Code] Rename dashboard panel props for API (elastic#235992)
1 parent 31f3c64 commit 043ddc2

47 files changed

Lines changed: 438 additions & 361 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

examples/portable_dashboards_example/public/static_by_value_example_panels.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
[
22
{
33
"type": "visualization",
4-
"gridData": {
4+
"grid": {
55
"x": 0,
66
"y": 0,
77
"w": 28,
88
"h": 10,
99
"i": "a514e5f6-1d0d-4fe9-85a9-f7ba40665033"
1010
},
11-
"panelIndex": "a514e5f6-1d0d-4fe9-85a9-f7ba40665033",
12-
"panelConfig": {
11+
"uid": "a514e5f6-1d0d-4fe9-85a9-f7ba40665033",
12+
"config": {
1313
"savedVis": {
1414
"id": "",
1515
"title": "",
@@ -37,15 +37,15 @@
3737
},
3838
{
3939
"type": "lens",
40-
"gridData": {
40+
"grid": {
4141
"x": 30,
4242
"y": 0,
4343
"w": 20,
4444
"h": 21,
4545
"i": "b06b849e-f4fd-423c-a582-5c4bfec812c9"
4646
},
47-
"panelIndex": "b06b849e-f4fd-423c-a582-5c4bfec812c9",
48-
"panelConfig": {
47+
"uid": "b06b849e-f4fd-423c-a582-5c4bfec812c9",
48+
"config": {
4949
"title": "Destinations",
5050
"attributes": {
5151
"title": "",
@@ -144,14 +144,14 @@
144144
},
145145
{
146146
"type": "lens",
147-
"gridData": {
147+
"grid": {
148148
"x": 0,
149149
"y": 9,
150150
"w": 28,
151151
"h": 11,
152152
"i": "a4121cab-b6f2-4de3-af71-ec9b5a6f0a2a"
153153
},
154-
"panelIndex": "a4121cab-b6f2-4de3-af71-ec9b5a6f0a2a",
154+
"uid": "a4121cab-b6f2-4de3-af71-ec9b5a6f0a2a",
155155
"explicitInput": {
156156
"enhancements": {},
157157
"attributes": {

src/platform/plugins/shared/dashboard/common/is_dashboard_panel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ import type { DashboardAttributes, DashboardPanel } from '../server/content_mana
1212
export const isDashboardPanel = (
1313
widget: DashboardAttributes['panels'][number]
1414
): widget is DashboardPanel => {
15-
return 'panelConfig' in widget;
15+
return 'config' in widget;
1616
};

src/platform/plugins/shared/dashboard/public/dashboard_actions/copy_to_dashboard_modal.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ describe('CopyToDashboardModal', () => {
4949
savedObjectId$: new BehaviorSubject<string | undefined>('dashboardOne'),
5050
getDashboardPanelFromId: () => ({
5151
type: 'testPanelType',
52-
gridData: { w: 1, h: 1, x: 0, y: 0, i: 'panelOne' },
52+
grid: { w: 1, h: 1, x: 0, y: 0, i: 'panelOne' },
5353
serializedState: {
5454
rawState: {
5555
title: 'Panel One',

src/platform/plugins/shared/dashboard/public/dashboard_actions/copy_to_dashboard_modal.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ export function CopyToDashboardModal({ api, closeModal }: CopyToDashboardModalPr
5656
type: panelToCopy.type,
5757
serializedState: panelToCopy.serializedState,
5858
size: {
59-
width: panelToCopy.gridData.w,
60-
height: panelToCopy.gridData.h,
59+
width: panelToCopy.grid.w,
60+
height: panelToCopy.grid.h,
6161
},
6262
};
6363

src/platform/plugins/shared/dashboard/public/dashboard_api/generate_new_panel_ids.test.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ describe('generateNewPanelIds', () => {
2121
const { newPanels, newPanelReferences } = generateNewPanelIds(
2222
[
2323
{
24-
gridData: { x: 0, y: 0, w: 6, h: 6, i: '1' },
25-
panelConfig: { title: 'panel One' },
26-
panelIndex: '1',
24+
grid: { x: 0, y: 0, w: 6, h: 6, i: '1' },
25+
config: { title: 'panel One' },
26+
uid: '1',
2727
type: 'testPanelType',
2828
},
2929
],
@@ -38,9 +38,9 @@ describe('generateNewPanelIds', () => {
3838

3939
expect(newPanels).toEqual([
4040
{
41-
gridData: { x: 0, y: 0, w: 6, h: 6, i: '100' },
42-
panelConfig: { title: 'panel One' },
43-
panelIndex: '100',
41+
grid: { x: 0, y: 0, w: 6, h: 6, i: '100' },
42+
config: { title: 'panel One' },
43+
uid: '100',
4444
type: 'testPanelType',
4545
},
4646
]);
@@ -60,15 +60,15 @@ describe('generateNewPanelIds', () => {
6060
{
6161
title: 'Section One',
6262
collapsed: true,
63-
gridData: {
63+
grid: {
6464
y: 6,
6565
i: 'section1',
6666
},
6767
panels: [
6868
{
69-
gridData: { x: 0, y: 0, w: 6, h: 6, i: '1' },
70-
panelConfig: { title: 'panel One' },
71-
panelIndex: '1',
69+
grid: { x: 0, y: 0, w: 6, h: 6, i: '1' },
70+
config: { title: 'panel One' },
71+
uid: '1',
7272
type: 'testPanelType',
7373
},
7474
],
@@ -87,15 +87,15 @@ describe('generateNewPanelIds', () => {
8787
{
8888
title: 'Section One',
8989
collapsed: true,
90-
gridData: {
90+
grid: {
9191
y: 6,
9292
i: '101',
9393
},
9494
panels: [
9595
{
96-
gridData: { x: 0, y: 0, w: 6, h: 6, i: '102' },
97-
panelConfig: { title: 'panel One' },
98-
panelIndex: '102',
96+
grid: { x: 0, y: 0, w: 6, h: 6, i: '102' },
97+
config: { title: 'panel One' },
98+
uid: '102',
9999
type: 'testPanelType',
100100
},
101101
],

src/platform/plugins/shared/dashboard/public/dashboard_api/generate_new_panel_ids.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@ export function generateNewPanelIds(panels: DashboardState['panels'], references
2323

2424
function generateNewPanelId(panel: DashboardPanel) {
2525
const newPanelId = v4();
26-
const oldPanelId = panel.panelIndex ?? panel.gridData.i;
26+
const oldPanelId = panel.uid ?? panel.grid.i;
2727
const panelReferences =
2828
oldPanelId && references ? getReferencesForPanelId(oldPanelId, references) : [];
2929

3030
newPanelReferences.push(...prefixReferencesFromPanel(newPanelId, panelReferences));
3131

3232
return {
3333
...panel,
34-
panelIndex: newPanelId,
35-
gridData: { ...panel.gridData, i: newPanelId },
34+
uid: newPanelId,
35+
grid: { ...panel.grid, i: newPanelId },
3636
};
3737
}
3838

@@ -42,7 +42,7 @@ export function generateNewPanelIds(panels: DashboardState['panels'], references
4242
const newSectionId = v4();
4343
newPanels.push({
4444
...section,
45-
gridData: { ...section.gridData, i: newSectionId },
45+
grid: { ...section.grid, i: newSectionId },
4646
panels: section.panels.map((panelInSection) => {
4747
return generateNewPanelId(panelInSection as DashboardPanel);
4848
}),

src/platform/plugins/shared/dashboard/public/dashboard_api/get_serialized_state.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ describe('getSerializedState', () => {
8787
it('should generate new IDs for panels and references when generateNewIds is true', () => {
8888
const dashboardState = {
8989
...getSampleDashboardState(),
90-
panels: [{ panelIndex: 'oldPanelId', type: 'visualization' } as DashboardPanel],
90+
panels: [{ uid: 'oldPanelId', type: 'visualization' } as DashboardPanel],
9191
};
9292
const result = getSerializedState({
9393
controlGroupReferences: [],
@@ -105,11 +105,11 @@ describe('getSerializedState', () => {
105105
expect(result.attributes.panels).toMatchInlineSnapshot(`
106106
Array [
107107
Object {
108-
"gridData": Object {
108+
"grid": Object {
109109
"i": "54321",
110110
},
111-
"panelIndex": "54321",
112111
"type": "visualization",
112+
"uid": "54321",
113113
},
114114
]
115115
`);

src/platform/plugins/shared/dashboard/public/dashboard_api/layout_manager/are_layouts_equal.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,7 @@ export const areLayoutsEqual = (originalLayout?: DashboardLayout, newLayout?: Da
4242
// then compare panel grid data
4343
for (const embeddableId of newPanelUuids) {
4444
if (
45-
!deepEqual(
46-
originalLayout?.panels[embeddableId]?.gridData,
47-
newLayout?.panels[embeddableId]?.gridData
48-
)
45+
!deepEqual(originalLayout?.panels[embeddableId]?.grid, newLayout?.panels[embeddableId]?.grid)
4946
) {
5047
return false;
5148
}

src/platform/plugins/shared/dashboard/public/dashboard_api/layout_manager/deserialize_layout.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,23 @@ describe('deserializeLayout', () => {
1414
const { layout, childState } = deserializeLayout(
1515
[
1616
{
17-
gridData: { x: 0, y: 0, w: 6, h: 6, i: '1' },
18-
panelConfig: { title: 'panel One' },
19-
panelIndex: '1',
17+
grid: { x: 0, y: 0, w: 6, h: 6, i: '1' },
18+
config: { title: 'panel One' },
19+
uid: '1',
2020
type: 'testPanelType',
2121
},
2222
{
2323
title: 'Section One',
2424
collapsed: true,
25-
gridData: {
25+
grid: {
2626
y: 6,
2727
i: 'section1',
2828
},
2929
panels: [
3030
{
31-
gridData: { x: 0, y: 0, w: 6, h: 6, i: '3' },
32-
panelConfig: { title: 'panel Three' },
33-
panelIndex: '3',
31+
grid: { x: 0, y: 0, w: 6, h: 6, i: '3' },
32+
config: { title: 'panel Three' },
33+
uid: '3',
3434
type: 'testPanelType',
3535
},
3636
],
@@ -41,7 +41,7 @@ describe('deserializeLayout', () => {
4141
expect(layout.panels).toMatchInlineSnapshot(`
4242
Object {
4343
"1": Object {
44-
"gridData": Object {
44+
"grid": Object {
4545
"h": 6,
4646
"i": "1",
4747
"w": 6,
@@ -51,7 +51,7 @@ describe('deserializeLayout', () => {
5151
"type": "testPanelType",
5252
},
5353
"3": Object {
54-
"gridData": Object {
54+
"grid": Object {
5555
"h": 6,
5656
"i": "3",
5757
"sectionId": "section1",
@@ -67,7 +67,7 @@ describe('deserializeLayout', () => {
6767
Object {
6868
"section1": Object {
6969
"collapsed": true,
70-
"gridData": Object {
70+
"grid": Object {
7171
"i": "section1",
7272
"y": 6,
7373
},

src/platform/plugins/shared/dashboard/public/dashboard_api/layout_manager/deserialize_layout.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,32 +24,32 @@ export function deserializeLayout(
2424
const childState: DashboardChildState = {};
2525

2626
function pushPanel(panel: DashboardPanel, sectionId?: string) {
27-
const panelId = panel.panelIndex ?? v4();
27+
const panelId = panel.uid ?? v4();
2828
layout.panels[panelId] = {
2929
type: panel.type,
30-
gridData: {
31-
...panel.gridData,
30+
grid: {
31+
...panel.grid,
3232
...(sectionId && { sectionId }),
3333
i: panelId,
3434
},
3535
};
3636
childState[panelId] = {
3737
rawState: {
38-
...panel.panelConfig,
38+
...panel.config,
3939
},
4040
references: getReferences(panelId),
4141
};
4242
}
4343

4444
panels.forEach((widget) => {
4545
if (isDashboardSection(widget)) {
46-
const sectionId = widget.gridData.i ?? v4();
46+
const sectionId = widget.grid.i ?? v4();
4747
const { panels: sectionPanels, ...restOfSection } = widget;
4848
layout.sections[sectionId] = {
4949
collapsed: false,
5050
...restOfSection,
51-
gridData: {
52-
...widget.gridData,
51+
grid: {
52+
...widget.grid,
5353
i: sectionId,
5454
},
5555
};

0 commit comments

Comments
 (0)