QueryEditor: Don't use _.defaults as it mutates the query prop directly (#37965)

* QueryEditor: Don't use _.defaults as it mutates the query prop directly

* QueryEditor: Update the query type on mount if none exists

* QueryEditor: Mutate in the constructor instead of render

* Apply defaults immutably in render
This commit is contained in:
Ashley Harrison 2021-08-25 10:19:02 +01:00 committed by GitHub
parent 65501cbad3
commit 7c97b9d03f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,5 +1,3 @@
import { defaults } from 'lodash';
import React, { PureComponent } from 'react';
import { InlineField, Select, Alert, Input } from '@grafana/ui';
import { QueryEditorProps, SelectableValue, dataFrameFromJSON, rangeUtil } from '@grafana/data';
@ -245,7 +243,11 @@ export class QueryEditor extends PureComponent<Props, State> {
}
render() {
const query = defaults(this.props.query, defaultQuery);
const query = {
...defaultQuery,
...this.props.query,
};
return (
<>
<div className="gf-form">