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

update assumption that panelIndex may be missing #44793

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
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { i18n } from '@kbn/i18n';
import semver from 'semver';
import { GridData } from 'src/legacy/core_plugins/dashboard_embeddable_container/public/np_ready/public';

import uuid from 'uuid';
import {
RawSavedDashboardPanelTo60,
RawSavedDashboardPanel630,
Expand Down Expand Up @@ -123,16 +124,17 @@ function migratePre61PanelToLatest(

const { columns, sort, row, col, size_x: sizeX, size_y: sizeY, ...rest } = panel;

const panelIndex = panel.panelIndex ? panel.panelIndex.toString() : uuid.v4();
return {
...rest,
version,
panelIndex: panel.panelIndex.toString(),
panelIndex,
gridData: {
x: (col - 1) * PANEL_WIDTH_SCALE_FACTOR,
y: (row - 1) * heightScaleFactor,
w: sizeX ? sizeX * PANEL_WIDTH_SCALE_FACTOR : DEFAULT_PANEL_WIDTH,
h: sizeY ? sizeY * heightScaleFactor : DEFAULT_PANEL_HEIGHT,
i: panel.panelIndex.toString(),
i: panelIndex,
},
embeddableConfig,
};
Expand Down Expand Up @@ -175,10 +177,11 @@ function migrate610PanelToLatest(
: PANEL_HEIGHT_SCALE_FACTOR;
const { columns, sort, ...rest } = panel;

const panelIndex = panel.panelIndex ? panel.panelIndex.toString() : uuid.v4();
return {
...rest,
version,
panelIndex: panel.panelIndex.toString(),
panelIndex,
gridData: {
w: panel.gridData.w * PANEL_WIDTH_SCALE_FACTOR,
h: panel.gridData.h * heightScaleFactor,
Expand Down Expand Up @@ -212,10 +215,11 @@ function migrate620PanelToLatest(
: PANEL_HEIGHT_SCALE_FACTOR;
const { columns, sort, ...rest } = panel;

const panelIndex = panel.panelIndex ? panel.panelIndex.toString() : uuid.v4();
return {
...rest,
version,
panelIndex: panel.panelIndex.toString(),
panelIndex,
gridData: {
w: panel.gridData.w * PANEL_WIDTH_SCALE_FACTOR,
h: panel.gridData.h * heightScaleFactor,
Expand All @@ -242,10 +246,11 @@ function migrate630PanelToLatest(
}

const { columns, sort, ...rest } = panel;
const panelIndex = panel.panelIndex ? panel.panelIndex.toString() : uuid.v4();
return {
...rest,
version,
panelIndex: panel.panelIndex.toString(),
panelIndex,
embeddableConfig,
};
}
Expand All @@ -256,10 +261,11 @@ function migrate640To720PanelsToLatest(
panel: RawSavedDashboardPanel630,
version: string
): RawSavedDashboardPanel730ToLatest {
const panelIndex = panel.panelIndex ? panel.panelIndex.toString() : uuid.v4();
return {
...panel,
version,
panelIndex: panel.panelIndex.toString(),
panelIndex,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,38 @@ test('dashboard migration 7.3.0 migrates filters to query on search source when
expect(newDoc.attributes.uiStateJSON).toBeUndefined();
});

// See https://github.com/elastic/kibana/issues/44639 - apparently this can happen.
test('dashboard migration works when panelsJSON is missing panelIndex', () => {
const doc: DashboardDoc700To720 = {
id: '1',
type: 'dashboard',
references: [],
attributes: {
description: '',
uiStateJSON: '{}',
title: 'fancy stuff',
timeRestore: true,
version: 1,
panelsJSON:
'[{"id":"funky-funky","type":"visualization","size_x":7,"size_y":5,"col":1,"row":1},{"id":"funky-funky2","type":"search","size_x":5,"size_y":5,"col":8,"row":1,"columns":["_source"],"sort":["@timestamp","desc"]}]',
optionsJSON: '{"darkTheme":false}',
kibanaSavedObjectMeta: {
searchSourceJSON:
'{"filter":[{"query":{"query_string":{"query":"user:spiderman","analyze_wildcard":true}}}]}',
},
},
};

const doc700: DashboardDoc700To720 = migrations.dashboard['7.0.0'](doc, mockLogger);
const newDoc = migrations.dashboard['7.3.0'](doc700, mockLogger);

const parsedSearchSource = JSON.parse(newDoc.attributes.kibanaSavedObjectMeta.searchSourceJSON);
expect(parsedSearchSource.filter.length).toBe(0);
expect(parsedSearchSource.query.query).toBe('user:spiderman');

expect(newDoc.attributes.uiStateJSON).toBeUndefined();
});

test('dashboard migration 7.3.0 migrates panels', () => {
const doc: DashboardDoc700To720 = {
id: '1',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export interface RawSavedDashboardPanelTo60 {
readonly size_y?: number;
readonly row: number;
readonly col: number;
panelIndex: number | string; // earlier versions allowed this to be number or string
panelIndex?: number | string; // earlier versions allowed this to be number or string. Some very early versions seem to be missing this entirely
readonly name: string;

// This is where custom panel titles are stored prior to Embeddable API v2
Expand Down