QueryEditorRow: Fixes issue loading query editor when data source variable selected (#61927)

* QueryEditorRow: Fixes issue loading query editor when data source variable selected

* Fix func name

* Removed wait

* restore waiting for with better check

* restore waiting for with better check
pull/62182/head
Torkel Ödegaard 2 years ago committed by GitHub
parent a3b396854a
commit 9f7ddf1f0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      public/api-merged.json
  2. 10
      public/app/features/explore/spec/helper/setup.tsx
  3. 10
      public/app/features/query/components/QueryEditorRow.tsx

@ -19094,6 +19094,7 @@
} }
}, },
"receiver": { "receiver": {
"description": "Receiver receiver",
"type": "object", "type": "object",
"required": [ "required": [
"active", "active",

@ -6,9 +6,15 @@ import { Provider } from 'react-redux';
import { Route, Router } from 'react-router-dom'; import { Route, Router } from 'react-router-dom';
import { getGrafanaContextMock } from 'test/mocks/getGrafanaContextMock'; import { getGrafanaContextMock } from 'test/mocks/getGrafanaContextMock';
import { DataSourceApi, DataSourceInstanceSettings, QueryEditorProps, ScopedVars, UrlQueryValue } from '@grafana/data'; import {
DataSourceApi,
DataSourceInstanceSettings,
DataSourceRef,
QueryEditorProps,
ScopedVars,
UrlQueryValue,
} from '@grafana/data';
import { locationSearchToObject, locationService, setDataSourceSrv, setEchoSrv, config } from '@grafana/runtime'; import { locationSearchToObject, locationService, setDataSourceSrv, setEchoSrv, config } from '@grafana/runtime';
import { DataSourceRef } from '@grafana/schema';
import { GrafanaContext } from 'app/core/context/GrafanaContext'; import { GrafanaContext } from 'app/core/context/GrafanaContext';
import { GrafanaRoute } from 'app/core/navigation/GrafanaRoute'; import { GrafanaRoute } from 'app/core/navigation/GrafanaRoute';
import { Echo } from 'app/core/services/echo/Echo'; import { Echo } from 'app/core/services/echo/Echo';

@ -63,8 +63,10 @@ interface Props<TQuery extends DataQuery> {
} }
interface State<TQuery extends DataQuery> { interface State<TQuery extends DataQuery> {
/** DatasourceUid or ds variable expression used to resolve current datasource */
loadedDataSourceIdentifier?: string | null; loadedDataSourceIdentifier?: string | null;
datasource: DataSourceApi<TQuery> | null; datasource: DataSourceApi<TQuery> | null;
datasourceUid?: string | null;
hasTextEditMode: boolean; hasTextEditMode: boolean;
data?: PanelData; data?: PanelData;
isOpen?: boolean; isOpen?: boolean;
@ -238,17 +240,17 @@ export class QueryEditorRow<TQuery extends DataQuery> extends PureComponent<Prop
} }
} }
waitingForDatasourceToLoad = (): boolean => { isWaitingForDatasourceToLoad(): boolean {
// if we not yet have loaded the datasource in state the // if we not yet have loaded the datasource in state the
// ds in props and the ds in state will have different values. // ds in props and the ds in state will have different values.
return this.props.dataSource.uid !== this.state.datasource?.uid; return this.props.dataSource.uid !== this.state.loadedDataSourceIdentifier;
}; }
renderPluginEditor = () => { renderPluginEditor = () => {
const { query, onChange, queries, onRunQuery, onAddQuery, app = CoreApp.PanelEditor, history } = this.props; const { query, onChange, queries, onRunQuery, onAddQuery, app = CoreApp.PanelEditor, history } = this.props;
const { datasource, data } = this.state; const { datasource, data } = this.state;
if (this.waitingForDatasourceToLoad()) { if (this.isWaitingForDatasourceToLoad()) {
return null; return null;
} }

Loading…
Cancel
Save