diff --git a/public/app/features/alerting/unified/components/rule-editor/QueryWrapper.tsx b/public/app/features/alerting/unified/components/rule-editor/QueryWrapper.tsx index 0989fada424..2d790354a68 100644 --- a/public/app/features/alerting/unified/components/rule-editor/QueryWrapper.tsx +++ b/public/app/features/alerting/unified/components/rule-editor/QueryWrapper.tsx @@ -13,6 +13,8 @@ import { PanelData, RelativeTimeRange, ThresholdsConfig, + getDefaultRelativeTimeRange, + rangeUtil, } from '@grafana/data'; import { config } from '@grafana/runtime'; import { DataQuery } from '@grafana/schema'; @@ -187,12 +189,12 @@ export const QueryWrapper = ({ // ⚠️ the query editors want the entire array of queries passed as "DataQuery" NOT "AlertQuery" // TypeScript isn't complaining here because the interfaces just happen to be compatible const editorQueries = cloneDeep(queries.map((query) => query.model)); + const range = rangeUtil.relativeToTimeRange(query.relativeTimeRange ?? getDefaultRelativeTimeRange()); return (
- alerting hideRefId={!isAdvancedMode} hideActionButtons={!isAdvancedMode} collapsable={false} @@ -209,6 +211,7 @@ export const QueryWrapper = ({ onAddQuery={() => onDuplicateQuery(cloneDeep(query))} onRunQuery={onRunQueries} queries={editorQueries} + range={range} renderHeaderExtras={() => ( )} diff --git a/public/app/features/query/components/QueryEditorRow.test.tsx b/public/app/features/query/components/QueryEditorRow.test.tsx index ae1bf9acc33..350d98bf11d 100644 --- a/public/app/features/query/components/QueryEditorRow.test.tsx +++ b/public/app/features/query/components/QueryEditorRow.test.tsx @@ -354,6 +354,7 @@ describe('QueryEditorRow', () => { onChange: jest.fn(), onRemoveQuery: jest.fn(), index: 0, + range: { from: dateTime(), to: dateTime(), raw: { from: 'now-1d', to: 'now' } }, }); it('should display error message in corresponding panel', async () => { const data = { diff --git a/public/app/features/query/components/QueryEditorRow.tsx b/public/app/features/query/components/QueryEditorRow.tsx index 36a3d5818ee..46093ff35ba 100644 --- a/public/app/features/query/components/QueryEditorRow.tsx +++ b/public/app/features/query/components/QueryEditorRow.tsx @@ -63,9 +63,9 @@ export interface Props { visualization?: ReactNode; hideHideQueryButton?: boolean; app?: CoreApp; + range: TimeRange; history?: Array>; eventBus?: EventBusExtended; - alerting?: boolean; hideActionButtons?: boolean; onQueryCopied?: () => void; onQueryRemoved?: () => void; @@ -273,7 +273,7 @@ export class QueryEditorRow extends PureComponent { - const { query, onChange, queries, onRunQuery, onAddQuery, app = CoreApp.PanelEditor, history } = this.props; + const { query, onChange, queries, onRunQuery, onAddQuery, range, app = CoreApp.PanelEditor, history } = this.props; const { datasource, data } = this.state; if (this.isWaitingForDatasourceToLoad()) { @@ -298,7 +298,7 @@ export class QueryEditorRow extends PureComponent extends PureComponent { - const { alerting, query, dataSource, onChangeDataSource, onChange, queries, renderHeaderExtras, hideRefId } = - this.props; + const { app, query, dataSource, onChangeDataSource, onChange, queries, renderHeaderExtras, hideRefId } = this.props; return ( extends PureComponent ); diff --git a/public/app/features/query/components/QueryEditorRows.tsx b/public/app/features/query/components/QueryEditorRows.tsx index 187ea5df7a5..3d87a646ab6 100644 --- a/public/app/features/query/components/QueryEditorRows.tsx +++ b/public/app/features/query/components/QueryEditorRows.tsx @@ -11,6 +11,7 @@ import { getDataSourceRef, } from '@grafana/data'; import { getDataSourceSrv, reportInteraction } from '@grafana/runtime'; +import { getTimeSrv } from 'app/features/dashboard/services/TimeSrv'; import { QueryEditorRow } from './QueryEditorRow'; @@ -175,6 +176,7 @@ export class QueryEditorRows extends PureComponent { onQueryToggled={onQueryToggled} queries={queries} app={app} + range={getTimeSrv().timeRange()} history={history} eventBus={eventBus} />