From 5e7d4beacf7a7f72052968b827e71d26d79af5f6 Mon Sep 17 00:00:00 2001 From: Erik Sundell Date: Tue, 27 Nov 2018 14:45:39 +0100 Subject: [PATCH] get intervals from explore function --- public/app/features/explore/Explore.tsx | 1 + public/app/features/explore/QueryEditor.tsx | 21 ++++++++++++++++++--- public/app/features/explore/QueryRows.tsx | 5 ++++- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/public/app/features/explore/Explore.tsx b/public/app/features/explore/Explore.tsx index e867d7411d7..2138702ae3d 100644 --- a/public/app/features/explore/Explore.tsx +++ b/public/app/features/explore/Explore.tsx @@ -897,6 +897,7 @@ export class Explore extends React.PureComponent { onRemoveQueryRow={this.onRemoveQueryRow} transactions={queryTransactions} exploreEvents={this.exploreEvents} + range={range} />
diff --git a/public/app/features/explore/QueryEditor.tsx b/public/app/features/explore/QueryEditor.tsx index c5ee0928623..32de7c64e3f 100644 --- a/public/app/features/explore/QueryEditor.tsx +++ b/public/app/features/explore/QueryEditor.tsx @@ -1,8 +1,11 @@ import React, { PureComponent } from 'react'; import { getAngularLoader, AngularComponent } from 'app/core/services/AngularLoader'; import { Emitter } from 'app/core/utils/emitter'; +import { getIntervals } from 'app/core/utils/explore'; import { DataQuery } from 'app/types'; +import { RawTimeRange } from 'app/types/series'; import 'app/features/plugins/plugin_loader'; +import { getTimeSrv } from 'app/features/dashboard/time_srv'; interface QueryEditorProps { datasource: any; @@ -11,6 +14,7 @@ interface QueryEditorProps { onQueryChange?: (value: DataQuery, override?: boolean) => void; initialQuery: DataQuery; exploreEvents: Emitter; + range: RawTimeRange; } export default class QueryEditor extends PureComponent { @@ -22,7 +26,9 @@ export default class QueryEditor extends PureComponent { return; } - const { datasource, initialQuery, exploreEvents } = this.props; + const { datasource, initialQuery, exploreEvents, range } = this.props; + this.initTimeSrv(range); + const loader = getAngularLoader(); const template = ' '; const target = { datasource: datasource.name, ...initialQuery }; @@ -42,8 +48,7 @@ export default class QueryEditor extends PureComponent { getNextQueryLetter: x => '', }, hideEditorRowActions: true, - interval: '1m', - intervalMs: 60000, + ...getIntervals(range, datasource, null), // Possible to get resolution? }, }; @@ -56,6 +61,16 @@ export default class QueryEditor extends PureComponent { } } + initTimeSrv(range) { + const timeSrv = getTimeSrv(); + timeSrv.init({ + time: range, + refresh: false, + getTimezone: () => 'utc', + timeRangeUpdated: () => console.log('refreshDashboard!'), + }); + } + render() { return
(this.element = element)} style={{ width: '100%' }} />; } diff --git a/public/app/features/explore/QueryRows.tsx b/public/app/features/explore/QueryRows.tsx index 8acb9a9403d..36d1db8f546 100644 --- a/public/app/features/explore/QueryRows.tsx +++ b/public/app/features/explore/QueryRows.tsx @@ -7,6 +7,7 @@ import { Emitter } from 'app/core/utils/emitter'; import QueryEditor from './QueryEditor'; import QueryTransactionStatus from './QueryTransactionStatus'; import { DataSource, DataQuery } from 'app/types'; +import { RawTimeRange } from 'app/types/series'; function getFirstHintFromTransactions(transactions: QueryTransaction[]): QueryHint { const transaction = transactions.find(qt => qt.hints && qt.hints.length > 0); @@ -30,6 +31,7 @@ interface QueryRowCommonProps { history: HistoryItem[]; transactions: QueryTransaction[]; exploreEvents: Emitter; + range: RawTimeRange; } type QueryRowProps = QueryRowCommonProps & @@ -84,7 +86,7 @@ class QueryRow extends PureComponent { }; render() { - const { datasource, history, initialQuery, transactions, exploreEvents } = this.props; + const { datasource, history, initialQuery, transactions, exploreEvents, range } = this.props; const transactionWithError = transactions.find(t => t.error !== undefined); const hint = getFirstHintFromTransactions(transactions); const queryError = transactionWithError ? transactionWithError.error : null; @@ -116,6 +118,7 @@ class QueryRow extends PureComponent { onExecuteQuery={this.onExecuteQuery} initialQuery={initialQuery} exploreEvents={exploreEvents} + range={range} /> )}