DashboardSchemaV2: Fix crash in response transformer (#103041)

* DashboardSchemaV2: Fix crash in response transformer

* update test only test for the missing current prop

* restore warning
pull/99012/head^2
Torkel Ödegaard 4 months ago committed by GitHub
parent 9eb5ed5db9
commit 1a53e85bc5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 13
      public/app/features/dashboard/api/ResponseTransformers.test.ts
  2. 4
      public/app/features/dashboard/api/ResponseTransformers.ts

@ -305,6 +305,15 @@ describe('ResponseTransformers', () => {
], ],
current: { value: ['1'], text: ['1'] }, current: { value: ['1'], text: ['1'] },
}, },
// Query variable with minimal props and without current
{
datasource: { type: 'prometheus', uid: 'abc' },
name: 'org_id',
label: 'Org ID',
hide: 2,
type: 'query',
query: { refId: 'A', query: 'label_values(grafanacloud_org_info{org_slug="$org_slug"}, org_id)' },
},
], ],
}, },
panels: [ panels: [
@ -627,6 +636,7 @@ describe('ResponseTransformers', () => {
validateVariablesV1ToV2(spec.variables[5], dashboardV1.templating?.list?.[5]); validateVariablesV1ToV2(spec.variables[5], dashboardV1.templating?.list?.[5]);
validateVariablesV1ToV2(spec.variables[6], dashboardV1.templating?.list?.[6]); validateVariablesV1ToV2(spec.variables[6], dashboardV1.templating?.list?.[6]);
validateVariablesV1ToV2(spec.variables[7], dashboardV1.templating?.list?.[7]); validateVariablesV1ToV2(spec.variables[7], dashboardV1.templating?.list?.[7]);
validateVariablesV1ToV2(spec.variables[8], dashboardV1.templating?.list?.[8]);
}); });
}); });
@ -938,8 +948,9 @@ describe('ResponseTransformers', () => {
label: v1.label, label: v1.label,
description: v1.description, description: v1.description,
hide: transformVariableHideToEnum(v1.hide), hide: transformVariableHideToEnum(v1.hide),
skipUrlSync: v1.skipUrlSync, skipUrlSync: Boolean(v1.skipUrlSync),
}; };
const v2Common = { const v2Common = {
name: v2.spec.name, name: v2.spec.name,
label: v2.spec.label, label: v2.spec.label,

@ -530,8 +530,8 @@ function getVariables(vars: TypedVariableModel[]): DashboardV2Spec['variables']
includeAll: Boolean(v.includeAll), includeAll: Boolean(v.includeAll),
...(v.allValue && { allValue: v.allValue }), ...(v.allValue && { allValue: v.allValue }),
current: { current: {
value: v.current.value, value: v.current?.value,
text: v.current.text, text: v.current?.text,
}, },
options: v.options || [], options: v.options || [],
refresh: transformVariableRefreshToEnum(v.refresh), refresh: transformVariableRefreshToEnum(v.refresh),

Loading…
Cancel
Save