Browse Source

Explore: Add typings for queryTransaction.request (#18847)

Andrej Ocenas 6 years ago
parent
commit
e0e3a4db54

+ 12 - 8
public/app/core/utils/explore.ts

@@ -12,12 +12,13 @@ import {
   LogRowModel,
   LogRowModel,
   LogsModel,
   LogsModel,
   LogsDedupStrategy,
   LogsDedupStrategy,
+  DefaultTimeZone,
 } from '@grafana/data';
 } from '@grafana/data';
 import { renderUrl } from 'app/core/utils/url';
 import { renderUrl } from 'app/core/utils/url';
 import store from 'app/core/store';
 import store from 'app/core/store';
 import { getNextRefIdChar } from './query';
 import { getNextRefIdChar } from './query';
 // Types
 // Types
-import { DataQuery, DataSourceApi, DataQueryError } from '@grafana/ui';
+import { DataQuery, DataSourceApi, DataQueryError, DataQueryRequest } from '@grafana/ui';
 import {
 import {
   ExploreUrlState,
   ExploreUrlState,
   HistoryItem,
   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.
  * 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 panelTargets The origin panel's query targets
  * @param panelDatasource The origin panel's datasource
  * @param panelDatasource The origin panel's datasource
  * @param datasourceSrv Datasource service to query other datasources in case the panel datasource is mixed
  * @param datasourceSrv Datasource service to query other datasources in case the panel datasource is mixed
@@ -107,19 +107,23 @@ export function buildQueryTransaction(
     return combinedKey;
     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.
   // 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.
   // 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`.
   // However, some datasources don't use `panelId + query.refId`, but only `panelId`.
   // Therefore panel id has to be unique.
   // Therefore panel id has to be unique.
   const panelId = `${key}`;
   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,
     interval,
     intervalMs,
     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.
     targets: configuredQueries, // Datasources rely on DataQueries being passed under the targets key.
     range,
     range,
     requestId: 'explore',
     requestId: 'explore',
@@ -133,7 +137,7 @@ export function buildQueryTransaction(
 
 
   return {
   return {
     queries,
     queries,
-    options,
+    request,
     scanning,
     scanning,
     id: generateKey(), // reusing for unique ID
     id: generateKey(), // reusing for unique ID
     done: false,
     done: false,

+ 5 - 8
public/app/features/explore/state/actions.ts

@@ -19,7 +19,7 @@ import {
   updateHistory,
   updateHistory,
 } from 'app/core/utils/explore';
 } from 'app/core/utils/explore';
 // Types
 // Types
-import { ThunkResult, ExploreUrlState } from 'app/types';
+import { ThunkResult, ExploreUrlState, ExploreItemState } from 'app/types';
 import { DataSourceApi, DataQuery, DataSourceSelectItem, QueryFixAction, PanelData } from '@grafana/ui';
 import { DataSourceApi, DataQuery, DataSourceSelectItem, QueryFixAction, PanelData } from '@grafana/ui';
 
 
 import {
 import {
@@ -31,7 +31,7 @@ import {
   isDateTime,
   isDateTime,
   dateTimeForTimeZone,
   dateTimeForTimeZone,
 } from '@grafana/data';
 } from '@grafana/data';
-import { ExploreId, ExploreUIState, QueryTransaction, ExploreMode } from 'app/types/explore';
+import { ExploreId, ExploreUIState, ExploreMode } from 'app/types/explore';
 import {
 import {
   updateDatasourceInstanceAction,
   updateDatasourceInstanceAction,
   changeQueryAction,
   changeQueryAction,
@@ -466,7 +466,7 @@ export function runQueries(exploreId: ExploreId): ThunkResult<void> {
     dispatch(queryStartAction({ exploreId }));
     dispatch(queryStartAction({ exploreId }));
 
 
     queryState
     queryState
-      .execute(datasourceInstance, transaction.options)
+      .execute(datasourceInstance, transaction.request)
       .then((response: PanelData) => {
       .then((response: PanelData) => {
         if (!response.error) {
         if (!response.error) {
           // Side-effect: Saving history in localstorage
           // Side-effect: Saving history in localstorage
@@ -493,7 +493,7 @@ export function runQueries(exploreId: ExploreId): ThunkResult<void> {
         dispatch(
         dispatch(
           queryEndedAction({
           queryEndedAction({
             exploreId,
             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<void> {
     const leftState = getState().explore[ExploreId.left];
     const leftState = getState().explore[ExploreId.left];
     const queryState = getState().location.query[ExploreId.left] as string;
     const queryState = getState().location.query[ExploreId.left] as string;
     const urlState = parseUrlState(queryState);
     const urlState = parseUrlState(queryState);
-    const queryTransactions: QueryTransaction[] = [];
-    const itemState = {
+    const itemState: ExploreItemState = {
       ...leftState,
       ...leftState,
-      queryTransactions,
       queries: leftState.queries.slice(),
       queries: leftState.queries.slice(),
-      exploreId: ExploreId.right,
       urlState,
       urlState,
     };
     };
     dispatch(splitOpenAction({ itemState }));
     dispatch(splitOpenAction({ itemState }));

+ 2 - 1
public/app/types/explore.ts

@@ -6,6 +6,7 @@ import {
   QueryHint,
   QueryHint,
   ExploreStartPageProps,
   ExploreStartPageProps,
   PanelData,
   PanelData,
+  DataQueryRequest,
 } from '@grafana/ui';
 } from '@grafana/ui';
 
 
 import {
 import {
@@ -338,7 +339,7 @@ export interface QueryTransaction {
   error?: string | JSX.Element;
   error?: string | JSX.Element;
   hints?: QueryHint[];
   hints?: QueryHint[];
   latency: number;
   latency: number;
-  options: any;
+  request: DataQueryRequest;
   queries: DataQuery[];
   queries: DataQuery[];
   result?: any; // Table model / Timeseries[] / Logs
   result?: any; // Table model / Timeseries[] / Logs
   scanning?: boolean;
   scanning?: boolean;