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

[Portable Dashboards] Remove Saved Object Class #138774

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
bbfc992
Replaced dashboard loading, removed savedDashboard from app state
ThomThomson Aug 10, 2022
94dedf1
Merge branch 'main' of https://github.com/elastic/kibana into portabl…
ThomThomson Aug 10, 2022
989e377
Added dashboard save util
ThomThomson Aug 12, 2022
b9b2f98
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Aug 12, 2022
f2576c1
Merge branch 'main' of https://github.com/elastic/kibana into portabl…
ThomThomson Aug 29, 2022
08e72f3
Removed dashboard saved object class
ThomThomson Sep 9, 2022
7963ffb
Merge branch 'portableDashboard/removeSavedObjectClass' of https://gi…
ThomThomson Sep 9, 2022
f90e5ce
Merge branch 'main' of https://github.com/elastic/kibana into portabl…
ThomThomson Sep 9, 2022
3abdb38
fix types, jest tests, and skip loading panels when any panel has a v…
ThomThomson Sep 9, 2022
b9da296
Merge branch 'main' of https://github.com/elastic/kibana into portabl…
ThomThomson Sep 9, 2022
1ccc78a
jest test import fixes
ThomThomson Sep 9, 2022
42e3991
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Sep 9, 2022
a06e8b8
More type fixes and jest test fixes
ThomThomson Sep 13, 2022
f8c9390
some functional test fixes
ThomThomson Sep 13, 2022
2b52d04
Merge branch 'portableDashboard/removeSavedObjectClass' of https://gi…
ThomThomson Sep 13, 2022
1453d75
more type fixes - fixed clone modal not applying title
ThomThomson Sep 13, 2022
b56ecdf
Merge branch 'main' of https://github.com/elastic/kibana into portabl…
ThomThomson Sep 13, 2022
e8bb483
dashboard import change for ML
ThomThomson Sep 13, 2022
9801890
Fix locator getFilterFields to async import
ThomThomson Sep 13, 2022
0063716
Merge branch 'main' of https://github.com/elastic/kibana into portabl…
ThomThomson Sep 14, 2022
5989797
Create and implement dashboard saved objects service
ThomThomson Sep 19, 2022
7caa447
remove unused lib functions, rules of hooks
ThomThomson Sep 19, 2022
0db6bae
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Sep 19, 2022
7f12bbc
type fixes
ThomThomson Sep 19, 2022
eef0a73
Merge branch 'portableDashboard/removeSavedObjectClass' of https://gi…
ThomThomson Sep 19, 2022
48a6b25
remove duplicate import from merge
ThomThomson Sep 19, 2022
43eb8e2
shrink bundle size, fix jest tests
ThomThomson Sep 19, 2022
0cd0bf1
restore export
ThomThomson Sep 19, 2022
52fd415
remove dashboard constants from functional tests. Fix action imports
ThomThomson Sep 20, 2022
829a7ec
Merge branch 'main' of https://github.com/elastic/kibana into portabl…
ThomThomson Sep 20, 2022
401c318
finish merge
ThomThomson Sep 20, 2022
3d11c44
fix types, dashboard security test
ThomThomson Sep 20, 2022
5a6cac1
Merge branch 'main' of https://github.com/elastic/kibana into portabl…
ThomThomson Sep 20, 2022
7abfc42
Fix security tests, remove top level export and unify dashboard const…
ThomThomson Sep 20, 2022
f0613bf
add error handling to load case
ThomThomson Sep 21, 2022
d1f5f97
import viewMode from embeddable common
ThomThomson Sep 21, 2022
28e99e3
Merge branch 'main' of https://github.com/elastic/kibana into portabl…
ThomThomson Sep 22, 2022
a625b3d
Merge branch 'main' of https://github.com/elastic/kibana into portabl…
ThomThomson Sep 22, 2022
8c136f2
resolve merge issue
ThomThomson Sep 22, 2022
4448541
Merge branch 'main' of https://github.com/elastic/kibana into portabl…
ThomThomson Sep 23, 2022
26103a4
Merge branch 'main' of https://github.com/elastic/kibana into portabl…
ThomThomson Sep 23, 2022
488024a
Merge branch 'main' of https://github.com/elastic/kibana into portabl…
ThomThomson Sep 26, 2022
ad7e29c
Address review comments
ThomThomson Sep 27, 2022
05fb7ee
Merge branch 'main' into portableDashboard/removeSavedObjectClass
kibanamachine Sep 27, 2022
1d93a4d
Undo change which backed up time range into session storage
ThomThomson Sep 27, 2022
1fc1f55
remove extra conditional from duplicate title check
ThomThomson Sep 28, 2022
474b6ed
Merge branch 'main' into portableDashboard/removeSavedObjectClass
kibanamachine Sep 28, 2022
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

This file was deleted.

This file was deleted.

32 changes: 18 additions & 14 deletions src/plugins/dashboard/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,28 @@
* Side Public License, v 1.
*/

export type { GridData } from './embeddable/types';
export type {
RawSavedDashboardPanel730ToLatest,
DashboardDoc730ToLatest,
DashboardDoc700To720,
DashboardDocPre700,
} from './bwc/types';
export type {
GridData,
DashboardPanelMap,
SavedDashboardPanel,
DashboardAttributes,
DashboardPanelState,
DashboardContainerStateWithType,
SavedDashboardPanelTo60,
SavedDashboardPanel610,
SavedDashboardPanel620,
SavedDashboardPanel630,
SavedDashboardPanel640To720,
SavedDashboardPanel730ToLatest,
} from './types';

export { migratePanelsTo730 } from './migrate_to_730_panels';
export {
injectReferences,
extractReferences,
} from './persistable_state/dashboard_saved_object_references';

export { createInject, createExtract } from './persistable_state/dashboard_container_references';

export {
convertPanelStateToSavedDashboardPanel,
convertSavedDashboardPanelToPanelState,
convertSavedPanelsToPanelMap,
convertPanelMapToSavedPanels,
} from './lib/dashboard_panel_converters';

export const UI_SETTINGS = {
ENABLE_LABS_UI: 'labs:dashboard:enable_ui',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import {
convertSavedDashboardPanelToPanelState,
convertPanelStateToSavedDashboardPanel,
} from './embeddable_saved_object_converters';
} from './dashboard_panel_converters';
import { SavedDashboardPanel, DashboardPanelState } from '../types';
import { EmbeddableInput } from '@kbn/embeddable-plugin/common/types';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import { omit } from 'lodash';
import { EmbeddableInput, SavedObjectEmbeddableInput } from '@kbn/embeddable-plugin/common';
import { DashboardPanelState, SavedDashboardPanel } from '../types';
import { DashboardPanelMap, DashboardPanelState, SavedDashboardPanel } from '../types';

export function convertSavedDashboardPanelToPanelState<
TEmbeddableInput extends EmbeddableInput | SavedObjectEmbeddableInput = SavedObjectEmbeddableInput
Expand Down Expand Up @@ -42,3 +42,17 @@ export function convertPanelStateToSavedDashboardPanel(
...(panelState.panelRefName !== undefined && { panelRefName: panelState.panelRefName }),
};
}

export const convertSavedPanelsToPanelMap = (panels?: SavedDashboardPanel[]): DashboardPanelMap => {
const panelsMap: DashboardPanelMap = {};
panels?.forEach((panel, idx) => {
panelsMap![panel.panelIndex ?? String(idx)] = convertSavedDashboardPanelToPanelState(panel);
});
return panelsMap;
};

export const convertPanelMapToSavedPanels = (panels: DashboardPanelMap, version: string) => {
return Object.values(panels).map((panel) =>
convertPanelStateToSavedDashboardPanel(panel, version)
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import { createExtract, createInject } from './dashboard_container_persistable_state';
import { createExtract, createInject } from './dashboard_container_references';
import { createEmbeddablePersistableStateServiceMock } from '@kbn/embeddable-plugin/common/mocks';
import { DashboardContainerStateWithType } from '../types';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import {
injectReferences,
InjectDeps,
ExtractDeps,
} from './saved_dashboard_references';
} from './dashboard_saved_object_references';

import { createExtract, createInject } from './embeddable/dashboard_container_persistable_state';
import { createExtract, createInject } from './dashboard_container_references';
import { createEmbeddablePersistableStateServiceMock } from '@kbn/embeddable-plugin/common/mocks';

const embeddablePersistableStateServiceMock = createEmbeddablePersistableStateServiceMock();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,33 @@
* Side Public License, v 1.
*/
import semverGt from 'semver/functions/gt';
import { SavedObjectAttributes, SavedObjectReference } from '@kbn/core/types';
import { EmbeddablePersistableStateService } from '@kbn/embeddable-plugin/common/types';

import {
PersistableControlGroupInput,
RawControlGroupAttributes,
PersistableControlGroupInput,
} from '@kbn/controls-plugin/common';
import { DashboardContainerStateWithType, DashboardPanelState } from './types';
import { SavedObjectAttributes, SavedObjectReference } from '@kbn/core/types';
import { EmbeddablePersistableStateService } from '@kbn/embeddable-plugin/common/types';

import {
SavedDashboardPanel,
DashboardPanelState,
DashboardContainerStateWithType,
} from '../types';
import {
convertPanelStateToSavedDashboardPanel,
convertSavedDashboardPanelToPanelState,
} from './embeddable/embeddable_saved_object_converters';
import { SavedDashboardPanel } from './types';
} from '../lib/dashboard_panel_converters';

interface ExtractDeps {
embeddablePersistableStateService: EmbeddablePersistableStateService;
}

export interface ExtractDeps {
interface InjectDeps {
embeddablePersistableStateService: EmbeddablePersistableStateService;
}
export interface SavedObjectAttributesAndReferences {

interface SavedObjectAttributesAndReferences {
attributes: SavedObjectAttributes;
references: SavedObjectReference[];
}
Expand Down Expand Up @@ -79,7 +89,7 @@ function panelStatesToPanels(
let originalPanel = originalPanels.find((p) => p.panelIndex === id);

if (!originalPanel) {
// Maybe original panel doesn't have a panel index and it's just straight up based on it's index
// Maybe original panel doesn't have a panel index and it's just straight up based on its index
const numericId = parseInt(id, 10);
originalPanel = isNaN(numericId) ? originalPanel : originalPanels[numericId];
}
Expand All @@ -91,6 +101,45 @@ function panelStatesToPanels(
});
}

export function injectReferences(
{ attributes, references = [] }: SavedObjectAttributesAndReferences,
deps: InjectDeps
): SavedObjectAttributes {
// Skip if panelsJSON is missing otherwise this will cause saved object import to fail when
// importing objects without panelsJSON. At development time of this, there is no guarantee each saved
// object has panelsJSON in all previous versions of kibana.
if (typeof attributes.panelsJSON !== 'string') {
return attributes;
}
const parsedPanels = JSON.parse(attributes.panelsJSON);
// Same here, prevent failing saved object import if ever panels aren't an array.
if (!Array.isArray(parsedPanels)) {
return attributes;
}

const { panels, state } = dashboardAttributesToState(attributes);

const injectedState = deps.embeddablePersistableStateService.inject(
state,
references
) as DashboardContainerStateWithType;
const injectedPanels = panelStatesToPanels(injectedState.panels, panels);

const newAttributes = {
...attributes,
panelsJSON: JSON.stringify(injectedPanels),
} as SavedObjectAttributes;

if (injectedState.controlGroupInput) {
newAttributes.controlGroupInput = {
...(attributes.controlGroupInput as SavedObjectAttributes),
panelsJSON: JSON.stringify(injectedState.controlGroupInput.panels),
};
}

return newAttributes;
}

export function extractReferences(
{ attributes, references = [] }: SavedObjectAttributesAndReferences,
deps: ExtractDeps
Expand Down Expand Up @@ -137,49 +186,6 @@ export function extractReferences(
};
}

export interface InjectDeps {
embeddablePersistableStateService: EmbeddablePersistableStateService;
}

export function injectReferences(
{ attributes, references = [] }: SavedObjectAttributesAndReferences,
deps: InjectDeps
): SavedObjectAttributes {
// Skip if panelsJSON is missing otherwise this will cause saved object import to fail when
// importing objects without panelsJSON. At development time of this, there is no guarantee each saved
// object has panelsJSON in all previous versions of kibana.
if (typeof attributes.panelsJSON !== 'string') {
return attributes;
}
const parsedPanels = JSON.parse(attributes.panelsJSON);
// Same here, prevent failing saved object import if ever panels aren't an array.
if (!Array.isArray(parsedPanels)) {
return attributes;
}

const { panels, state } = dashboardAttributesToState(attributes);

const injectedState = deps.embeddablePersistableStateService.inject(
state,
references
) as DashboardContainerStateWithType;
const injectedPanels = panelStatesToPanels(injectedState.panels, panels);

const newAttributes = {
...attributes,
panelsJSON: JSON.stringify(injectedPanels),
} as SavedObjectAttributes;

if (injectedState.controlGroupInput) {
newAttributes.controlGroupInput = {
...(attributes.controlGroupInput as SavedObjectAttributes),
panelsJSON: JSON.stringify(injectedState.controlGroupInput.panels),
};
}

return newAttributes;
}

function pre730ExtractReferences(
{ attributes, references = [] }: SavedObjectAttributesAndReferences,
deps: ExtractDeps
Expand Down
Loading