mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Dash-SchemaV2: Don't persist undefined fields (#98493)
Don't persist undefined values
This commit is contained in:
parent
79c61bcc3c
commit
8b72e2188a
@ -37,7 +37,7 @@ export const handyTestingSchema: DashboardV2Spec = {
|
||||
type: 'prometheus',
|
||||
uid: 'uid',
|
||||
},
|
||||
filter: { ids: [] },
|
||||
filter: { ids: [1] },
|
||||
enable: true,
|
||||
hide: false,
|
||||
iconColor: 'rgba(0, 211, 255, 1)',
|
||||
@ -63,7 +63,6 @@ export const handyTestingSchema: DashboardV2Spec = {
|
||||
scenarioId: 'annotations',
|
||||
},
|
||||
},
|
||||
filter: { ids: [] },
|
||||
hide: true,
|
||||
},
|
||||
},
|
||||
@ -75,7 +74,6 @@ export const handyTestingSchema: DashboardV2Spec = {
|
||||
type: 'grafana-testdata-datasource',
|
||||
uid: 'uid',
|
||||
},
|
||||
filter: { ids: [] },
|
||||
enable: false,
|
||||
iconColor: 'yellow',
|
||||
name: 'Disabled',
|
||||
@ -94,7 +92,6 @@ export const handyTestingSchema: DashboardV2Spec = {
|
||||
type: 'grafana-testdata-datasource',
|
||||
uid: 'uid',
|
||||
},
|
||||
filter: { ids: [] },
|
||||
enable: true,
|
||||
hide: true,
|
||||
iconColor: 'dark-purple',
|
||||
@ -282,7 +279,6 @@ export const handyTestingSchema: DashboardV2Spec = {
|
||||
{
|
||||
kind: 'DatasourceVariable',
|
||||
spec: {
|
||||
allValue: undefined,
|
||||
current: {
|
||||
text: 'text1',
|
||||
value: 'value1',
|
||||
|
@ -12,7 +12,6 @@ exports[`transformSceneToSaveModelSchemaV2 should transform scene to save model
|
||||
"uid": "-- Grafana --",
|
||||
},
|
||||
"enable": true,
|
||||
"filter": undefined,
|
||||
"hide": false,
|
||||
"iconColor": "red",
|
||||
"name": "query1",
|
||||
@ -27,7 +26,6 @@ exports[`transformSceneToSaveModelSchemaV2 should transform scene to save model
|
||||
"uid": "abcdef",
|
||||
},
|
||||
"enable": true,
|
||||
"filter": undefined,
|
||||
"hide": true,
|
||||
"iconColor": "blue",
|
||||
"name": "query2",
|
||||
@ -42,7 +40,6 @@ exports[`transformSceneToSaveModelSchemaV2 should transform scene to save model
|
||||
"uid": "Loki",
|
||||
},
|
||||
"enable": true,
|
||||
"filter": undefined,
|
||||
"hide": true,
|
||||
"iconColor": "green",
|
||||
"name": "query3",
|
||||
@ -212,7 +209,6 @@ exports[`transformSceneToSaveModelSchemaV2 should transform scene to save model
|
||||
{
|
||||
"kind": "DatasourceVariable",
|
||||
"spec": {
|
||||
"allValue": undefined,
|
||||
"current": {
|
||||
"text": "text1",
|
||||
"value": "value1",
|
||||
|
@ -327,10 +327,14 @@ export function sceneVariablesSetToSchemaV2Variables(
|
||||
refresh: 'onDashboardLoad',
|
||||
pluginId: variable.state.pluginId,
|
||||
multi: variable.state.isMulti || false,
|
||||
allValue: variable.state.allValue,
|
||||
includeAll: variable.state.includeAll || false,
|
||||
},
|
||||
};
|
||||
|
||||
if (variable.state.allValue !== undefined) {
|
||||
datasourceVariable.spec.allValue = variable.state.allValue;
|
||||
}
|
||||
|
||||
variables.push(datasourceVariable);
|
||||
} else if (sceneUtils.isConstantVariable(variable)) {
|
||||
const constantVariable: ConstantVariableKind = {
|
||||
|
@ -407,7 +407,6 @@ function getAnnotations(state: DashboardSceneState): AnnotationQueryKind[] {
|
||||
datasource: layer.state.query.datasource || getDefaultDataSourceRef(),
|
||||
enable: Boolean(layer.state.isEnabled),
|
||||
hide: Boolean(layer.state.isHidden),
|
||||
filter: layer.state.query.filter,
|
||||
iconColor: layer.state.query.iconColor,
|
||||
},
|
||||
};
|
||||
@ -421,6 +420,11 @@ function getAnnotations(state: DashboardSceneState): AnnotationQueryKind[] {
|
||||
};
|
||||
}
|
||||
|
||||
// If filter is an empty array, don't save it
|
||||
if (layer.state.query.filter?.ids?.length) {
|
||||
result.spec.filter = layer.state.query.filter;
|
||||
}
|
||||
|
||||
annotations.push(result);
|
||||
}
|
||||
return annotations;
|
||||
|
Loading…
Reference in New Issue
Block a user