From 1c73d3db69611f84912a4c36f463cd0e2be1f453 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Guerraz Date: Wed, 6 Jan 2021 18:47:21 +0100 Subject: [PATCH] variables query: ensure query is object --- src/QueryEditor.tsx | 12 ++++++++++-- src/VariableQueryEditor.tsx | 12 ++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/QueryEditor.tsx b/src/QueryEditor.tsx index d931294..031025b 100644 --- a/src/QueryEditor.tsx +++ b/src/QueryEditor.tsx @@ -30,16 +30,24 @@ export class QueryEditor extends PureComponent { onBuilderOptionsChange = (queryBuilderOptions: QueryBuilderOptions) => { const { query, onChange, onRunQuery } = this.props; + //workaround: https://github.com/grafana/grafana/issues/30013 - query.expr = JSON.stringify({ builder: query.builder, settings: query.settings }); + if (typeof query === 'object') { + query.expr = JSON.stringify({ builder: query.builder, settings: query.settings }); + } + onChange({ ...query, ...queryBuilderOptions }); onRunQuery(); }; onSettingsOptionsChange = (querySettingsOptions: QuerySettingsOptions) => { const { query, onChange, onRunQuery } = this.props; + //workaround: https://github.com/grafana/grafana/issues/30013 - query.expr = JSON.stringify({ builder: query.builder, settings: query.settings }); + if (typeof query === 'object') { + query.expr = JSON.stringify({ builder: query.builder, settings: query.settings }); + } + onChange({ ...query, ...querySettingsOptions }); onRunQuery(); }; diff --git a/src/VariableQueryEditor.tsx b/src/VariableQueryEditor.tsx index ee976e7..6fbc0bd 100644 --- a/src/VariableQueryEditor.tsx +++ b/src/VariableQueryEditor.tsx @@ -32,15 +32,23 @@ export class VariableQueryEditor extends PureComponent { onBuilderOptionsChange = (queryBuilderOptions: QueryBuilderOptions) => { const { query, onChange } = this.props; + //workaround: https://github.com/grafana/grafana/issues/30013 - query.expr = JSON.stringify({ builder: query.builder, settings: query.settings }); + if (typeof query === 'object') { + query.expr = JSON.stringify({ builder: query.builder, settings: query.settings }); + } + onChange({ ...query, ...queryBuilderOptions }, query.expr); }; onSettingsOptionsChange = (querySettingsOptions: QuerySettingsOptions) => { const { query, onChange } = this.props; + //workaround: https://github.com/grafana/grafana/issues/30013 - query.expr = JSON.stringify({ builder: query.builder, settings: query.settings }); + if (typeof query === 'object') { + query.expr = JSON.stringify({ builder: query.builder, settings: query.settings }); + } + onChange({ ...query, ...querySettingsOptions }, query.expr); };