mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Scenes/Dashboards: Fix issue where changes in panel height weren't saved (#91125)
* Scenes/Dashboards: Fix issue where changes in panel height weren't saved
This commit is contained in:
parent
35315f43fe
commit
b80e16075f
@ -2906,7 +2906,9 @@ exports[`better eslint`] = {
|
|||||||
[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"]
|
[0, 0, 0, "Unexpected any. Specify a different type.", "12"],
|
||||||
|
[0, 0, 0, "Unexpected any. Specify a different type.", "13"],
|
||||||
|
[0, 0, 0, "Unexpected any. Specify a different type.", "14"]
|
||||||
],
|
],
|
||||||
"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"],
|
||||||
|
@ -15,7 +15,14 @@ import {
|
|||||||
} from '@grafana/data';
|
} from '@grafana/data';
|
||||||
import { getPanelPlugin } from '@grafana/data/test/__mocks__/pluginMocks';
|
import { getPanelPlugin } from '@grafana/data/test/__mocks__/pluginMocks';
|
||||||
import { getPluginLinkExtensions, setPluginImportUtils } from '@grafana/runtime';
|
import { getPluginLinkExtensions, setPluginImportUtils } from '@grafana/runtime';
|
||||||
import { MultiValueVariable, SceneGridLayout, SceneGridRow, SceneTimeRange, VizPanel } from '@grafana/scenes';
|
import {
|
||||||
|
MultiValueVariable,
|
||||||
|
sceneGraph,
|
||||||
|
SceneGridLayout,
|
||||||
|
SceneGridRow,
|
||||||
|
SceneTimeRange,
|
||||||
|
VizPanel,
|
||||||
|
} from '@grafana/scenes';
|
||||||
import { Dashboard, LoadingState, Panel, RowPanel, VariableRefresh } from '@grafana/schema';
|
import { Dashboard, LoadingState, Panel, RowPanel, VariableRefresh } from '@grafana/schema';
|
||||||
import { PanelModel } from 'app/features/dashboard/state';
|
import { PanelModel } from 'app/features/dashboard/state';
|
||||||
import { getTimeRange } from 'app/features/dashboard/utils/timeRange';
|
import { getTimeRange } from 'app/features/dashboard/utils/timeRange';
|
||||||
@ -1094,6 +1101,37 @@ describe('transformSceneToSaveModel', () => {
|
|||||||
expect((saveModel.panels![1] as any).options.content).toBe('new content');
|
expect((saveModel.panels![1] as any).options.content).toBe('new content');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('Given a scene with repeated panels and non-repeated panels', () => {
|
||||||
|
it('should save repeated panels itemHeight as height', () => {
|
||||||
|
const scene = transformSaveModelToScene({ dashboard: repeatingRowsAndPanelsDashboardJson as any, meta: {} });
|
||||||
|
const gridItem = sceneGraph.findByKey(scene, 'grid-item-2') as DashboardGridItem;
|
||||||
|
expect(gridItem).toBeInstanceOf(DashboardGridItem);
|
||||||
|
expect(gridItem.state.height).toBe(10);
|
||||||
|
expect(gridItem.state.itemHeight).toBe(10);
|
||||||
|
expect(gridItem.state.itemHeight).toBe(10);
|
||||||
|
expect(gridItem.state.variableName).toBe('pod');
|
||||||
|
gridItem.setState({ itemHeight: 24 });
|
||||||
|
const saveModel = transformSceneToSaveModel(scene);
|
||||||
|
expect(saveModel.panels?.[3].gridPos?.h).toBe(24);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not save non-repeated panels itemHeight as height', () => {
|
||||||
|
const scene = transformSaveModelToScene({ dashboard: repeatingRowsAndPanelsDashboardJson as any, meta: {} });
|
||||||
|
const gridItem = sceneGraph.findByKey(scene, 'grid-item-15') as DashboardGridItem;
|
||||||
|
expect(gridItem).toBeInstanceOf(DashboardGridItem);
|
||||||
|
expect(gridItem.state.height).toBe(2);
|
||||||
|
expect(gridItem.state.itemHeight).toBe(2);
|
||||||
|
expect(gridItem.state.variableName).toBeUndefined();
|
||||||
|
gridItem.setState({ itemHeight: 24 });
|
||||||
|
let saveModel = transformSceneToSaveModel(scene);
|
||||||
|
expect(saveModel.panels?.[1].gridPos?.h).toBe(2);
|
||||||
|
|
||||||
|
gridItem.setState({ height: 34 });
|
||||||
|
saveModel = transformSceneToSaveModel(scene);
|
||||||
|
expect(saveModel.panels?.[1].gridPos?.h).toBe(34);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
export function buildGridItemFromPanelSchema(panel: Partial<Panel>) {
|
export function buildGridItemFromPanelSchema(panel: Partial<Panel>) {
|
||||||
|
@ -200,7 +200,7 @@ export function gridItemToPanel(
|
|||||||
x = gridItem_.state.x ?? 0;
|
x = gridItem_.state.x ?? 0;
|
||||||
y = gridItem_.state.y ?? 0;
|
y = gridItem_.state.y ?? 0;
|
||||||
w = gridItem_.state.width ?? 0;
|
w = gridItem_.state.width ?? 0;
|
||||||
h = gridItem_.state.itemHeight ?? gridItem_.state.height ?? 0;
|
h = (gridItem_.state.variableName ? gridItem_.state.itemHeight : gridItem_.state.height) ?? 0;
|
||||||
|
|
||||||
if (!vizPanel) {
|
if (!vizPanel) {
|
||||||
throw new Error('Unsupported grid item type');
|
throw new Error('Unsupported grid item type');
|
||||||
|
Loading…
Reference in New Issue
Block a user