diff --git a/public/app/features/annotations/annotations_srv.ts b/public/app/features/annotations/annotations_srv.ts index 6540a5aca93..3a8588503ac 100644 --- a/public/app/features/annotations/annotations_srv.ts +++ b/public/app/features/annotations/annotations_srv.ts @@ -25,7 +25,7 @@ import { Observable, of } from 'rxjs'; import { map, mergeMap } from 'rxjs/operators'; import { AnnotationQueryOptions, AnnotationQueryResponse } from './types'; import { standardAnnotationSupport } from './standardAnnotationSupport'; -import { runRequest } from '../dashboard/state/runRequest'; +import { runRequest } from '../query/state/runRequest'; let counter = 100; function getNextRequestId() { diff --git a/public/app/features/dashboard/components/Inspector/InspectContent.tsx b/public/app/features/dashboard/components/Inspector/InspectContent.tsx index 7e51f31d29f..5edf0e725f0 100644 --- a/public/app/features/dashboard/components/Inspector/InspectContent.tsx +++ b/public/app/features/dashboard/components/Inspector/InspectContent.tsx @@ -12,7 +12,7 @@ import { InspectStatsTab } from './InspectStatsTab'; import { QueryInspector } from './QueryInspector'; import { InspectTab } from './types'; import { DashboardModel, PanelModel } from '../../state'; -import { GetDataOptions } from '../../state/PanelQueryRunner'; +import { GetDataOptions } from '../../../query/state/PanelQueryRunner'; interface Props { dashboard: DashboardModel; diff --git a/public/app/features/dashboard/components/Inspector/InspectDataTab.tsx b/public/app/features/dashboard/components/Inspector/InspectDataTab.tsx index 7156006f499..65d90e5f985 100644 --- a/public/app/features/dashboard/components/Inspector/InspectDataTab.tsx +++ b/public/app/features/dashboard/components/Inspector/InspectDataTab.tsx @@ -19,7 +19,7 @@ import { getPanelInspectorStyles } from './styles'; import { config } from 'app/core/config'; import { saveAs } from 'file-saver'; import { css } from 'emotion'; -import { GetDataOptions } from '../../state/PanelQueryRunner'; +import { GetDataOptions } from '../../../query/state/PanelQueryRunner'; import { QueryOperationRow } from 'app/core/components/QueryOperationRow/QueryOperationRow'; import { PanelModel } from 'app/features/dashboard/state'; import { DetailText } from './DetailText'; diff --git a/public/app/features/dashboard/components/Inspector/PanelInspector.tsx b/public/app/features/dashboard/components/Inspector/PanelInspector.tsx index 188423fe87c..e5f63922b35 100644 --- a/public/app/features/dashboard/components/Inspector/PanelInspector.tsx +++ b/public/app/features/dashboard/components/Inspector/PanelInspector.tsx @@ -5,7 +5,7 @@ import { DashboardModel, PanelModel } from 'app/features/dashboard/state'; import { PanelPlugin } from '@grafana/data'; import { StoreState } from 'app/types'; -import { GetDataOptions } from '../../state/PanelQueryRunner'; +import { GetDataOptions } from '../../../query/state/PanelQueryRunner'; import { usePanelLatestData } from '../PanelEditor/usePanelLatestData'; import { InspectContent } from './InspectContent'; import { useDatasourceMetadata, useInspectTabs } from './hooks'; diff --git a/public/app/features/dashboard/components/PanelEditor/PanelEditorQueries.tsx b/public/app/features/dashboard/components/PanelEditor/PanelEditorQueries.tsx new file mode 100644 index 00000000000..2e974c3ede6 --- /dev/null +++ b/public/app/features/dashboard/components/PanelEditor/PanelEditorQueries.tsx @@ -0,0 +1,16 @@ +import React, { PureComponent } from 'react'; +import { QueriesTab } from 'app/features/query/components/QueriesTab'; +import { DashboardModel, PanelModel } from '../../state'; + +interface Props { + panel: PanelModel; + dashboard: DashboardModel; +} + +export class PanelEditorQueries extends PureComponent { + render() { + const { panel, dashboard } = this.props; + + return ; + } +} diff --git a/public/app/features/dashboard/components/PanelEditor/PanelEditorTabs.tsx b/public/app/features/dashboard/components/PanelEditor/PanelEditorTabs.tsx index 646d5bf3fc2..944cffda809 100644 --- a/public/app/features/dashboard/components/PanelEditor/PanelEditorTabs.tsx +++ b/public/app/features/dashboard/components/PanelEditor/PanelEditorTabs.tsx @@ -2,13 +2,13 @@ import React, { PureComponent } from 'react'; import { config } from 'app/core/config'; import { css } from 'emotion'; import { IconName, stylesFactory, Tab, TabContent, TabsBar } from '@grafana/ui'; -import { QueriesTab } from '../../panel_editor/QueriesTab'; import { AlertTab } from 'app/features/alerting/AlertTab'; import { TransformationsEditor } from '../TransformationsEditor/TransformationsEditor'; import { DashboardModel, PanelModel } from '../../state'; import { PanelEditorTab, PanelEditorTabId } from './types'; import { Subscription } from 'rxjs'; import { PanelQueriesChangedEvent, PanelTransformationsChangedEvent } from 'app/types/events'; +import { PanelEditorQueries } from './PanelEditorQueries'; interface PanelEditorTabsProps { panel: PanelModel; @@ -76,7 +76,7 @@ export class PanelEditorTabs extends PureComponent { })} - {activeTab.id === PanelEditorTabId.Query && } + {activeTab.id === PanelEditorTabId.Query && } {activeTab.id === PanelEditorTabId.Alert && } {activeTab.id === PanelEditorTabId.Transform && } diff --git a/public/app/features/dashboard/components/PanelEditor/VisualizationTab.tsx b/public/app/features/dashboard/components/PanelEditor/VisualizationTab.tsx index 1d40283cffa..e5b28f98ffc 100644 --- a/public/app/features/dashboard/components/PanelEditor/VisualizationTab.tsx +++ b/public/app/features/dashboard/components/PanelEditor/VisualizationTab.tsx @@ -6,7 +6,7 @@ import { changePanelPlugin } from '../../state/actions'; import { StoreState } from 'app/types'; import { PanelModel } from '../../state/PanelModel'; import { connect, MapStateToProps, MapDispatchToProps } from 'react-redux'; -import { VizTypePicker, getAllPanelPluginMeta, filterPluginList } from '../../panel_editor/VizTypePicker'; +import { VizTypePicker, getAllPanelPluginMeta, filterPluginList } from '../VizTypePicker/VizTypePicker'; import { Field } from '@grafana/ui/src/components/Forms/Field'; interface OwnProps { diff --git a/public/app/features/dashboard/components/PanelEditor/usePanelLatestData.ts b/public/app/features/dashboard/components/PanelEditor/usePanelLatestData.ts index 3ea6d16e6e1..2c66fe00302 100644 --- a/public/app/features/dashboard/components/PanelEditor/usePanelLatestData.ts +++ b/public/app/features/dashboard/components/PanelEditor/usePanelLatestData.ts @@ -2,7 +2,7 @@ import { DataQueryError, LoadingState, PanelData } from '@grafana/data'; import { useEffect, useRef, useState } from 'react'; import { PanelModel } from '../../state'; import { Unsubscribable } from 'rxjs'; -import { GetDataOptions } from '../../state/PanelQueryRunner'; +import { GetDataOptions } from '../../../query/state/PanelQueryRunner'; interface UsePanelLatestData { data?: PanelData; diff --git a/public/app/features/dashboard/panel_editor/VizTypePicker.tsx b/public/app/features/dashboard/components/VizTypePicker/VizTypePicker.tsx similarity index 100% rename from public/app/features/dashboard/panel_editor/VizTypePicker.tsx rename to public/app/features/dashboard/components/VizTypePicker/VizTypePicker.tsx diff --git a/public/app/features/dashboard/panel_editor/VizTypePickerPlugin.tsx b/public/app/features/dashboard/components/VizTypePicker/VizTypePickerPlugin.tsx similarity index 99% rename from public/app/features/dashboard/panel_editor/VizTypePickerPlugin.tsx rename to public/app/features/dashboard/components/VizTypePicker/VizTypePickerPlugin.tsx index 791aa5256ab..043cf1ee824 100644 --- a/public/app/features/dashboard/panel_editor/VizTypePickerPlugin.tsx +++ b/public/app/features/dashboard/components/VizTypePicker/VizTypePickerPlugin.tsx @@ -3,7 +3,7 @@ import { GrafanaTheme, PanelPluginMeta, PluginState } from '@grafana/data'; import { Badge, BadgeProps, styleMixins, stylesFactory, useTheme } from '@grafana/ui'; import { css, cx } from 'emotion'; import { selectors } from '@grafana/e2e-selectors'; -import { isUnsignedPluginSignature, PluginSignatureBadge } from '../../plugins/PluginSignatureBadge'; +import { isUnsignedPluginSignature, PluginSignatureBadge } from '../../../plugins/PluginSignatureBadge'; interface Props { isCurrent: boolean; diff --git a/public/app/features/dashboard/state/PanelModel.test.ts b/public/app/features/dashboard/state/PanelModel.test.ts index a3f10f210ae..3af984340c9 100644 --- a/public/app/features/dashboard/state/PanelModel.test.ts +++ b/public/app/features/dashboard/state/PanelModel.test.ts @@ -12,7 +12,7 @@ import { FieldColorConfigSettings, } from '@grafana/data'; import { ComponentClass } from 'react'; -import { PanelQueryRunner } from './PanelQueryRunner'; +import { PanelQueryRunner } from '../../query/state/PanelQueryRunner'; import { setDataSourceSrv } from '@grafana/runtime'; class TablePanelCtrl {} diff --git a/public/app/features/dashboard/state/PanelModel.ts b/public/app/features/dashboard/state/PanelModel.ts index 074fdfaac03..4496c7a44fb 100644 --- a/public/app/features/dashboard/state/PanelModel.ts +++ b/public/app/features/dashboard/state/PanelModel.ts @@ -25,7 +25,7 @@ import { } from '@grafana/data'; import { EDIT_PANEL_ID } from 'app/core/constants'; import config from 'app/core/config'; -import { PanelQueryRunner } from './PanelQueryRunner'; +import { PanelQueryRunner } from '../../query/state/PanelQueryRunner'; import { getDatasourceSrv } from '../../plugins/datasource_srv'; import { PanelOptionsChangedEvent, PanelQueriesChangedEvent, PanelTransformationsChangedEvent } from 'app/types/events'; diff --git a/public/app/features/dashboard/state/analyticsProcessor.ts b/public/app/features/dashboard/state/analyticsProcessor.ts index 9fe1caf6049..9834d86f149 100644 --- a/public/app/features/dashboard/state/analyticsProcessor.ts +++ b/public/app/features/dashboard/state/analyticsProcessor.ts @@ -1,67 +1,5 @@ -import { getDashboardSrv } from '../services/DashboardSrv'; import { DashboardModel } from './DashboardModel'; - -import { PanelData, LoadingState, DataSourceApi, CoreApp, urlUtil } from '@grafana/data'; - -import { - reportMetaAnalytics, - MetaAnalyticsEventName, - DataRequestEventPayload, - DashboardViewEventPayload, -} from '@grafana/runtime'; - -export function emitDataRequestEvent(datasource: DataSourceApi) { - let done = false; - - return (data: PanelData) => { - if (!data.request || done || data.request.app === CoreApp.Explore) { - return; - } - - const params = urlUtil.getUrlSearchParams(); - if (params.editPanel != null) { - return; - } - - if (data.state !== LoadingState.Done && data.state !== LoadingState.Error) { - return; - } - - const eventData: DataRequestEventPayload = { - eventName: MetaAnalyticsEventName.DataRequest, - datasourceName: datasource.name, - datasourceId: datasource.id, - panelId: data.request.panelId, - dashboardId: data.request.dashboardId, - dataSize: 0, - duration: data.request.endTime! - data.request.startTime, - }; - - // enrich with dashboard info - const dashboard = getDashboardSrv().getCurrent(); - if (dashboard) { - eventData.dashboardId = dashboard.id; - eventData.dashboardName = dashboard.title; - eventData.dashboardUid = dashboard.uid; - eventData.folderName = dashboard.meta.folderTitle; - } - - if (data.series && data.series.length > 0) { - // estimate size - eventData.dataSize = data.series.length; - } - - if (data.error) { - eventData.error = data.error.message; - } - - reportMetaAnalytics(eventData); - - // this done check is to make sure we do not double emit events in case - // there are multiple responses with done state - done = true; - }; -} +import { reportMetaAnalytics, MetaAnalyticsEventName, DashboardViewEventPayload } from '@grafana/runtime'; export function emitDashboardViewEvent(dashboard: DashboardModel) { const eventData: DashboardViewEventPayload = { diff --git a/public/app/features/dashboard/utils/loadSnapshotData.ts b/public/app/features/dashboard/utils/loadSnapshotData.ts index d81802272f0..534ab23c468 100644 --- a/public/app/features/dashboard/utils/loadSnapshotData.ts +++ b/public/app/features/dashboard/utils/loadSnapshotData.ts @@ -2,7 +2,7 @@ import { applyFieldOverrides, DefaultTimeRange, LoadingState, PanelData } from ' import { config } from 'app/core/config'; import { getDatasourceSrv } from 'app/features/plugins/datasource_srv'; import { DashboardModel, PanelModel } from '../state'; -import { getProcessedDataFrames } from '../state/runRequest'; +import { getProcessedDataFrames } from '../../query/state/runRequest'; export function loadSnapshotData(panel: PanelModel, dashboard: DashboardModel): PanelData { const data = getProcessedDataFrames(panel.snapshotData); diff --git a/public/app/features/explore/state/query.ts b/public/app/features/explore/state/query.ts index 896c8edb716..f7c01368006 100644 --- a/public/app/features/explore/state/query.ts +++ b/public/app/features/explore/state/query.ts @@ -27,7 +27,7 @@ import { ExploreId, QueryOptions } from 'app/types/explore'; import { getTimeZone } from 'app/features/profile/state/selectors'; import { getShiftedTimeRange } from 'app/core/utils/timePicker'; import { notifyApp } from '../../../core/actions'; -import { preProcessPanelData, runRequest } from '../../dashboard/state/runRequest'; +import { preProcessPanelData, runRequest } from '../../query/state/runRequest'; import { decorateWithGraphLogsTraceAndTable, decorateWithGraphResult, diff --git a/public/app/features/panel/metrics_panel_ctrl.ts b/public/app/features/panel/metrics_panel_ctrl.ts index 4bcf3bdf465..f5b157bdd3a 100644 --- a/public/app/features/panel/metrics_panel_ctrl.ts +++ b/public/app/features/panel/metrics_panel_ctrl.ts @@ -16,7 +16,7 @@ import { } from '@grafana/data'; import { Unsubscribable } from 'rxjs'; import { PanelModel } from 'app/features/dashboard/state'; -import { PanelQueryRunner } from '../dashboard/state/PanelQueryRunner'; +import { PanelQueryRunner } from '../query/state/PanelQueryRunner'; class MetricsPanelCtrl extends PanelCtrl { scope: any; diff --git a/public/app/features/dashboard/panel_editor/QueriesTab.tsx b/public/app/features/query/components/QueriesTab.tsx similarity index 98% rename from public/app/features/dashboard/panel_editor/QueriesTab.tsx rename to public/app/features/query/components/QueriesTab.tsx index 99434812939..a292d6419b0 100644 --- a/public/app/features/dashboard/panel_editor/QueriesTab.tsx +++ b/public/app/features/query/components/QueriesTab.tsx @@ -11,8 +11,8 @@ import { getDatasourceSrv } from 'app/features/plugins/datasource_srv'; import { backendSrv } from 'app/core/services/backend_srv'; import config from 'app/core/config'; // Types -import { PanelModel } from '../state/PanelModel'; -import { DashboardModel } from '../state/DashboardModel'; +import { PanelModel } from '../../dashboard/state/PanelModel'; +import { DashboardModel } from '../../dashboard/state/DashboardModel'; import { DataQuery, DataSourceSelectItem, @@ -31,7 +31,7 @@ import { selectors } from '@grafana/e2e-selectors'; interface Props { panel: PanelModel; - dashboard: DashboardModel; + dashboard?: DashboardModel; } interface State { @@ -153,10 +153,6 @@ export class QueriesTab extends PureComponent { }); }; - renderHelp = () => { - return; - }; - /** * Sets the queries for the panel */ diff --git a/public/app/features/dashboard/panel_editor/QueryEditorRow.test.ts b/public/app/features/query/components/QueryEditorRow.test.ts similarity index 100% rename from public/app/features/dashboard/panel_editor/QueryEditorRow.test.ts rename to public/app/features/query/components/QueryEditorRow.test.ts diff --git a/public/app/features/dashboard/panel_editor/QueryEditorRow.tsx b/public/app/features/query/components/QueryEditorRow.tsx similarity index 97% rename from public/app/features/dashboard/panel_editor/QueryEditorRow.tsx rename to public/app/features/query/components/QueryEditorRow.tsx index 626cdb45eda..9465fd5b4e4 100644 --- a/public/app/features/dashboard/panel_editor/QueryEditorRow.tsx +++ b/public/app/features/query/components/QueryEditorRow.tsx @@ -7,7 +7,7 @@ import { getDatasourceSrv } from 'app/features/plugins/datasource_srv'; import { AngularComponent, getAngularLoader } from '@grafana/runtime'; import { getTimeSrv } from 'app/features/dashboard/services/TimeSrv'; // Types -import { PanelModel } from '../state/PanelModel'; +import { PanelModel } from '../../dashboard/state/PanelModel'; import { ErrorBoundaryAlert, HorizontalGroup } from '@grafana/ui'; import { @@ -23,14 +23,14 @@ import { import { QueryEditorRowTitle } from './QueryEditorRowTitle'; import { QueryOperationRow } from 'app/core/components/QueryOperationRow/QueryOperationRow'; import { QueryOperationAction } from 'app/core/components/QueryOperationRow/QueryOperationAction'; -import { DashboardModel } from '../state/DashboardModel'; +import { DashboardModel } from '../../dashboard/state/DashboardModel'; import { selectors } from '@grafana/e2e-selectors'; interface Props { panel: PanelModel; data: PanelData; query: DataQuery; - dashboard: DashboardModel; + dashboard?: DashboardModel; dataSourceValue: string | null; inMixedMode?: boolean; id: string; @@ -79,9 +79,9 @@ export class QueryEditorRow extends PureComponent { datasource: datasource, target: query, panel: panel, - dashboard: dashboard, + dashboard: dashboard!, refresh: () => panel.refresh(), - render: () => panel.render(), + render: () => () => console.log('legacy render function called, it does nothing'), events: panel.events, range: getTimeSrv().timeRange(), }; @@ -141,13 +141,16 @@ export class QueryEditorRow extends PureComponent { if (!this.element) { return; } + if (this.angularQueryEditor) { this.angularQueryEditor.destroy(); this.angularQueryEditor = null; } + const loader = getAngularLoader(); const template = ''; const scopeProps = { ctrl: this.getAngularQueryComponentScope() }; + this.angularQueryEditor = loader.load(this.element, scopeProps, template); this.angularScope = scopeProps.ctrl; }; diff --git a/public/app/features/dashboard/panel_editor/QueryEditorRowTitle.tsx b/public/app/features/query/components/QueryEditorRowTitle.tsx similarity index 100% rename from public/app/features/dashboard/panel_editor/QueryEditorRowTitle.tsx rename to public/app/features/query/components/QueryEditorRowTitle.tsx diff --git a/public/app/features/dashboard/panel_editor/QueryEditorRows.tsx b/public/app/features/query/components/QueryEditorRows.tsx similarity index 95% rename from public/app/features/dashboard/panel_editor/QueryEditorRows.tsx rename to public/app/features/query/components/QueryEditorRows.tsx index 9a45c9bcc1d..008a4e92374 100644 --- a/public/app/features/dashboard/panel_editor/QueryEditorRows.tsx +++ b/public/app/features/query/components/QueryEditorRows.tsx @@ -2,9 +2,9 @@ import React, { PureComponent } from 'react'; // Types -import { PanelModel } from '../state/PanelModel'; +import { PanelModel } from '../../dashboard/state/PanelModel'; import { DataQuery, PanelData, DataSourceSelectItem } from '@grafana/data'; -import { DashboardModel } from '../state/DashboardModel'; +import { DashboardModel } from '../../dashboard/state/DashboardModel'; import { QueryEditorRow } from './QueryEditorRow'; import { addQuery } from 'app/core/utils/query'; import { DragDropContext, Droppable, DropResult } from 'react-beautiful-dnd'; @@ -20,7 +20,7 @@ interface Props { // Dashboard Configs panel: PanelModel; - dashboard: DashboardModel; + dashboard?: DashboardModel; // Query Response Data data: PanelData; diff --git a/public/app/features/dashboard/panel_editor/QueryOptions.tsx b/public/app/features/query/components/QueryOptions.tsx similarity index 99% rename from public/app/features/dashboard/panel_editor/QueryOptions.tsx rename to public/app/features/query/components/QueryOptions.tsx index 89421689d4c..0d820a682c4 100644 --- a/public/app/features/dashboard/panel_editor/QueryOptions.tsx +++ b/public/app/features/query/components/QueryOptions.tsx @@ -8,7 +8,7 @@ import { rangeUtil, PanelData, DataSourceApi } from '@grafana/data'; import { Switch, Input, InlineField, InlineFormLabel, stylesFactory } from '@grafana/ui'; // Types -import { PanelModel } from '../state'; +import { PanelModel } from '../../dashboard/state'; import { QueryOperationRow } from 'app/core/components/QueryOperationRow/QueryOperationRow'; import { config } from 'app/core/config'; import { css } from 'emotion'; diff --git a/public/app/features/dashboard/state/PanelQueryRunner.test.ts b/public/app/features/query/state/PanelQueryRunner.test.ts similarity index 99% rename from public/app/features/dashboard/state/PanelQueryRunner.test.ts rename to public/app/features/query/state/PanelQueryRunner.test.ts index 86808b2d035..092b33e16a0 100644 --- a/public/app/features/dashboard/state/PanelQueryRunner.test.ts +++ b/public/app/features/query/state/PanelQueryRunner.test.ts @@ -17,7 +17,7 @@ import { PanelData, ScopedVars, } from '@grafana/data'; -import { DashboardModel } from './index'; +import { DashboardModel } from '../../dashboard/state/index'; import { setDataSourceSrv, setEchoSrv } from '@grafana/runtime'; import { Echo } from '../../../core/services/echo/Echo'; diff --git a/public/app/features/dashboard/state/PanelQueryRunner.ts b/public/app/features/query/state/PanelQueryRunner.ts similarity index 100% rename from public/app/features/dashboard/state/PanelQueryRunner.ts rename to public/app/features/query/state/PanelQueryRunner.ts diff --git a/public/app/features/dashboard/state/analyticsProcessor.test.ts b/public/app/features/query/state/queryAnalytics.test.ts similarity index 95% rename from public/app/features/dashboard/state/analyticsProcessor.test.ts rename to public/app/features/query/state/queryAnalytics.test.ts index 5cd1590d1bf..7af84e4fcb8 100644 --- a/public/app/features/dashboard/state/analyticsProcessor.test.ts +++ b/public/app/features/query/state/queryAnalytics.test.ts @@ -1,7 +1,7 @@ import { MetaAnalyticsEventName, reportMetaAnalytics } from '@grafana/runtime'; import { CoreApp, DataQueryRequest, DataSourceApi, dateTime, LoadingState, PanelData } from '@grafana/data'; -import { emitDataRequestEvent } from './analyticsProcessor'; -import { DashboardModel } from './DashboardModel'; +import { emitDataRequestEvent } from './queryAnalytics'; +import { DashboardModel } from '../../dashboard/state/DashboardModel'; beforeEach(() => { jest.clearAllMocks(); diff --git a/public/app/features/query/state/queryAnalytics.ts b/public/app/features/query/state/queryAnalytics.ts new file mode 100644 index 00000000000..90b288724eb --- /dev/null +++ b/public/app/features/query/state/queryAnalytics.ts @@ -0,0 +1,56 @@ +import { getDashboardSrv } from '../../dashboard/services/DashboardSrv'; +import { PanelData, LoadingState, DataSourceApi, CoreApp, urlUtil } from '@grafana/data'; +import { reportMetaAnalytics, MetaAnalyticsEventName, DataRequestEventPayload } from '@grafana/runtime'; + +export function emitDataRequestEvent(datasource: DataSourceApi) { + let done = false; + + return (data: PanelData) => { + if (!data.request || done || data.request.app === CoreApp.Explore) { + return; + } + + const params = urlUtil.getUrlSearchParams(); + if (params.editPanel != null) { + return; + } + + if (data.state !== LoadingState.Done && data.state !== LoadingState.Error) { + return; + } + + const eventData: DataRequestEventPayload = { + eventName: MetaAnalyticsEventName.DataRequest, + datasourceName: datasource.name, + datasourceId: datasource.id, + panelId: data.request.panelId, + dashboardId: data.request.dashboardId, + dataSize: 0, + duration: data.request.endTime! - data.request.startTime, + }; + + // enrich with dashboard info + const dashboard = getDashboardSrv().getCurrent(); + if (dashboard) { + eventData.dashboardId = dashboard.id; + eventData.dashboardName = dashboard.title; + eventData.dashboardUid = dashboard.uid; + eventData.folderName = dashboard.meta.folderTitle; + } + + if (data.series && data.series.length > 0) { + // estimate size + eventData.dataSize = data.series.length; + } + + if (data.error) { + eventData.error = data.error.message; + } + + reportMetaAnalytics(eventData); + + // this done check is to make sure we do not double emit events in case + // there are multiple responses with done state + done = true; + }; +} diff --git a/public/app/features/dashboard/state/runRequest.test.ts b/public/app/features/query/state/runRequest.test.ts similarity index 99% rename from public/app/features/dashboard/state/runRequest.test.ts rename to public/app/features/query/state/runRequest.test.ts index 76ce4aa2141..d2a25396d81 100644 --- a/public/app/features/dashboard/state/runRequest.test.ts +++ b/public/app/features/query/state/runRequest.test.ts @@ -11,7 +11,7 @@ import { import { Observable, Subscriber, Subscription } from 'rxjs'; import { runRequest } from './runRequest'; import { deepFreeze } from '../../../../test/core/redux/reducerTester'; -import { DashboardModel } from './DashboardModel'; +import { DashboardModel } from '../../dashboard/state/DashboardModel'; import { setEchoSrv } from '@grafana/runtime'; import { Echo } from '../../../core/services/echo/Echo'; diff --git a/public/app/features/dashboard/state/runRequest.ts b/public/app/features/query/state/runRequest.ts similarity index 99% rename from public/app/features/dashboard/state/runRequest.ts rename to public/app/features/query/state/runRequest.ts index 327ba76190a..605c6261334 100644 --- a/public/app/features/dashboard/state/runRequest.ts +++ b/public/app/features/query/state/runRequest.ts @@ -20,7 +20,7 @@ import { toDataFrame, } from '@grafana/data'; import { toDataQueryError } from '@grafana/runtime'; -import { emitDataRequestEvent } from './analyticsProcessor'; +import { emitDataRequestEvent } from './queryAnalytics'; import { expressionDatasource, ExpressionDatasourceID } from 'app/features/expressions/ExpressionDatasource'; import { ExpressionQuery } from 'app/features/expressions/types'; diff --git a/public/app/features/sandbox/TestStuffPage.tsx b/public/app/features/sandbox/TestStuffPage.tsx new file mode 100644 index 00000000000..11d6bc4bdbb --- /dev/null +++ b/public/app/features/sandbox/TestStuffPage.tsx @@ -0,0 +1,33 @@ +import React, { FC, useState } from 'react'; +import { PanelModel } from '../dashboard/state'; +import { QueriesTab } from '../query/components/QueriesTab'; + +interface State { + panel: PanelModel; +} + +export const TestStuffPage: FC = () => { + const [state] = useState(getDefaultState()); + + return ( +
+

Hello

+ + +
+ ); +}; + +export function getDefaultState(): State { + const panel = new PanelModel({ + datasource: 'gdev-testdata', + id: 10, + targets: [], + }); + + return { + panel, + }; +} + +export default TestStuffPage; diff --git a/public/app/features/variables/query/VariableQueryRunner.ts b/public/app/features/variables/query/VariableQueryRunner.ts index 4ab45c5be8a..58a399be439 100644 --- a/public/app/features/variables/query/VariableQueryRunner.ts +++ b/public/app/features/variables/query/VariableQueryRunner.ts @@ -19,7 +19,7 @@ import { getTemplatedRegex } from '../utils'; import { v4 as uuidv4 } from 'uuid'; import { getTimeSrv } from '../../dashboard/services/TimeSrv'; import { QueryRunners } from './queryRunners'; -import { runRequest } from '../../dashboard/state/runRequest'; +import { runRequest } from '../../query/state/runRequest'; import { runUpdateTagsRequest, toMetricFindValues, diff --git a/public/app/plugins/datasource/dashboard/DashboardQueryEditor.tsx b/public/app/plugins/datasource/dashboard/DashboardQueryEditor.tsx index 52e1df63d12..a49afcb6133 100644 --- a/public/app/plugins/datasource/dashboard/DashboardQueryEditor.tsx +++ b/public/app/plugins/datasource/dashboard/DashboardQueryEditor.tsx @@ -11,7 +11,8 @@ import { getDatasourceSrv } from 'app/features/plugins/datasource_srv'; import { PanelModel } from 'app/features/dashboard/state'; import { SHARED_DASHBODARD_QUERY } from './types'; import { getDashboardSrv } from 'app/features/dashboard/services/DashboardSrv'; -import { filterPanelDataToQuery } from 'app/features/dashboard/panel_editor/QueryEditorRow'; +import { filterPanelDataToQuery } from 'app/features/query/components/QueryEditorRow'; + const { Select } = LegacyForms; type ResultInfo = { diff --git a/public/app/plugins/datasource/dashboard/runSharedRequest.ts b/public/app/plugins/datasource/dashboard/runSharedRequest.ts index 09f1e01dfc4..8a2addb8a2e 100644 --- a/public/app/plugins/datasource/dashboard/runSharedRequest.ts +++ b/public/app/plugins/datasource/dashboard/runSharedRequest.ts @@ -1,5 +1,5 @@ import { Observable } from 'rxjs'; -import { QueryRunnerOptions } from 'app/features/dashboard/state/PanelQueryRunner'; +import { QueryRunnerOptions } from 'app/features/query/state/PanelQueryRunner'; import { DashboardQuery, SHARED_DASHBODARD_QUERY } from './types'; import { getDashboardSrv } from 'app/features/dashboard/services/DashboardSrv'; import { LoadingState, DefaultTimeRange, DataQuery, PanelData, DataSourceApi, DataQueryRequest } from '@grafana/data'; diff --git a/public/app/plugins/panel/graph/module.ts b/public/app/plugins/panel/graph/module.ts index 195c95d55cb..a05e9aba3e4 100644 --- a/public/app/plugins/panel/graph/module.ts +++ b/public/app/plugins/panel/graph/module.ts @@ -11,7 +11,7 @@ import { DataProcessor } from './data_processor'; import { axesEditorComponent } from './axes_editor'; import config from 'app/core/config'; import TimeSeries from 'app/core/time_series2'; -import { getProcessedDataFrames } from 'app/features/dashboard/state/runRequest'; +import { getProcessedDataFrames } from 'app/features/query/state/runRequest'; import { DataFrame, FieldConfigProperty, getColorForTheme, PanelEvents, PanelPlugin } from '@grafana/data'; import { GraphContextMenuCtrl } from './GraphContextMenuCtrl'; diff --git a/public/app/plugins/panel/graph/specs/data_processor.test.ts b/public/app/plugins/panel/graph/specs/data_processor.test.ts index 5eee488b673..307b6e3e8d9 100644 --- a/public/app/plugins/panel/graph/specs/data_processor.test.ts +++ b/public/app/plugins/panel/graph/specs/data_processor.test.ts @@ -1,5 +1,5 @@ import { DataProcessor } from '../data_processor'; -import { getProcessedDataFrames } from 'app/features/dashboard/state/runRequest'; +import { getProcessedDataFrames } from 'app/features/query/state/runRequest'; describe('Graph DataProcessor', () => { const panel: any = { diff --git a/public/app/plugins/panel/heatmap/heatmap_ctrl.ts b/public/app/plugins/panel/heatmap/heatmap_ctrl.ts index 6038f905106..ea93bf3ef99 100644 --- a/public/app/plugins/panel/heatmap/heatmap_ctrl.ts +++ b/public/app/plugins/panel/heatmap/heatmap_ctrl.ts @@ -13,7 +13,7 @@ import { sortSeriesByLabel, } from './heatmap_data_converter'; import { auto } from 'angular'; -import { getProcessedDataFrames } from 'app/features/dashboard/state/runRequest'; +import { getProcessedDataFrames } from 'app/features/query/state/runRequest'; import { DataProcessor } from '../graph/data_processor'; import { LegacyResponseData, PanelEvents, DataFrame, rangeUtil } from '@grafana/data'; import { CoreEvents } from 'app/types'; diff --git a/public/app/plugins/panel/singlestat/module.ts b/public/app/plugins/panel/singlestat/module.ts index 2abd1acfb96..6fe53bc743f 100644 --- a/public/app/plugins/panel/singlestat/module.ts +++ b/public/app/plugins/panel/singlestat/module.ts @@ -31,7 +31,7 @@ import { convertOldAngularValueMapping } from '@grafana/ui'; import config from 'app/core/config'; import { MetricsPanelCtrl } from 'app/plugins/sdk'; import { LinkSrv } from 'app/features/panel/panellinks/link_srv'; -import { getProcessedDataFrames } from 'app/features/dashboard/state/runRequest'; +import { getProcessedDataFrames } from 'app/features/query/state/runRequest'; const BASE_FONT_SIZE = 38; diff --git a/public/app/routes/routes.ts b/public/app/routes/routes.ts index c27b65080f0..2218cf50cb0 100644 --- a/public/app/routes/routes.ts +++ b/public/app/routes/routes.ts @@ -237,6 +237,14 @@ export function setupAngularRoutes($routeProvider: route.IRouteProvider, $locati component: () => SafeDynamicImport(import(/* webpackChunkName: "explore" */ 'app/features/explore/Wrapper')), }, }) + .when('/sandbox/test', { + template: '', + reloadOnSearch: false, + resolve: { + component: () => + SafeDynamicImport(import(/* webpackChunkName: "sandbox" */ 'app/features/sandbox/TestStuffPage')), + }, + }) .when('/a/:pluginId/', { // Someday * and will get a ReactRouter under that path! template: '',