[v11.0.x] DashboardScene: Fixes saving dashboard with angular panels (#86255)

DashboardScene: Fixes saving dashboard with angular panels  (#86098)

* DashboardScene: Fixes saving angularOptions

* Update

* Update

(cherry picked from commit e15beab362)

Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
This commit is contained in:
grafana-delivery-bot[bot]
2024-04-16 03:32:40 +02:00
committed by GitHub
co-authored by Torkel Ödegaard
parent 900080155c
commit ee1850dca3
3 changed files with 34 additions and 5 deletions
+6 -3
View File
@@ -2442,16 +2442,19 @@ exports[`better eslint`] = {
[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.", "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": [
[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.", "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.", "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/variables/components/VariableSelectField.tsx:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
@@ -260,6 +260,22 @@ describe('transformSceneToSaveModel', () => {
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', () => {
const gridItem = buildGridItemFromPanelSchema({
title: '',
@@ -1,4 +1,4 @@
import { isEqual } from 'lodash';
import { defaults, isEqual } from 'lodash';
import { isEmptyObject, ScopedVars, TimeRange } from '@grafana/data';
import {
@@ -232,7 +232,6 @@ export function vizPanelToPanel(
title: vizPanel.state.title,
description: vizPanel.state.description ?? undefined,
gridPos,
options: vizPanel.state.options,
fieldConfig: (vizPanel.state.fieldConfig as FieldConfigSource) ?? { defaults: {}, overrides: [] },
transformations: [],
transparent: vizPanel.state.displayMode === 'transparent',
@@ -240,6 +239,16 @@ export function vizPanelToPanel(
...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;
if (panelTime instanceof PanelTimeRange) {
@@ -275,6 +284,7 @@ export function vizPanelToPanel(
if (!panel.transparent) {
delete panel.transparent;
}
return panel;
}