mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Datasource/CloudWatch: Handle invalidation of log groups when switching datasources (#24703)
This commit is contained in:
parent
d3a8f6d026
commit
1b29d3460e
@ -56,7 +56,7 @@ export class QueryEditorRow extends PureComponent<Props, State> {
|
|||||||
datasource: null,
|
datasource: null,
|
||||||
loadedDataSourceValue: undefined,
|
loadedDataSourceValue: undefined,
|
||||||
hasTextEditMode: false,
|
hasTextEditMode: false,
|
||||||
data: null,
|
data: undefined,
|
||||||
isOpen: true,
|
isOpen: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -163,15 +163,16 @@ export class QueryEditorRow extends PureComponent<Props, State> {
|
|||||||
const { query, onChange } = this.props;
|
const { query, onChange } = this.props;
|
||||||
const { datasource, data } = this.state;
|
const { datasource, data } = this.state;
|
||||||
|
|
||||||
if (datasource.components.QueryCtrl) {
|
if (datasource?.components?.QueryCtrl) {
|
||||||
return <div ref={element => (this.element = element)} />;
|
return <div ref={element => (this.element = element)} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (datasource.components.QueryEditor) {
|
if (datasource?.components?.QueryEditor) {
|
||||||
const QueryEditor = datasource.components.QueryEditor;
|
const QueryEditor = datasource.components.QueryEditor;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<QueryEditor
|
<QueryEditor
|
||||||
|
key={datasource?.name}
|
||||||
query={query}
|
query={query}
|
||||||
datasource={datasource}
|
datasource={datasource}
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
@ -188,7 +189,7 @@ export class QueryEditorRow extends PureComponent<Props, State> {
|
|||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
if (this.angularScope && this.angularScope.toggleEditorMode) {
|
if (this.angularScope && this.angularScope.toggleEditorMode) {
|
||||||
this.angularScope.toggleEditorMode();
|
this.angularScope.toggleEditorMode();
|
||||||
this.angularQueryEditor.digest();
|
this.angularQueryEditor?.digest();
|
||||||
if (!isOpen) {
|
if (!isOpen) {
|
||||||
openRow();
|
openRow();
|
||||||
}
|
}
|
||||||
@ -212,7 +213,7 @@ export class QueryEditorRow extends PureComponent<Props, State> {
|
|||||||
|
|
||||||
renderCollapsedText(): string | null {
|
renderCollapsedText(): string | null {
|
||||||
const { datasource } = this.state;
|
const { datasource } = this.state;
|
||||||
if (datasource.getQueryDisplayText) {
|
if (datasource?.getQueryDisplayText) {
|
||||||
return datasource.getQueryDisplayText(this.props.query);
|
return datasource.getQueryDisplayText(this.props.query);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -302,7 +303,7 @@ export class QueryEditorRow extends PureComponent<Props, State> {
|
|||||||
|
|
||||||
// To avoid sending duplicate events for each row we have this global cached object here
|
// To avoid sending duplicate events for each row we have this global cached object here
|
||||||
// So we can check if we already emitted this legacy data event
|
// So we can check if we already emitted this legacy data event
|
||||||
let globalLastPanelDataCache: PanelData = null;
|
let globalLastPanelDataCache: PanelData | null = null;
|
||||||
|
|
||||||
function notifyAngularQueryEditorsOfData(panel: PanelModel, data: PanelData, editor: AngularComponent) {
|
function notifyAngularQueryEditorsOfData(panel: PanelModel, data: PanelData, editor: AngularComponent) {
|
||||||
if (data === globalLastPanelDataCache) {
|
if (data === globalLastPanelDataCache) {
|
||||||
|
@ -56,6 +56,6 @@ describe('CloudWatchLogsQueryField', () => {
|
|||||||
// We clear the select
|
// We clear the select
|
||||||
expect(getLogGroupSelect().props.value.length).toBe(0);
|
expect(getLogGroupSelect().props.value.length).toBe(0);
|
||||||
// Make sure we correctly updated the upstream state
|
// Make sure we correctly updated the upstream state
|
||||||
expect(onChange.mock.calls[1][0]).toEqual({ region: 'region2', logGroupNames: [] });
|
expect(onChange.mock.calls[onChange.mock.calls.length - 1][0]).toEqual({ region: 'region2', logGroupNames: [] });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
// Libraries
|
// Libraries
|
||||||
import React, { ReactNode } from 'react';
|
import React, { ReactNode } from 'react';
|
||||||
import intersection from 'lodash/intersection';
|
import intersectionBy from 'lodash/intersectionBy';
|
||||||
import debounce from 'lodash/debounce';
|
import debounce from 'lodash/debounce';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@ -122,16 +122,29 @@ export class CloudWatchLogsQueryField extends React.PureComponent<CloudWatchLogs
|
|||||||
};
|
};
|
||||||
|
|
||||||
componentWillMount = () => {
|
componentWillMount = () => {
|
||||||
const { datasource, query } = this.props;
|
const { datasource, query, onChange } = this.props;
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
loadingLogGroups: true,
|
loadingLogGroups: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
this.fetchLogGroupOptions(query.region).then(logGroups => {
|
this.fetchLogGroupOptions(query.region).then(logGroups => {
|
||||||
this.setState({
|
this.setState(state => {
|
||||||
loadingLogGroups: false,
|
const selectedLogGroups = intersectionBy(state.selectedLogGroups, logGroups, 'value');
|
||||||
availableLogGroups: logGroups,
|
if (onChange) {
|
||||||
|
const nextQuery = {
|
||||||
|
...query,
|
||||||
|
logGroupNames: selectedLogGroups.map(group => group.value!),
|
||||||
|
};
|
||||||
|
|
||||||
|
onChange(nextQuery);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
loadingLogGroups: false,
|
||||||
|
availableLogGroups: logGroups,
|
||||||
|
selectedLogGroups,
|
||||||
|
};
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -184,7 +197,7 @@ export class CloudWatchLogsQueryField extends React.PureComponent<CloudWatchLogs
|
|||||||
const logGroups = await this.fetchLogGroupOptions(v.value!);
|
const logGroups = await this.fetchLogGroupOptions(v.value!);
|
||||||
|
|
||||||
this.setState(state => {
|
this.setState(state => {
|
||||||
const selectedLogGroups = intersection(state.selectedLogGroups, logGroups);
|
const selectedLogGroups = intersectionBy(state.selectedLogGroups, logGroups, 'value');
|
||||||
|
|
||||||
const { onChange, query } = this.props;
|
const { onChange, query } = this.props;
|
||||||
if (onChange) {
|
if (onChange) {
|
||||||
|
Loading…
Reference in New Issue
Block a user