Skip to content

Commit

Permalink
variables query: ensure query is object
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-Baptiste Guerraz committed Jan 6, 2021
1 parent 58c9448 commit 1c73d3d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
12 changes: 10 additions & 2 deletions src/QueryEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,24 @@ export class QueryEditor extends PureComponent<Props, State> {

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();
};
Expand Down
12 changes: 10 additions & 2 deletions src/VariableQueryEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,23 @@ export class VariableQueryEditor extends PureComponent<Props, State> {

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);
};

Expand Down

0 comments on commit 1c73d3d

Please sign in to comment.