diff --git a/public/app/core/utils/explore.ts b/public/app/core/utils/explore.ts index b22ab4f9e65..038f283b435 100644 --- a/public/app/core/utils/explore.ts +++ b/public/app/core/utils/explore.ts @@ -12,12 +12,13 @@ import { LogRowModel, LogsModel, LogsDedupStrategy, + DefaultTimeZone, } from '@grafana/data'; import { renderUrl } from 'app/core/utils/url'; import store from 'app/core/store'; import { getNextRefIdChar } from './query'; // Types -import { DataQuery, DataSourceApi, DataQueryError } from '@grafana/ui'; +import { DataQuery, DataSourceApi, DataQueryError, DataQueryRequest } from '@grafana/ui'; import { ExploreUrlState, HistoryItem, @@ -49,7 +50,6 @@ export const lastUsedDatasourceKeyForOrgId = (orgId: number) => `${LAST_USED_DAT /** * Returns an Explore-URL that contains a panel's queries and the dashboard time range. * - * @param panel Origin panel of the jump to Explore * @param panelTargets The origin panel's query targets * @param panelDatasource The origin panel's datasource * @param datasourceSrv Datasource service to query other datasources in case the panel datasource is mixed @@ -107,19 +107,23 @@ export function buildQueryTransaction( return combinedKey; }, ''); - // Clone range for query request - // const queryRange: RawTimeRange = { ...range }; - // const { from, to, raw } = this.timeSrv.timeRange(); // Most datasource is using `panelId + query.refId` for cancellation logic. // Using `format` here because it relates to the view panel that the request is for. // However, some datasources don't use `panelId + query.refId`, but only `panelId`. // Therefore panel id has to be unique. const panelId = `${key}`; - const options = { + const request: DataQueryRequest = { + dashboardId: 0, + // TODO probably should be taken from preferences but does not seem to be used anyway. + timezone: DefaultTimeZone, + // This is set to correct time later on before the query is actually run. + startTime: 0, interval, intervalMs, - panelId, + // TODO: the query request expects number and we are using string here. Seems like it works so far but can create + // issues down the road. + panelId: panelId as any, targets: configuredQueries, // Datasources rely on DataQueries being passed under the targets key. range, requestId: 'explore', @@ -133,7 +137,7 @@ export function buildQueryTransaction( return { queries, - options, + request, scanning, id: generateKey(), // reusing for unique ID done: false, diff --git a/public/app/features/explore/state/actions.ts b/public/app/features/explore/state/actions.ts index 69123285b52..45942a7e286 100644 --- a/public/app/features/explore/state/actions.ts +++ b/public/app/features/explore/state/actions.ts @@ -19,7 +19,7 @@ import { updateHistory, } from 'app/core/utils/explore'; // Types -import { ThunkResult, ExploreUrlState } from 'app/types'; +import { ThunkResult, ExploreUrlState, ExploreItemState } from 'app/types'; import { DataSourceApi, DataQuery, DataSourceSelectItem, QueryFixAction, PanelData } from '@grafana/ui'; import { @@ -31,7 +31,7 @@ import { isDateTime, dateTimeForTimeZone, } from '@grafana/data'; -import { ExploreId, ExploreUIState, QueryTransaction, ExploreMode } from 'app/types/explore'; +import { ExploreId, ExploreUIState, ExploreMode } from 'app/types/explore'; import { updateDatasourceInstanceAction, changeQueryAction, @@ -466,7 +466,7 @@ export function runQueries(exploreId: ExploreId): ThunkResult { dispatch(queryStartAction({ exploreId })); queryState - .execute(datasourceInstance, transaction.options) + .execute(datasourceInstance, transaction.request) .then((response: PanelData) => { if (!response.error) { // Side-effect: Saving history in localstorage @@ -493,7 +493,7 @@ export function runQueries(exploreId: ExploreId): ThunkResult { dispatch( queryEndedAction({ exploreId, - response: { error, legacy: [], series: [], request: transaction.options, state: LoadingState.Error }, + response: { error, legacy: [], series: [], request: transaction.request, state: LoadingState.Error }, }) ); }); @@ -649,12 +649,9 @@ export function splitOpen(): ThunkResult { const leftState = getState().explore[ExploreId.left]; const queryState = getState().location.query[ExploreId.left] as string; const urlState = parseUrlState(queryState); - const queryTransactions: QueryTransaction[] = []; - const itemState = { + const itemState: ExploreItemState = { ...leftState, - queryTransactions, queries: leftState.queries.slice(), - exploreId: ExploreId.right, urlState, }; dispatch(splitOpenAction({ itemState })); diff --git a/public/app/types/explore.ts b/public/app/types/explore.ts index ba7db9bad58..42821700559 100644 --- a/public/app/types/explore.ts +++ b/public/app/types/explore.ts @@ -6,6 +6,7 @@ import { QueryHint, ExploreStartPageProps, PanelData, + DataQueryRequest, } from '@grafana/ui'; import { @@ -338,7 +339,7 @@ export interface QueryTransaction { error?: string | JSX.Element; hints?: QueryHint[]; latency: number; - options: any; + request: DataQueryRequest; queries: DataQuery[]; result?: any; // Table model / Timeseries[] / Logs scanning?: boolean;