Dashboard: Dashboard schema fixes and scene to save model fixes (#81867)

This commit is contained in:
Torkel Ödegaard
2024-02-05 12:27:44 +01:00
committed by GitHub
parent 9fab7bd27d
commit 071b301e39
7 changed files with 25 additions and 51 deletions

View File

@@ -110,7 +110,6 @@ exports[`transformSceneToSaveModel Given a scene with rows Should transform back
"y": 1,
},
"id": 15,
"links": [],
"options": {
"code": {
"language": "plaintext",
@@ -124,9 +123,8 @@ exports[`transformSceneToSaveModel Given a scene with rows Should transform back
</div>",
"mode": "markdown",
},
"pluginVersion": "10.2.0-pre",
"title": "",
"transformations": [],
"transparent": false,
"type": "text",
},
{
@@ -165,7 +163,6 @@ exports[`transformSceneToSaveModel Given a scene with rows Should transform back
"y": 26,
},
"id": 30,
"links": [],
"options": {
"code": {
"language": "plaintext",
@@ -177,9 +174,8 @@ exports[`transformSceneToSaveModel Given a scene with rows Should transform back
</div>",
"mode": "markdown",
},
"pluginVersion": "10.2.0-pre",
"title": "Text panel in collapsed row",
"transformations": [],
"transparent": false,
"type": "text",
},
],
@@ -378,7 +374,6 @@ exports[`transformSceneToSaveModel Given a simple scene with custom settings Sho
"y": 0,
},
"id": 28,
"links": [],
"options": {
"legend": {
"calcs": [],
@@ -404,8 +399,6 @@ exports[`transformSceneToSaveModel Given a simple scene with custom settings Sho
},
],
"title": "Simple time series graph ",
"transformations": [],
"transparent": false,
"type": "timeseries",
},
{
@@ -437,7 +430,6 @@ exports[`transformSceneToSaveModel Given a simple scene with custom settings Sho
"y": 9,
},
"id": 29,
"links": [],
"options": {},
"targets": [
{
@@ -452,8 +444,6 @@ exports[`transformSceneToSaveModel Given a simple scene with custom settings Sho
},
],
"title": "panel inside row",
"transformations": [],
"transparent": false,
"type": "timeseries",
},
{
@@ -468,7 +458,6 @@ exports[`transformSceneToSaveModel Given a simple scene with custom settings Sho
"y": 9,
},
"id": 25,
"links": [],
"options": {
"code": {
"language": "plaintext",
@@ -478,8 +467,8 @@ exports[`transformSceneToSaveModel Given a simple scene with custom settings Sho
"content": "content",
"mode": "markdown",
},
"pluginVersion": "10.2.0-pre",
"title": "Transparent text panel",
"transformations": [],
"transparent": true,
"type": "text",
},
@@ -697,7 +686,6 @@ exports[`transformSceneToSaveModel Given a simple scene with variables Should tr
"y": 0,
},
"id": 28,
"links": [],
"options": {
"legend": {
"calcs": [],
@@ -723,8 +711,6 @@ exports[`transformSceneToSaveModel Given a simple scene with variables Should tr
},
],
"title": "Simple time series graph ",
"transformations": [],
"transparent": false,
"type": "timeseries",
},
{
@@ -756,7 +742,6 @@ exports[`transformSceneToSaveModel Given a simple scene with variables Should tr
"y": 9,
},
"id": 29,
"links": [],
"options": {},
"targets": [
{
@@ -771,8 +756,6 @@ exports[`transformSceneToSaveModel Given a simple scene with variables Should tr
},
],
"title": "panel inside row",
"transformations": [],
"transparent": false,
"type": "timeseries",
},
{
@@ -787,7 +770,6 @@ exports[`transformSceneToSaveModel Given a simple scene with variables Should tr
"y": 9,
},
"id": 25,
"links": [],
"options": {
"code": {
"language": "plaintext",
@@ -797,8 +779,8 @@ exports[`transformSceneToSaveModel Given a simple scene with variables Should tr
"content": "content",
"mode": "markdown",
},
"pluginVersion": "10.2.0-pre",
"title": "Transparent text panel",
"transformations": [],
"transparent": true,
"type": "text",
},

View File

@@ -7,7 +7,6 @@ import {
SceneGridLayout,
SceneGridRow,
VizPanel,
SceneQueryRunner,
SceneDataTransformer,
SceneVariableSet,
AdHocFilterSet,
@@ -39,7 +38,7 @@ import { PanelRepeaterGridItem } from '../scene/PanelRepeaterGridItem';
import { PanelTimeRange } from '../scene/PanelTimeRange';
import { RowRepeaterBehavior } from '../scene/RowRepeaterBehavior';
import { dashboardSceneGraph } from '../utils/dashboardSceneGraph';
import { getPanelIdForVizPanel } from '../utils/utils';
import { getPanelIdForVizPanel, getQueryRunnerFor } from '../utils/utils';
import { GRAFANA_DATASOURCE_REF } from './const';
import { dataLayersToAnnotations } from './dataLayersToAnnotations';
@@ -208,6 +207,7 @@ export function gridItemToPanel(gridItem: SceneGridItemLike, isSnapshot = false)
fieldConfig: (vizPanel.state.fieldConfig as FieldConfigSource) ?? { defaults: {}, overrides: [] },
transformations: [],
transparent: vizPanel.state.displayMode === 'transparent',
pluginVersion: vizPanel.state.pluginVersion,
...vizPanelDataToPanel(vizPanel, isSnapshot),
};
@@ -228,6 +228,18 @@ export function gridItemToPanel(gridItem: SceneGridItemLike, isSnapshot = false)
const panelLinks = dashboardSceneGraph.getPanelLinks(vizPanel);
panel.links = (panelLinks.state.rawLinks as DashboardLink[]) ?? [];
if (panel.links.length === 0) {
delete panel.links;
}
if (panel.transformations?.length === 0) {
delete panel.transformations;
}
if (!panel.transparent) {
delete panel.transparent;
}
return panel;
}
@@ -238,24 +250,15 @@ function vizPanelDataToPanel(
const dataProvider = vizPanel.state.$data;
const panel: Pick<Panel, 'datasource' | 'targets' | 'maxDataPoints' | 'transformations'> = {};
const queryRunner = getQueryRunnerFor(vizPanel);
// Regular queries handling
if (dataProvider instanceof SceneQueryRunner) {
panel.targets = dataProvider.state.queries;
panel.maxDataPoints = dataProvider.state.maxDataPoints;
panel.datasource = dataProvider.state.datasource;
if (queryRunner) {
panel.targets = queryRunner.state.queries;
panel.maxDataPoints = queryRunner.state.maxDataPoints;
panel.datasource = queryRunner.state.datasource;
}
// Transformations handling
if (dataProvider instanceof SceneDataTransformer) {
const panelData = dataProvider.state.$data;
if (panelData instanceof SceneQueryRunner) {
panel.targets = panelData.state.queries;
panel.maxDataPoints = panelData.state.maxDataPoints;
panel.datasource = panelData.state.datasource;
}
panel.transformations = dataProvider.state.transformations as DataTransformerConfig[];
}

View File

@@ -121,6 +121,8 @@ const defaults: any = {
cachedPluginOptions: {},
transparent: false,
options: {},
links: [],
transformations: [],
fieldConfig: {
defaults: {},
overrides: [],