mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: making sure we use the updated queries when querying for data. (#34631)
This commit is contained in:
parent
e19b3df1a9
commit
70efaa5582
@ -34,11 +34,13 @@ interface State {
|
||||
}
|
||||
export class QueryEditor extends PureComponent<Props, State> {
|
||||
private runner: AlertingQueryRunner;
|
||||
private queries: GrafanaQuery[];
|
||||
|
||||
constructor(props: Props) {
|
||||
super(props);
|
||||
this.state = { panelDataByRefId: {} };
|
||||
this.runner = new AlertingQueryRunner();
|
||||
this.queries = props.value ?? [];
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
@ -52,29 +54,34 @@ export class QueryEditor extends PureComponent<Props, State> {
|
||||
}
|
||||
|
||||
onRunQueries = () => {
|
||||
const { value = [] } = this.props;
|
||||
this.runner.run(value);
|
||||
const { queries } = this;
|
||||
this.runner.run(queries);
|
||||
};
|
||||
|
||||
onCancelQueries = () => {
|
||||
this.runner.cancel();
|
||||
};
|
||||
|
||||
onChangeQueries = (queries: GrafanaQuery[]) => {
|
||||
this.queries = queries;
|
||||
this.props.onChange(queries);
|
||||
};
|
||||
|
||||
onDuplicateQuery = (query: GrafanaQuery) => {
|
||||
const { onChange, value = [] } = this.props;
|
||||
onChange(addQuery(value, query));
|
||||
const { queries } = this;
|
||||
this.onChangeQueries(addQuery(queries, query));
|
||||
};
|
||||
|
||||
onNewAlertingQuery = () => {
|
||||
const { onChange, value = [] } = this.props;
|
||||
const { queries } = this;
|
||||
const defaultDataSource = getDatasourceSrv().getInstanceSettings('default');
|
||||
|
||||
if (!defaultDataSource) {
|
||||
return;
|
||||
}
|
||||
|
||||
onChange(
|
||||
addQuery(value, {
|
||||
this.onChangeQueries(
|
||||
addQuery(queries, {
|
||||
datasourceUid: defaultDataSource.uid,
|
||||
model: {
|
||||
refId: '',
|
||||
@ -85,10 +92,10 @@ export class QueryEditor extends PureComponent<Props, State> {
|
||||
};
|
||||
|
||||
onNewExpressionQuery = () => {
|
||||
const { onChange, value = [] } = this.props;
|
||||
const { queries } = this;
|
||||
|
||||
onChange(
|
||||
addQuery(value, {
|
||||
this.onChangeQueries(
|
||||
addQuery(queries, {
|
||||
datasourceUid: ExpressionDatasourceUID,
|
||||
model: expressionDatasource.newQuery({
|
||||
type: ExpressionQueryType.classic,
|
||||
@ -166,7 +173,7 @@ export class QueryEditor extends PureComponent<Props, State> {
|
||||
<QueryRows
|
||||
data={panelDataByRefId}
|
||||
queries={value}
|
||||
onQueriesChange={this.props.onChange}
|
||||
onQueriesChange={this.onChangeQueries}
|
||||
onDuplicateQuery={this.onDuplicateQuery}
|
||||
onRunQueries={this.onRunQueries}
|
||||
/>
|
||||
|
Loading…
Reference in New Issue
Block a user