From ffc18ebbcf0f3ca5c6bb45cffb94cadb358dc537 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=A4ggmark?= Date: Tue, 22 Jun 2021 08:53:41 +0200 Subject: [PATCH] Variables: Fix for changing readonly query property (#35992) * Variables: Fix for changing readonly query property * Docs: adds release * Docs: adds release --- packages/grafana-e2e-selectors/src/types/selectors.ts | 9 +++++++++ public/app/features/variables/query/queryRunners.test.ts | 1 + public/app/features/variables/query/queryRunners.ts | 5 +---- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/grafana-e2e-selectors/src/types/selectors.ts b/packages/grafana-e2e-selectors/src/types/selectors.ts index e58a9251cac..f19c55f5628 100644 --- a/packages/grafana-e2e-selectors/src/types/selectors.ts +++ b/packages/grafana-e2e-selectors/src/types/selectors.ts @@ -2,14 +2,23 @@ export type StringSelector = string; export type FunctionSelector = (id: string) => string; export type CssSelector = () => string; +/** + * @alpha + */ export interface Selectors { [key: string]: StringSelector | FunctionSelector | CssSelector | UrlSelector | Selectors; } +/** + * @alpha + */ export type E2ESelectors = { [P in keyof S]: S[P]; }; +/** + * @alpha + */ export interface UrlSelector extends Selectors { url: string | FunctionSelector; } diff --git a/public/app/features/variables/query/queryRunners.test.ts b/public/app/features/variables/query/queryRunners.test.ts index 3d76a655f62..066defdd32a 100644 --- a/public/app/features/variables/query/queryRunners.test.ts +++ b/public/app/features/variables/query/queryRunners.test.ts @@ -293,6 +293,7 @@ describe('QueryRunners', () => { const target = runner.getTarget({ datasource, variable }); expect(target).toEqual({ refId: 'A', query: 'A query' }); }); + describe('and ref id is missing', () => { it('then it should return correct target with dummy ref id', () => { const { runner, datasource, variable } = getDatasourceTestContext(); diff --git a/public/app/features/variables/query/queryRunners.ts b/public/app/features/variables/query/queryRunners.ts index b014d07034d..38d7fa60c12 100644 --- a/public/app/features/variables/query/queryRunners.ts +++ b/public/app/features/variables/query/queryRunners.ts @@ -160,10 +160,7 @@ class DatasourceQueryRunner implements QueryRunner { getTarget({ datasource, variable }: GetTargetArgs) { if (hasDatasourceVariableSupport(datasource)) { - if (!variable.query.refId) { - variable.query.refId = variableDummyRefId; - } - return variable.query; + return { ...variable.query, refId: variable.query.refId ?? variableDummyRefId }; } throw new Error("Couldn't create a target with supplied arguments.");