mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Fixed loading of default query editor
This commit is contained in:
parent
96d28703f7
commit
db2a15daf0
@ -197,7 +197,7 @@ export class QueriesTab extends PureComponent<Props, State> {
|
|||||||
<div className="query-editor-rows">
|
<div className="query-editor-rows">
|
||||||
{panel.targets.map((query, index) => (
|
{panel.targets.map((query, index) => (
|
||||||
<QueryEditorRow
|
<QueryEditorRow
|
||||||
datasourceName={query.datasource || panel.datasource}
|
dataSourceValue={query.datasource || panel.datasource}
|
||||||
key={query.refId}
|
key={query.refId}
|
||||||
panel={panel}
|
panel={panel}
|
||||||
query={query}
|
query={query}
|
||||||
|
@ -18,11 +18,12 @@ interface Props {
|
|||||||
onAddQuery: (query?: DataQuery) => void;
|
onAddQuery: (query?: DataQuery) => void;
|
||||||
onRemoveQuery: (query: DataQuery) => void;
|
onRemoveQuery: (query: DataQuery) => void;
|
||||||
onMoveQuery: (query: DataQuery, direction: number) => void;
|
onMoveQuery: (query: DataQuery, direction: number) => void;
|
||||||
datasourceName: string | null;
|
dataSourceValue: string | null;
|
||||||
inMixedMode: boolean;
|
inMixedMode: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface State {
|
interface State {
|
||||||
|
loadedDataSourceValue: string | null | undefined;
|
||||||
datasource: DataSourceApi | null;
|
datasource: DataSourceApi | null;
|
||||||
isCollapsed: boolean;
|
isCollapsed: boolean;
|
||||||
angularScope: AngularQueryComponentScope | null;
|
angularScope: AngularQueryComponentScope | null;
|
||||||
@ -36,6 +37,7 @@ export class QueryEditorRow extends PureComponent<Props, State> {
|
|||||||
datasource: null,
|
datasource: null,
|
||||||
isCollapsed: false,
|
isCollapsed: false,
|
||||||
angularScope: null,
|
angularScope: null,
|
||||||
|
loadedDataSourceValue: undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
@ -61,14 +63,14 @@ export class QueryEditorRow extends PureComponent<Props, State> {
|
|||||||
const dataSourceSrv = getDatasourceSrv();
|
const dataSourceSrv = getDatasourceSrv();
|
||||||
const datasource = await dataSourceSrv.get(query.datasource || panel.datasource);
|
const datasource = await dataSourceSrv.get(query.datasource || panel.datasource);
|
||||||
|
|
||||||
this.setState({ datasource });
|
this.setState({ datasource, loadedDataSourceValue: this.props.dataSourceValue });
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidUpdate() {
|
componentDidUpdate() {
|
||||||
const { datasource } = this.state;
|
const { loadedDataSourceValue } = this.state;
|
||||||
|
|
||||||
// check if we need to load another datasource
|
// check if we need to load another datasource
|
||||||
if (datasource && datasource.name !== this.props.datasourceName) {
|
if (loadedDataSourceValue !== this.props.dataSourceValue) {
|
||||||
if (this.angularQueryEditor) {
|
if (this.angularQueryEditor) {
|
||||||
this.angularQueryEditor.destroy();
|
this.angularQueryEditor.destroy();
|
||||||
this.angularQueryEditor = null;
|
this.angularQueryEditor = null;
|
||||||
@ -178,7 +180,7 @@ export class QueryEditorRow extends PureComponent<Props, State> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { query, datasourceName, inMixedMode } = this.props;
|
const { query, inMixedMode } = this.props;
|
||||||
const { datasource, isCollapsed } = this.state;
|
const { datasource, isCollapsed } = this.state;
|
||||||
const isDisabled = query.hide;
|
const isDisabled = query.hide;
|
||||||
|
|
||||||
@ -202,7 +204,7 @@ export class QueryEditorRow extends PureComponent<Props, State> {
|
|||||||
{isCollapsed && <i className="fa fa-caret-right" />}
|
{isCollapsed && <i className="fa fa-caret-right" />}
|
||||||
{!isCollapsed && <i className="fa fa-caret-down" />}
|
{!isCollapsed && <i className="fa fa-caret-down" />}
|
||||||
<span>{query.refId}</span>
|
<span>{query.refId}</span>
|
||||||
{inMixedMode && <em className="query-editor-row__context-info"> ({datasourceName})</em>}
|
{inMixedMode && <em className="query-editor-row__context-info"> ({datasource.name})</em>}
|
||||||
{isDisabled && <em className="query-editor-row__context-info"> Disabled</em>}
|
{isDisabled && <em className="query-editor-row__context-info"> Disabled</em>}
|
||||||
</div>
|
</div>
|
||||||
<div className="query-editor-row__collapsed-text" onClick={this.onToggleEditMode}>
|
<div className="query-editor-row__collapsed-text" onClick={this.onToggleEditMode}>
|
||||||
|
Loading…
Reference in New Issue
Block a user