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> {
|
export class QueryEditor extends PureComponent<Props, State> {
|
||||||
private runner: AlertingQueryRunner;
|
private runner: AlertingQueryRunner;
|
||||||
|
private queries: GrafanaQuery[];
|
||||||
|
|
||||||
constructor(props: Props) {
|
constructor(props: Props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = { panelDataByRefId: {} };
|
this.state = { panelDataByRefId: {} };
|
||||||
this.runner = new AlertingQueryRunner();
|
this.runner = new AlertingQueryRunner();
|
||||||
|
this.queries = props.value ?? [];
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
@ -52,29 +54,34 @@ export class QueryEditor extends PureComponent<Props, State> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onRunQueries = () => {
|
onRunQueries = () => {
|
||||||
const { value = [] } = this.props;
|
const { queries } = this;
|
||||||
this.runner.run(value);
|
this.runner.run(queries);
|
||||||
};
|
};
|
||||||
|
|
||||||
onCancelQueries = () => {
|
onCancelQueries = () => {
|
||||||
this.runner.cancel();
|
this.runner.cancel();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
onChangeQueries = (queries: GrafanaQuery[]) => {
|
||||||
|
this.queries = queries;
|
||||||
|
this.props.onChange(queries);
|
||||||
|
};
|
||||||
|
|
||||||
onDuplicateQuery = (query: GrafanaQuery) => {
|
onDuplicateQuery = (query: GrafanaQuery) => {
|
||||||
const { onChange, value = [] } = this.props;
|
const { queries } = this;
|
||||||
onChange(addQuery(value, query));
|
this.onChangeQueries(addQuery(queries, query));
|
||||||
};
|
};
|
||||||
|
|
||||||
onNewAlertingQuery = () => {
|
onNewAlertingQuery = () => {
|
||||||
const { onChange, value = [] } = this.props;
|
const { queries } = this;
|
||||||
const defaultDataSource = getDatasourceSrv().getInstanceSettings('default');
|
const defaultDataSource = getDatasourceSrv().getInstanceSettings('default');
|
||||||
|
|
||||||
if (!defaultDataSource) {
|
if (!defaultDataSource) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
onChange(
|
this.onChangeQueries(
|
||||||
addQuery(value, {
|
addQuery(queries, {
|
||||||
datasourceUid: defaultDataSource.uid,
|
datasourceUid: defaultDataSource.uid,
|
||||||
model: {
|
model: {
|
||||||
refId: '',
|
refId: '',
|
||||||
@ -85,10 +92,10 @@ export class QueryEditor extends PureComponent<Props, State> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
onNewExpressionQuery = () => {
|
onNewExpressionQuery = () => {
|
||||||
const { onChange, value = [] } = this.props;
|
const { queries } = this;
|
||||||
|
|
||||||
onChange(
|
this.onChangeQueries(
|
||||||
addQuery(value, {
|
addQuery(queries, {
|
||||||
datasourceUid: ExpressionDatasourceUID,
|
datasourceUid: ExpressionDatasourceUID,
|
||||||
model: expressionDatasource.newQuery({
|
model: expressionDatasource.newQuery({
|
||||||
type: ExpressionQueryType.classic,
|
type: ExpressionQueryType.classic,
|
||||||
@ -166,7 +173,7 @@ export class QueryEditor extends PureComponent<Props, State> {
|
|||||||
<QueryRows
|
<QueryRows
|
||||||
data={panelDataByRefId}
|
data={panelDataByRefId}
|
||||||
queries={value}
|
queries={value}
|
||||||
onQueriesChange={this.props.onChange}
|
onQueriesChange={this.onChangeQueries}
|
||||||
onDuplicateQuery={this.onDuplicateQuery}
|
onDuplicateQuery={this.onDuplicateQuery}
|
||||||
onRunQueries={this.onRunQueries}
|
onRunQueries={this.onRunQueries}
|
||||||
/>
|
/>
|
||||||
|
Loading…
Reference in New Issue
Block a user