DashboardScene: Fixes saving dashboard with angular panels (#86098)
* DashboardScene: Fixes saving angularOptions * Update * Update
This commit is contained in:
+6
-3
@@ -2538,16 +2538,19 @@ exports[`better eslint`] = {
|
|||||||
[0, 0, 0, "Unexpected any. Specify a different type.", "8"],
|
[0, 0, 0, "Unexpected any. Specify a different type.", "8"],
|
||||||
[0, 0, 0, "Unexpected any. Specify a different type.", "9"],
|
[0, 0, 0, "Unexpected any. Specify a different type.", "9"],
|
||||||
[0, 0, 0, "Unexpected any. Specify a different type.", "10"],
|
[0, 0, 0, "Unexpected any. Specify a different type.", "10"],
|
||||||
[0, 0, 0, "Unexpected any. Specify a different type.", "11"]
|
[0, 0, 0, "Unexpected any. Specify a different type.", "11"],
|
||||||
|
[0, 0, 0, "Unexpected any. Specify a different type.", "12"]
|
||||||
],
|
],
|
||||||
"public/app/features/dashboard-scene/serialization/transformSceneToSaveModel.ts:5381": [
|
"public/app/features/dashboard-scene/serialization/transformSceneToSaveModel.ts:5381": [
|
||||||
[0, 0, 0, "Do not use any type assertions.", "0"],
|
[0, 0, 0, "Do not use any type assertions.", "0"],
|
||||||
[0, 0, 0, "Do not use any type assertions.", "1"],
|
[0, 0, 0, "Do not use any type assertions.", "1"],
|
||||||
[0, 0, 0, "Do not use any type assertions.", "2"],
|
[0, 0, 0, "Do not use any type assertions.", "2"],
|
||||||
[0, 0, 0, "Do not use any type assertions.", "3"],
|
[0, 0, 0, "Unexpected any. Specify a different type.", "3"],
|
||||||
[0, 0, 0, "Do not use any type assertions.", "4"],
|
[0, 0, 0, "Do not use any type assertions.", "4"],
|
||||||
[0, 0, 0, "Do not use any type assertions.", "5"],
|
[0, 0, 0, "Do not use any type assertions.", "5"],
|
||||||
[0, 0, 0, "Do not use any type assertions.", "6"]
|
[0, 0, 0, "Do not use any type assertions.", "6"],
|
||||||
|
[0, 0, 0, "Do not use any type assertions.", "7"],
|
||||||
|
[0, 0, 0, "Do not use any type assertions.", "8"]
|
||||||
],
|
],
|
||||||
"public/app/features/dashboard-scene/settings/VersionsEditView.tsx:5381": [
|
"public/app/features/dashboard-scene/settings/VersionsEditView.tsx:5381": [
|
||||||
[0, 0, 0, "\'HorizontalGroup\' import from \'@grafana/ui\' is restricted from being used by a pattern. Use Stack component instead.", "0"]
|
[0, 0, 0, "\'HorizontalGroup\' import from \'@grafana/ui\' is restricted from being used by a pattern. Use Stack component instead.", "0"]
|
||||||
|
|||||||
@@ -260,6 +260,22 @@ describe('transformSceneToSaveModel', () => {
|
|||||||
expect(saveModel.transparent).toBe(true);
|
expect(saveModel.transparent).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('With angular options', () => {
|
||||||
|
const gridItem = buildGridItemFromPanelSchema({});
|
||||||
|
const vizPanel = gridItem.state.body as VizPanel;
|
||||||
|
vizPanel.setState({
|
||||||
|
options: {
|
||||||
|
angularOptions: {
|
||||||
|
bars: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const saveModel = gridItemToPanel(gridItem);
|
||||||
|
expect(saveModel.options?.angularOptions).toBe(undefined);
|
||||||
|
expect((saveModel as any).bars).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
it('Given panel with repeat', () => {
|
it('Given panel with repeat', () => {
|
||||||
const gridItem = buildGridItemFromPanelSchema({
|
const gridItem = buildGridItemFromPanelSchema({
|
||||||
title: '',
|
title: '',
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { isEqual } from 'lodash';
|
import { defaults, isEqual } from 'lodash';
|
||||||
|
|
||||||
import { isEmptyObject, ScopedVars, TimeRange } from '@grafana/data';
|
import { isEmptyObject, ScopedVars, TimeRange } from '@grafana/data';
|
||||||
import {
|
import {
|
||||||
@@ -232,7 +232,6 @@ export function vizPanelToPanel(
|
|||||||
title: vizPanel.state.title,
|
title: vizPanel.state.title,
|
||||||
description: vizPanel.state.description ?? undefined,
|
description: vizPanel.state.description ?? undefined,
|
||||||
gridPos,
|
gridPos,
|
||||||
options: vizPanel.state.options,
|
|
||||||
fieldConfig: (vizPanel.state.fieldConfig as FieldConfigSource) ?? { defaults: {}, overrides: [] },
|
fieldConfig: (vizPanel.state.fieldConfig as FieldConfigSource) ?? { defaults: {}, overrides: [] },
|
||||||
transformations: [],
|
transformations: [],
|
||||||
transparent: vizPanel.state.displayMode === 'transparent',
|
transparent: vizPanel.state.displayMode === 'transparent',
|
||||||
@@ -240,6 +239,16 @@ export function vizPanelToPanel(
|
|||||||
...vizPanelDataToPanel(vizPanel, isSnapshot),
|
...vizPanelDataToPanel(vizPanel, isSnapshot),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (vizPanel.state.options) {
|
||||||
|
const { angularOptions, ...rest } = vizPanel.state.options as any;
|
||||||
|
panel.options = rest;
|
||||||
|
|
||||||
|
if (angularOptions) {
|
||||||
|
// Allow angularOptions to overwrite non system level root properties
|
||||||
|
defaults(panel, angularOptions);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const panelTime = vizPanel.state.$timeRange;
|
const panelTime = vizPanel.state.$timeRange;
|
||||||
|
|
||||||
if (panelTime instanceof PanelTimeRange) {
|
if (panelTime instanceof PanelTimeRange) {
|
||||||
@@ -275,6 +284,7 @@ export function vizPanelToPanel(
|
|||||||
if (!panel.transparent) {
|
if (!panel.transparent) {
|
||||||
delete panel.transparent;
|
delete panel.transparent;
|
||||||
}
|
}
|
||||||
|
|
||||||
return panel;
|
return panel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user