Dash-SchemaV2: Don't persist undefined fields (#98493)

Don't persist undefined values
This commit is contained in:
Haris Rozajac 2025-01-07 10:54:56 -07:00 committed by GitHub
parent 79c61bcc3c
commit 8b72e2188a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 11 additions and 11 deletions

View File

@ -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',

View File

@ -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",

View File

@ -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 = {

View File

@ -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;