From c96c92d712f9e555b7d5e4c5754ac2021829568d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Wed, 10 Nov 2021 11:05:36 +0100 Subject: [PATCH] Angular: Isolate angular more (#41440) * Getting close * Restore angular app boot at startup * Moving angular annotations dependencies to app/angular or old graph * Remove redundant setLinkSrv call * Fixing graph test * Minor refactor based on review feedback * Create in get function --- public/app/AppWrapper.tsx | 15 +--- public/app/angular/AngularApp.ts | 3 + public/app/angular/AngularRoot.tsx | 15 ++++ public/app/{routes => angular}/GrafanaCtrl.ts | 27 +----- public/app/angular/diff-view.ts | 2 +- public/app/angular/index.ts | 1 + public/app/angular/lazyBootAngular.ts | 23 +++++ public/app/angular/registerComponents.ts | 9 +- public/app/angular/services/AngularLoader.ts | 2 +- .../services}/annotations_srv.test.ts | 2 +- .../services}/annotations_srv.ts | 87 +------------------ public/app/angular/services/popover_srv.ts | 2 +- public/app/app.ts | 15 +++- public/app/core/profiler.ts | 15 +--- public/app/core/services/util_srv.ts | 3 +- public/app/features/all.ts | 1 - public/app/features/annotations/all.ts | 5 -- .../StandardAnnotationQueryEditor.tsx | 2 +- ...pecs.test.ts => events_processing.test.ts} | 2 +- .../annotations/executeAnnotationQuery.ts | 74 ++++++++++++++++ .../PanelEditor/getFieldOverrideElements.tsx | 2 +- .../PanelEditor/getPanelFrameOptions.tsx | 2 +- .../PanelEditor/getVizualizationOptions.tsx | 2 +- .../components/SubMenu/DashboardLinks.tsx | 2 +- .../SubMenu/DashboardLinksDashboard.tsx | 2 +- .../components/VersionHistory/HistorySrv.ts | 3 - .../dashgrid/PanelHeader/PanelHeader.tsx | 2 +- .../dashboard/services/DashboardSrv.ts | 6 +- .../explore/TraceView/createSpanLink.test.ts | 2 +- .../app/features/explore/utils/links.test.ts | 2 +- public/app/features/explore/utils/links.ts | 2 +- .../panel/panellinks/linkSuppliers.test.ts | 2 +- .../panel/panellinks/linkSuppliers.ts | 0 .../panel/panellinks/link_srv.ts | 27 ++---- .../panel/panellinks/specs/link_srv.test.ts | 0 public/app/features/plugins/datasource_srv.ts | 33 +++---- .../app/features/plugins/plugin_component.ts | 2 +- .../app/features/plugins/plugin_page_ctrl.ts | 2 +- .../plugins/specs/datasource_srv.test.ts | 2 +- .../AnnotationsQueryRunner.test.ts | 2 +- .../AnnotationsQueryRunner.ts | 2 +- .../AnnotationsWorker.test.ts | 2 +- .../DashboardQueryRunner.test.ts | 2 +- .../loki/configuration/DebugSection.test.tsx | 2 +- .../panel/graph}/annotation_tooltip.ts | 4 +- .../panel/graph}/event_editor.ts | 4 +- .../panel/graph}/event_manager.ts | 0 public/app/plugins/panel/graph/graph.ts | 4 +- public/app/plugins/panel/graph/module.ts | 2 + .../plugins/panel/graph/specs/graph.test.ts | 2 +- public/test/specs/helpers.ts | 2 +- 51 files changed, 201 insertions(+), 227 deletions(-) create mode 100644 public/app/angular/AngularRoot.tsx rename public/app/{routes => angular}/GrafanaCtrl.ts (86%) create mode 100644 public/app/angular/lazyBootAngular.ts rename public/app/{features/annotations/specs => angular/services}/annotations_srv.test.ts (93%) rename public/app/{features/annotations => angular/services}/annotations_srv.ts (55%) delete mode 100644 public/app/features/annotations/all.ts rename public/app/features/annotations/{specs/annotations_srv_specs.test.ts => events_processing.test.ts} (94%) create mode 100644 public/app/features/annotations/executeAnnotationQuery.ts rename public/app/{angular => features}/panel/panellinks/linkSuppliers.test.ts (98%) rename public/app/{angular => features}/panel/panellinks/linkSuppliers.ts (100%) rename public/app/{angular => features}/panel/panellinks/link_srv.ts (92%) rename public/app/{angular => features}/panel/panellinks/specs/link_srv.test.ts (100%) rename public/app/{features/annotations => plugins/panel/graph}/annotation_tooltip.ts (95%) rename public/app/{features/annotations => plugins/panel/graph}/event_editor.ts (94%) rename public/app/{features/annotations => plugins/panel/graph}/event_manager.ts (100%) diff --git a/public/app/AppWrapper.tsx b/public/app/AppWrapper.tsx index eed25f8f2ee..63ff476ebe3 100644 --- a/public/app/AppWrapper.tsx +++ b/public/app/AppWrapper.tsx @@ -15,6 +15,7 @@ import { GrafanaRoute } from './core/navigation/GrafanaRoute'; import { AppNotificationList } from './core/components/AppNotifications/AppNotificationList'; import { SearchWrapper } from 'app/features/search'; import { LiveConnectionWarning } from './features/live/LiveConnectionWarning'; +import { AngularRoot } from './angular/AngularRoot'; interface AppWrapperProps { app: GrafanaApp; @@ -57,6 +58,7 @@ export class AppWrapper extends React.Component { @@ -89,8 +91,6 @@ export class AppWrapper extends React.Component`; const newNavigationEnabled = config.featureToggles.newNavigation; return ( @@ -108,17 +108,10 @@ export class AppWrapper extends React.Component ))} -
- + - {this.state.ngInjector && this.container && this.renderRoutes()} + {this.state.ngInjector && this.renderRoutes()} {bodyRenderHooks.map((Hook, index) => ( ))} diff --git a/public/app/angular/AngularApp.ts b/public/app/angular/AngularApp.ts index c17f7ac6e0e..a746e355e1b 100644 --- a/public/app/angular/AngularApp.ts +++ b/public/app/angular/AngularApp.ts @@ -92,6 +92,9 @@ export class AngularApp { registerAngularDirectives(); registerComponents(); initAngularRoutingBridge(); + + // disable tool tip animation + $.fn.tooltip.defaults.animation = false; } useModule(module: angular.IModule) { diff --git a/public/app/angular/AngularRoot.tsx b/public/app/angular/AngularRoot.tsx new file mode 100644 index 00000000000..ec3964a7b86 --- /dev/null +++ b/public/app/angular/AngularRoot.tsx @@ -0,0 +1,15 @@ +import React from 'react'; + +export const AngularRoot = React.forwardRef((props, ref) => { + return ( +
', + }} + /> + ); +}); + +AngularRoot.displayName = 'AngularRoot'; diff --git a/public/app/routes/GrafanaCtrl.ts b/public/app/angular/GrafanaCtrl.ts similarity index 86% rename from public/app/routes/GrafanaCtrl.ts rename to public/app/angular/GrafanaCtrl.ts index a800a3a1e5d..e8ee62136d9 100644 --- a/public/app/routes/GrafanaCtrl.ts +++ b/public/app/angular/GrafanaCtrl.ts @@ -5,27 +5,16 @@ import $ from 'jquery'; // Utils and servies import { colors } from '@grafana/ui'; -import { - setDataSourceSrv, - setLegacyAngularInjector, - setLocationSrv, - locationService, - setAppEvents, - setAngularLoader, -} from '@grafana/runtime'; +import { setLegacyAngularInjector, setAppEvents, setAngularLoader } from '@grafana/runtime'; import config from 'app/core/config'; import coreModule from 'app/angular/core_module'; -import { profiler } from 'app/core/profiler'; import appEvents from 'app/core/app_events'; -import { DatasourceSrv } from 'app/features/plugins/datasource_srv'; import { AngularLoader } from 'app/angular/services/AngularLoader'; // Types import { CoreEvents, AppEventEmitter, AppEventConsumer } from 'app/types'; -import { setLinkSrv, LinkSrv } from 'app/angular/panel/panellinks/link_srv'; import { UtilSrv } from 'app/core/services/util_srv'; import { ContextSrv } from 'app/core/services/context_srv'; -import { DashboardSrv, setDashboardSrv } from 'app/features/dashboard/services/DashboardSrv'; import { IRootScopeService, IAngularEvent, auto } from 'angular'; import { AppEvent } from '@grafana/data'; import { initGrafanaLive } from 'app/features/live'; @@ -39,22 +28,12 @@ export class GrafanaCtrl { utilSrv: UtilSrv, $rootScope: GrafanaRootScope, contextSrv: ContextSrv, - linkSrv: LinkSrv, - datasourceSrv: DatasourceSrv, - dashboardSrv: DashboardSrv, angularLoader: AngularLoader, $injector: auto.IInjectorService ) { // make angular loader service available to react components setAngularLoader(angularLoader); - setDataSourceSrv(datasourceSrv); - setLinkSrv(linkSrv); - setDashboardSrv(dashboardSrv); setLegacyAngularInjector($injector); - - datasourceSrv.init(config.datasources, config.defaultDatasource); - - setLocationSrv(locationService); setAppEvents(appEvents); initGrafanaLive(); @@ -63,8 +42,6 @@ export class GrafanaCtrl { $scope.contextSrv = contextSrv; $scope.appSubUrl = config.appSubUrl; $scope._ = _; - - profiler.init(config, $rootScope); utilSrv.init(); }; @@ -116,8 +93,6 @@ export function grafanaAppDirective() { // see https://github.com/zenorocha/clipboard.js/issues/155 $.fn.modal.Constructor.prototype.enforceFocus = () => {}; - $('.preloader').remove(); - appEvents.on(CoreEvents.toggleSidemenuHidden, () => { body.toggleClass('sidemenu-hidden'); }); diff --git a/public/app/angular/diff-view.ts b/public/app/angular/diff-view.ts index 72ebed93fe6..664edd0f381 100644 --- a/public/app/angular/diff-view.ts +++ b/public/app/angular/diff-view.ts @@ -1,6 +1,6 @@ import angular from 'angular'; import coreModule from './core_module'; -import { GrafanaRootScope } from 'app/routes/GrafanaCtrl'; +import { GrafanaRootScope } from 'app/angular/GrafanaCtrl'; export class DeltaCtrl { observer: any; diff --git a/public/app/angular/index.ts b/public/app/angular/index.ts index f8ea94d9b7d..88e6d011480 100644 --- a/public/app/angular/index.ts +++ b/public/app/angular/index.ts @@ -31,5 +31,6 @@ import './components/info_popover'; import './components/spectrum_picker'; import './components/code_editor/code_editor'; import './components/sql_part/sql_part_editor'; +import './GrafanaCtrl'; export { AngularApp } from './AngularApp'; diff --git a/public/app/angular/lazyBootAngular.ts b/public/app/angular/lazyBootAngular.ts new file mode 100644 index 00000000000..81ee623f126 --- /dev/null +++ b/public/app/angular/lazyBootAngular.ts @@ -0,0 +1,23 @@ +import { auto } from 'angular'; + +let injector: auto.IInjectorService | undefined; + +/** + * Future poc to lazy load angular app, not yet used + */ +export async function getAngularInjector(): Promise { + if (injector) { + return injector; + } + + const { AngularApp } = await import(/* webpackChunkName: "AngularApp" */ './index'); + if (injector) { + return injector; + } + + const app = new AngularApp(); + app.init(); + injector = app.bootstrap(); + + return injector; +} diff --git a/public/app/angular/registerComponents.ts b/public/app/angular/registerComponents.ts index c9b73f28af2..6b3546e6288 100644 --- a/public/app/angular/registerComponents.ts +++ b/public/app/angular/registerComponents.ts @@ -1,8 +1,15 @@ -import { getBackendSrv } from '@grafana/runtime'; +import { getBackendSrv, getDataSourceSrv } from '@grafana/runtime'; import { contextSrv } from 'app/core/core'; +import { getDashboardSrv } from 'app/features/dashboard/services/DashboardSrv'; +import { getLinkSrv } from 'app/features/panel/panellinks/link_srv'; import coreModule from './core_module'; +import { AnnotationsSrv } from './services/annotations_srv'; export function registerComponents() { coreModule.factory('backendSrv', () => getBackendSrv()); coreModule.factory('contextSrv', () => contextSrv); + coreModule.factory('dashboardSrv', () => getDashboardSrv()); + coreModule.factory('datasourceSrv', () => getDataSourceSrv()); + coreModule.factory('linkSrv', () => getLinkSrv()); + coreModule.service('annotationsSrv', AnnotationsSrv); } diff --git a/public/app/angular/services/AngularLoader.ts b/public/app/angular/services/AngularLoader.ts index eb2cec7a9f3..438da88cc88 100644 --- a/public/app/angular/services/AngularLoader.ts +++ b/public/app/angular/services/AngularLoader.ts @@ -3,7 +3,7 @@ import coreModule from 'app/angular/core_module'; import { assign } from 'lodash'; import { AngularComponent, AngularLoader as AngularLoaderInterface } from '@grafana/runtime'; -import { GrafanaRootScope } from 'app/routes/GrafanaCtrl'; +import { GrafanaRootScope } from 'app/angular/GrafanaCtrl'; export class AngularLoader implements AngularLoaderInterface { /** @ngInject */ diff --git a/public/app/features/annotations/specs/annotations_srv.test.ts b/public/app/angular/services/annotations_srv.test.ts similarity index 93% rename from public/app/features/annotations/specs/annotations_srv.test.ts rename to public/app/angular/services/annotations_srv.test.ts index 5329a1450aa..621cdff0895 100644 --- a/public/app/features/annotations/specs/annotations_srv.test.ts +++ b/public/app/angular/services/annotations_srv.test.ts @@ -1,4 +1,4 @@ -import { AnnotationsSrv } from '../annotations_srv'; +import { AnnotationsSrv } from './annotations_srv'; describe('AnnotationsSrv', () => { const annotationsSrv = new AnnotationsSrv(); diff --git a/public/app/features/annotations/annotations_srv.ts b/public/app/angular/services/annotations_srv.ts similarity index 55% rename from public/app/features/annotations/annotations_srv.ts rename to public/app/angular/services/annotations_srv.ts index dc4f2dd40b8..3e90ee3e594 100644 --- a/public/app/features/annotations/annotations_srv.ts +++ b/public/app/angular/services/annotations_srv.ts @@ -1,26 +1,9 @@ import { cloneDeep } from 'lodash'; -import { Observable, of } from 'rxjs'; -import { map, mergeMap } from 'rxjs/operators'; -import { - AnnotationEvent, - CoreApp, - DataQueryRequest, - DataSourceApi, - deprecationWarning, - rangeUtil, - ScopedVars, -} from '@grafana/data'; +import { AnnotationEvent, deprecationWarning } from '@grafana/data'; -import coreModule from 'app/angular/core_module'; -import { AnnotationQueryOptions, AnnotationQueryResponse } from './types'; -import { standardAnnotationSupport } from './standardAnnotationSupport'; -import { runRequest } from '../query/state/runRequest'; -import { deleteAnnotation, saveAnnotation, updateAnnotation } from './api'; +import { deleteAnnotation, saveAnnotation, updateAnnotation } from 'app/features/annotations/api'; +import { AnnotationQueryOptions } from 'app/features/annotations/types'; -let counter = 100; -function getNextRequestId() { - return 'AQ' + counter++; -} /** * @deprecated AnnotationsSrv is deprecated in favor of DashboardQueryRunner */ @@ -102,67 +85,3 @@ export class AnnotationsSrv { return results; } } - -export function executeAnnotationQuery( - options: AnnotationQueryOptions, - datasource: DataSourceApi, - savedJsonAnno: any -): Observable { - const processor = { - ...standardAnnotationSupport, - ...datasource.annotations, - }; - - const annotation = processor.prepareAnnotation!(savedJsonAnno); - if (!annotation) { - return of({}); - } - - const query = processor.prepareQuery!(annotation); - if (!query) { - return of({}); - } - - // No more points than pixels - const maxDataPoints = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth; - - // Add interval to annotation queries - const interval = rangeUtil.calculateInterval(options.range, maxDataPoints, datasource.interval); - - const scopedVars: ScopedVars = { - __interval: { text: interval.interval, value: interval.interval }, - __interval_ms: { text: interval.intervalMs.toString(), value: interval.intervalMs }, - __annotation: { text: annotation.name, value: annotation }, - }; - - const queryRequest: DataQueryRequest = { - startTime: Date.now(), - requestId: getNextRequestId(), - range: options.range, - maxDataPoints, - scopedVars, - ...interval, - app: CoreApp.Dashboard, - - timezone: options.dashboard.timezone, - - targets: [ - { - ...query, - refId: 'Anno', - }, - ], - }; - - return runRequest(datasource, queryRequest).pipe( - mergeMap((panelData) => { - if (!panelData.series) { - return of({ panelData, events: [] }); - } - - return processor.processEvents!(annotation, panelData.series).pipe(map((events) => ({ panelData, events }))); - }) - ); -} - -coreModule.service('annotationsSrv', AnnotationsSrv); diff --git a/public/app/angular/services/popover_srv.ts b/public/app/angular/services/popover_srv.ts index 57c70a1afe8..e84c0975f33 100644 --- a/public/app/angular/services/popover_srv.ts +++ b/public/app/angular/services/popover_srv.ts @@ -2,7 +2,7 @@ import { extend } from 'lodash'; import coreModule from 'app/angular/core_module'; // @ts-ignore import Drop from 'tether-drop'; -import { GrafanaRootScope } from 'app/routes/GrafanaCtrl'; +import { GrafanaRootScope } from 'app/angular/GrafanaCtrl'; /** @ngInject */ function popoverSrv(this: any, $compile: any, $rootScope: GrafanaRootScope, $timeout: any) { diff --git a/public/app/app.ts b/public/app/app.ts index e4967cc84d9..6807b091efa 100644 --- a/public/app/app.ts +++ b/public/app/app.ts @@ -27,16 +27,18 @@ import { import { arrayMove } from 'app/core/utils/arrayMove'; import { importPluginModule } from 'app/features/plugins/plugin_loader'; import { + locationService, registerEchoBackend, setBackendSrv, + setDataSourceSrv, setEchoSrv, + setLocationSrv, setPanelRenderer, setQueryRunnerFactory, } from '@grafana/runtime'; import { Echo } from './core/services/echo/Echo'; import { reportPerformance } from './core/services/echo/EchoSrv'; import { PerformanceBackend } from './core/services/echo/backends/PerformanceBackend'; -import 'app/routes/GrafanaCtrl'; import 'app/features/all'; import { getScrollbarWidth, getStandardFieldConfigs } from '@grafana/ui'; import { getDefaultVariableAdapters, variableAdapters } from './features/variables/adapters'; @@ -47,7 +49,6 @@ import { setVariableQueryRunner, VariableQueryRunner } from './features/variable import { configureStore } from './store/configureStore'; import { AppWrapper } from './AppWrapper'; import { interceptLinkClicks } from './core/navigation/patch/interceptLinkClicks'; -import { AngularApp } from './angular'; import { PanelRenderer } from './features/panel/components/PanelRenderer'; import { QueryRunner } from './features/query/state/QueryRunner'; import { getTimeSrv } from './features/dashboard/services/TimeSrv'; @@ -59,6 +60,8 @@ import { ApplicationInsightsBackend } from './core/services/echo/backends/analyt import { RudderstackBackend } from './core/services/echo/backends/analytics/RudderstackBackend'; import { getAllOptionEditors } from './core/components/editors/registry'; import { backendSrv } from './core/services/backend_srv'; +import { DatasourceSrv } from './features/plugins/datasource_srv'; +import { AngularApp } from './angular'; // add move to lodash for backward compatabilty with plugins // @ts-ignore @@ -89,6 +92,7 @@ export class GrafanaApp { setLocale(config.bootData.user.locale); setWeekStart(config.bootData.user.weekStart); setPanelRenderer(PanelRenderer); + setLocationSrv(locationService); setTimeZoneResolver(() => config.bootData.user.timezone); // Important that extensions are initialized before store initExtensions(); @@ -112,9 +116,12 @@ export class GrafanaApp { // intercept anchor clicks and forward it to custom history instead of relying on browser's history document.addEventListener('click', interceptLinkClicks); - // disable tool tip animation - $.fn.tooltip.defaults.animation = false; + // Init DataSourceSrv + const dataSourceSrv = new DatasourceSrv(); + dataSourceSrv.init(config.datasources, config.defaultDatasource); + setDataSourceSrv(dataSourceSrv); + // Init angular this.angularApp.init(); // Preload selected app plugins diff --git a/public/app/core/profiler.ts b/public/app/core/profiler.ts index 100b42d4171..a83be82c536 100644 --- a/public/app/core/profiler.ts +++ b/public/app/core/profiler.ts @@ -1,19 +1,6 @@ -import { GrafanaRootScope } from 'app/routes/GrafanaCtrl'; - export class Profiler { panelsRendered = 0; enabled?: boolean = undefined; - $rootScope?: GrafanaRootScope = undefined; - window?: any = undefined; - - init(config: any, $rootScope: GrafanaRootScope) { - this.$rootScope = $rootScope; - this.window = window; - - if (!this.enabled) { - return; - } - } renderingCompleted() { // add render counter to root scope @@ -22,7 +9,7 @@ export class Profiler { // this window variable is used by backend rendering tools to know // all panels have completed rendering - this.window.panelsRendered = this.panelsRendered; + (window as any).panelsRendered = this.panelsRendered; } } diff --git a/public/app/core/services/util_srv.ts b/public/app/core/services/util_srv.ts index 74b3676b642..75e70b2ca5d 100644 --- a/public/app/core/services/util_srv.ts +++ b/public/app/core/services/util_srv.ts @@ -3,8 +3,7 @@ import ReactDOM from 'react-dom'; import coreModule from 'app/angular/core_module'; import appEvents from 'app/core/app_events'; - -import { GrafanaRootScope } from 'app/routes/GrafanaCtrl'; +import { GrafanaRootScope } from 'app/angular/GrafanaCtrl'; import { AngularModalProxy } from '../components/modals/AngularModalProxy'; import { provideTheme } from '../utils/ConfigProvider'; import { diff --git a/public/app/features/all.ts b/public/app/features/all.ts index fcb7c20703e..ad19a4a89b0 100644 --- a/public/app/features/all.ts +++ b/public/app/features/all.ts @@ -1,4 +1,3 @@ -import './annotations/all'; import './plugins/all'; import './dashboard'; import './manage-dashboards'; diff --git a/public/app/features/annotations/all.ts b/public/app/features/annotations/all.ts deleted file mode 100644 index ed2c65062be..00000000000 --- a/public/app/features/annotations/all.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { AnnotationsSrv } from './annotations_srv'; -import { eventEditor } from './event_editor'; -import { EventManager } from './event_manager'; -import { annotationTooltipDirective } from './annotation_tooltip'; -export { AnnotationsSrv, eventEditor, EventManager, annotationTooltipDirective }; diff --git a/public/app/features/annotations/components/StandardAnnotationQueryEditor.tsx b/public/app/features/annotations/components/StandardAnnotationQueryEditor.tsx index 9b85dd779a6..f0937dbdac3 100644 --- a/public/app/features/annotations/components/StandardAnnotationQueryEditor.tsx +++ b/public/app/features/annotations/components/StandardAnnotationQueryEditor.tsx @@ -7,7 +7,7 @@ import { Button, Icon, IconName, Spinner } from '@grafana/ui'; import { getDashboardSrv } from 'app/features/dashboard/services/DashboardSrv'; import { getTimeSrv } from 'app/features/dashboard/services/TimeSrv'; import { standardAnnotationSupport } from '../standardAnnotationSupport'; -import { executeAnnotationQuery } from '../annotations_srv'; +import { executeAnnotationQuery } from '../executeAnnotationQuery'; import { PanelModel } from 'app/features/dashboard/state'; import { AnnotationQueryResponse } from '../types'; import { AnnotationFieldMapper } from './AnnotationResultMapper'; diff --git a/public/app/features/annotations/specs/annotations_srv_specs.test.ts b/public/app/features/annotations/events_processing.test.ts similarity index 94% rename from public/app/features/annotations/specs/annotations_srv_specs.test.ts rename to public/app/features/annotations/events_processing.test.ts index 825b992938f..f8707fe8390 100644 --- a/public/app/features/annotations/specs/annotations_srv_specs.test.ts +++ b/public/app/features/annotations/events_processing.test.ts @@ -1,4 +1,4 @@ -import { dedupAnnotations } from '../events_processing'; +import { dedupAnnotations } from './events_processing'; describe('Annotations deduplication', () => { it('should remove duplicated annotations', () => { diff --git a/public/app/features/annotations/executeAnnotationQuery.ts b/public/app/features/annotations/executeAnnotationQuery.ts new file mode 100644 index 00000000000..3fe88217ad3 --- /dev/null +++ b/public/app/features/annotations/executeAnnotationQuery.ts @@ -0,0 +1,74 @@ +import { Observable, of } from 'rxjs'; +import { map, mergeMap } from 'rxjs/operators'; +import { CoreApp, DataQueryRequest, DataSourceApi, rangeUtil, ScopedVars } from '@grafana/data'; + +import { AnnotationQueryOptions, AnnotationQueryResponse } from './types'; +import { standardAnnotationSupport } from './standardAnnotationSupport'; +import { runRequest } from '../query/state/runRequest'; + +let counter = 100; +function getNextRequestId() { + return 'AQ' + counter++; +} + +export function executeAnnotationQuery( + options: AnnotationQueryOptions, + datasource: DataSourceApi, + savedJsonAnno: any +): Observable { + const processor = { + ...standardAnnotationSupport, + ...datasource.annotations, + }; + + const annotation = processor.prepareAnnotation!(savedJsonAnno); + if (!annotation) { + return of({}); + } + + const query = processor.prepareQuery!(annotation); + if (!query) { + return of({}); + } + + // No more points than pixels + const maxDataPoints = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth; + + // Add interval to annotation queries + const interval = rangeUtil.calculateInterval(options.range, maxDataPoints, datasource.interval); + + const scopedVars: ScopedVars = { + __interval: { text: interval.interval, value: interval.interval }, + __interval_ms: { text: interval.intervalMs.toString(), value: interval.intervalMs }, + __annotation: { text: annotation.name, value: annotation }, + }; + + const queryRequest: DataQueryRequest = { + startTime: Date.now(), + requestId: getNextRequestId(), + range: options.range, + maxDataPoints, + scopedVars, + ...interval, + app: CoreApp.Dashboard, + + timezone: options.dashboard.timezone, + + targets: [ + { + ...query, + refId: 'Anno', + }, + ], + }; + + return runRequest(datasource, queryRequest).pipe( + mergeMap((panelData) => { + if (!panelData.series) { + return of({ panelData, events: [] }); + } + + return processor.processEvents!(annotation, panelData.series).pipe(map((events) => ({ panelData, events }))); + }) + ); +} diff --git a/public/app/features/dashboard/components/PanelEditor/getFieldOverrideElements.tsx b/public/app/features/dashboard/components/PanelEditor/getFieldOverrideElements.tsx index bb108e9f4a8..9811f4e273e 100644 --- a/public/app/features/dashboard/components/PanelEditor/getFieldOverrideElements.tsx +++ b/public/app/features/dashboard/components/PanelEditor/getFieldOverrideElements.tsx @@ -14,7 +14,7 @@ import { OptionPaneRenderProps } from './types'; import { OptionsPaneItemDescriptor } from './OptionsPaneItemDescriptor'; import { OptionsPaneCategoryDescriptor } from './OptionsPaneCategoryDescriptor'; import { DynamicConfigValueEditor } from './DynamicConfigValueEditor'; -import { getDataLinksVariableSuggestions } from 'app/angular/panel/panellinks/link_srv'; +import { getDataLinksVariableSuggestions } from 'app/features/panel/panellinks/link_srv'; import { OverrideCategoryTitle } from './OverrideCategoryTitle'; import { css } from '@emotion/css'; diff --git a/public/app/features/dashboard/components/PanelEditor/getPanelFrameOptions.tsx b/public/app/features/dashboard/components/PanelEditor/getPanelFrameOptions.tsx index 0b4c6c1e417..5cd1e34348b 100644 --- a/public/app/features/dashboard/components/PanelEditor/getPanelFrameOptions.tsx +++ b/public/app/features/dashboard/components/PanelEditor/getPanelFrameOptions.tsx @@ -1,5 +1,5 @@ import { DataLinksInlineEditor, Input, RadioButtonGroup, Select, Switch, TextArea } from '@grafana/ui'; -import { getPanelLinksVariableSuggestions } from 'app/angular/panel/panellinks/link_srv'; +import { getPanelLinksVariableSuggestions } from 'app/features/panel/panellinks/link_srv'; import React from 'react'; import { RepeatRowSelect } from '../RepeatRowSelect/RepeatRowSelect'; import { OptionsPaneItemDescriptor } from './OptionsPaneItemDescriptor'; diff --git a/public/app/features/dashboard/components/PanelEditor/getVizualizationOptions.tsx b/public/app/features/dashboard/components/PanelEditor/getVizualizationOptions.tsx index 59b638b49cf..2a2a5ba2b58 100644 --- a/public/app/features/dashboard/components/PanelEditor/getVizualizationOptions.tsx +++ b/public/app/features/dashboard/components/PanelEditor/getVizualizationOptions.tsx @@ -1,7 +1,7 @@ import React from 'react'; import { StandardEditorContext, VariableSuggestionsScope } from '@grafana/data'; import { get as lodashGet } from 'lodash'; -import { getDataLinksVariableSuggestions } from 'app/angular/panel/panellinks/link_srv'; +import { getDataLinksVariableSuggestions } from 'app/features/panel/panellinks/link_srv'; import { OptionPaneRenderProps } from './types'; import { updateDefaultFieldConfigValue, setOptionImmutably } from './utils'; import { OptionsPaneItemDescriptor } from './OptionsPaneItemDescriptor'; diff --git a/public/app/features/dashboard/components/SubMenu/DashboardLinks.tsx b/public/app/features/dashboard/components/SubMenu/DashboardLinks.tsx index 0e9d8d0c00b..2cc9bd5b752 100644 --- a/public/app/features/dashboard/components/SubMenu/DashboardLinks.tsx +++ b/public/app/features/dashboard/components/SubMenu/DashboardLinks.tsx @@ -2,7 +2,7 @@ import React, { FC } from 'react'; import { Icon, IconName, Tooltip, useForceUpdate } from '@grafana/ui'; import { sanitizeUrl } from '@grafana/data/src/text/sanitize'; import { DashboardLinksDashboard } from './DashboardLinksDashboard'; -import { getLinkSrv } from '../../../../angular/panel/panellinks/link_srv'; +import { getLinkSrv } from '../../../panel/panellinks/link_srv'; import { DashboardModel } from '../../state'; import { DashboardLink } from '../../state/DashboardModel'; diff --git a/public/app/features/dashboard/components/SubMenu/DashboardLinksDashboard.tsx b/public/app/features/dashboard/components/SubMenu/DashboardLinksDashboard.tsx index a08c89e0734..203af35cf60 100644 --- a/public/app/features/dashboard/components/SubMenu/DashboardLinksDashboard.tsx +++ b/public/app/features/dashboard/components/SubMenu/DashboardLinksDashboard.tsx @@ -2,7 +2,7 @@ import React, { useRef, useState, useLayoutEffect } from 'react'; import { Icon, ToolbarButton, Tooltip, useStyles2 } from '@grafana/ui'; import { sanitize, sanitizeUrl } from '@grafana/data/src/text/sanitize'; import { getBackendSrv } from 'app/core/services/backend_srv'; -import { getLinkSrv } from '../../../../angular/panel/panellinks/link_srv'; +import { getLinkSrv } from '../../../panel/panellinks/link_srv'; import { DashboardLink } from '../../state/DashboardModel'; import { DashboardSearchHit } from 'app/features/search/types'; import { selectors } from '@grafana/e2e-selectors'; diff --git a/public/app/features/dashboard/components/VersionHistory/HistorySrv.ts b/public/app/features/dashboard/components/VersionHistory/HistorySrv.ts index 041df2fb9f2..5bcd302ffac 100644 --- a/public/app/features/dashboard/components/VersionHistory/HistorySrv.ts +++ b/public/app/features/dashboard/components/VersionHistory/HistorySrv.ts @@ -1,5 +1,4 @@ import { isNumber } from 'lodash'; -import coreModule from 'app/angular/core_module'; import { DashboardModel } from '../../state/DashboardModel'; import { getBackendSrv } from '@grafana/runtime'; @@ -45,5 +44,3 @@ export class HistorySrv { const historySrv = new HistorySrv(); export { historySrv }; - -coreModule.service('historySrv', HistorySrv); diff --git a/public/app/features/dashboard/dashgrid/PanelHeader/PanelHeader.tsx b/public/app/features/dashboard/dashgrid/PanelHeader/PanelHeader.tsx index f12fae773fb..a5f020a89a6 100644 --- a/public/app/features/dashboard/dashgrid/PanelHeader/PanelHeader.tsx +++ b/public/app/features/dashboard/dashgrid/PanelHeader/PanelHeader.tsx @@ -7,7 +7,7 @@ import { selectors } from '@grafana/e2e-selectors'; import PanelHeaderCorner from './PanelHeaderCorner'; import { DashboardModel } from 'app/features/dashboard/state/DashboardModel'; import { PanelModel } from 'app/features/dashboard/state/PanelModel'; -import { getPanelLinksSupplier } from 'app/angular/panel/panellinks/linkSuppliers'; +import { getPanelLinksSupplier } from 'app/features/panel/panellinks/linkSuppliers'; import { PanelHeaderNotices } from './PanelHeaderNotices'; import { PanelHeaderMenuTrigger } from './PanelHeaderMenuTrigger'; import { PanelHeaderLoadingIndicator } from './PanelHeaderLoadingIndicator'; diff --git a/public/app/features/dashboard/services/DashboardSrv.ts b/public/app/features/dashboard/services/DashboardSrv.ts index 7d07ce0d9ea..2341977103f 100644 --- a/public/app/features/dashboard/services/DashboardSrv.ts +++ b/public/app/features/dashboard/services/DashboardSrv.ts @@ -1,4 +1,3 @@ -import coreModule from 'app/angular/core_module'; import { appEvents } from 'app/core/app_events'; import { DashboardModel } from '../state/DashboardModel'; import { removePanel } from '../utils/panel'; @@ -67,8 +66,6 @@ export class DashboardSrv { } } -coreModule.service('dashboardSrv', DashboardSrv); - // // Code below is to export the service to React components // @@ -80,5 +77,8 @@ export function setDashboardSrv(instance: DashboardSrv) { } export function getDashboardSrv(): DashboardSrv { + if (!singletonInstance) { + singletonInstance = new DashboardSrv(); + } return singletonInstance; } diff --git a/public/app/features/explore/TraceView/createSpanLink.test.ts b/public/app/features/explore/TraceView/createSpanLink.test.ts index efd1a760bea..253f16a7b6d 100644 --- a/public/app/features/explore/TraceView/createSpanLink.test.ts +++ b/public/app/features/explore/TraceView/createSpanLink.test.ts @@ -3,7 +3,7 @@ import { setDataSourceSrv, setTemplateSrv } from '@grafana/runtime'; import { createSpanLinkFactory } from './createSpanLink'; import { TraceSpan } from '@jaegertracing/jaeger-ui-components'; import { TraceToLogsOptions } from '../../../core/components/TraceToLogsSettings'; -import { LinkSrv, setLinkSrv } from '../../../angular/panel/panellinks/link_srv'; +import { LinkSrv, setLinkSrv } from '../../panel/panellinks/link_srv'; import { TemplateSrv } from '../../templating/template_srv'; describe('createSpanLinkFactory', () => { diff --git a/public/app/features/explore/utils/links.test.ts b/public/app/features/explore/utils/links.test.ts index 846f0e245af..dec2bf3f9ed 100644 --- a/public/app/features/explore/utils/links.test.ts +++ b/public/app/features/explore/utils/links.test.ts @@ -9,7 +9,7 @@ import { LinkModel, TimeRange, } from '@grafana/data'; -import { setLinkSrv } from '../../../angular/panel/panellinks/link_srv'; +import { setLinkSrv } from '../../panel/panellinks/link_srv'; import { setContextSrv } from '../../../core/services/context_srv'; describe('getFieldLinksForExplore', () => { diff --git a/public/app/features/explore/utils/links.ts b/public/app/features/explore/utils/links.ts index 48b7621150f..c3aabab2a51 100644 --- a/public/app/features/explore/utils/links.ts +++ b/public/app/features/explore/utils/links.ts @@ -11,7 +11,7 @@ import { SplitOpen, } from '@grafana/data'; import { getTemplateSrv } from '@grafana/runtime'; -import { getLinkSrv } from '../../../angular/panel/panellinks/link_srv'; +import { getLinkSrv } from '../../panel/panellinks/link_srv'; import { contextSrv } from 'app/core/services/context_srv'; /** diff --git a/public/app/angular/panel/panellinks/linkSuppliers.test.ts b/public/app/features/panel/panellinks/linkSuppliers.test.ts similarity index 98% rename from public/app/angular/panel/panellinks/linkSuppliers.test.ts rename to public/app/features/panel/panellinks/linkSuppliers.test.ts index 961aaee01c0..69f44e4af14 100644 --- a/public/app/angular/panel/panellinks/linkSuppliers.test.ts +++ b/public/app/features/panel/panellinks/linkSuppliers.test.ts @@ -1,7 +1,7 @@ import { getFieldLinksSupplier } from './linkSuppliers'; import { applyFieldOverrides, createTheme, DataFrameView, dateTime, FieldDisplay, toDataFrame } from '@grafana/data'; import { getLinkSrv, LinkService, LinkSrv, setLinkSrv } from './link_srv'; -import { TemplateSrv } from '../../../features/templating/template_srv'; +import { TemplateSrv } from '../../templating/template_srv'; // We do not need more here and TimeSrv is hard to setup fully. jest.mock('app/features/dashboard/services/TimeSrv', () => ({ diff --git a/public/app/angular/panel/panellinks/linkSuppliers.ts b/public/app/features/panel/panellinks/linkSuppliers.ts similarity index 100% rename from public/app/angular/panel/panellinks/linkSuppliers.ts rename to public/app/features/panel/panellinks/linkSuppliers.ts diff --git a/public/app/angular/panel/panellinks/link_srv.ts b/public/app/features/panel/panellinks/link_srv.ts similarity index 92% rename from public/app/angular/panel/panellinks/link_srv.ts rename to public/app/features/panel/panellinks/link_srv.ts index f353497e066..a803bd8ec0f 100644 --- a/public/app/angular/panel/panellinks/link_srv.ts +++ b/public/app/features/panel/panellinks/link_srv.ts @@ -1,7 +1,6 @@ import { chain } from 'lodash'; import { getTimeSrv } from 'app/features/dashboard/services/TimeSrv'; import { getTemplateSrv } from '@grafana/runtime'; -import coreModule from 'app/angular/core_module'; import { getConfig } from 'app/core/config'; import { DataFrame, @@ -15,7 +14,6 @@ import { KeyValue, LinkModel, locationUtil, - PanelPlugin, ScopedVars, textUtil, urlUtil, @@ -23,7 +21,7 @@ import { VariableSuggestion, VariableSuggestionsScope, } from '@grafana/data'; -import { getVariablesUrlParams } from '../../../features/variables/getAllVariableValuesForUrl'; +import { getVariablesUrlParams } from '../../variables/getAllVariableValuesForUrl'; const timeRangeVars = [ { @@ -242,20 +240,6 @@ export const getCalculationValueDataLinksVariableSuggestions = (dataFrames: Data return [...seriesVars, ...fieldVars, ...valueVars, valueCalcVar, ...getPanelLinksVariableSuggestions()]; }; -export const getPanelOptionsVariableSuggestions = (plugin: PanelPlugin, data?: DataFrame[]): VariableSuggestion[] => { - const dataVariables = plugin.meta.skipDataQuery ? [] : getDataFrameVars(data || []); - return [ - ...dataVariables, // field values - ...getTemplateSrv() - .getVariables() - .map((variable) => ({ - value: variable.name as string, - label: variable.name, - origin: VariableOrigin.Template, - })), - ]; -}; - export interface LinkService { getDataLinkUIModel: (link: DataLink, replaceVariables: InterpolateFunction | undefined, origin: T) => LinkModel; getAnchorInfo: (link: any) => any; @@ -263,8 +247,6 @@ export interface LinkService { } export class LinkSrv implements LinkService { - constructor() {} - getLinkUrl(link: any) { let url = locationUtil.assureBaseUrl(getTemplateSrv().replace(link.url || '')); let params: { [key: string]: any } = {}; @@ -353,14 +335,15 @@ export class LinkSrv implements LinkService { } } -let singleton: LinkService; +let singleton: LinkService | undefined; export function setLinkSrv(srv: LinkService) { singleton = srv; } export function getLinkSrv(): LinkService { + if (!singleton) { + singleton = new LinkSrv(); + } return singleton; } - -coreModule.service('linkSrv', LinkSrv); diff --git a/public/app/angular/panel/panellinks/specs/link_srv.test.ts b/public/app/features/panel/panellinks/specs/link_srv.test.ts similarity index 100% rename from public/app/angular/panel/panellinks/specs/link_srv.test.ts rename to public/app/features/panel/panellinks/specs/link_srv.test.ts diff --git a/public/app/features/plugins/datasource_srv.ts b/public/app/features/plugins/datasource_srv.ts index d027a554558..5d572a3d57b 100644 --- a/public/app/features/plugins/datasource_srv.ts +++ b/public/app/features/plugins/datasource_srv.ts @@ -1,5 +1,3 @@ -// Libraries -import coreModule from 'app/angular/core_module'; // Services & Utils import { importDataSourcePlugin } from './plugin_loader'; import { @@ -7,6 +5,7 @@ import { DataSourceSrv as DataSourceService, getDataSourceSrv as getDataSourceService, TemplateSrv, + getTemplateSrv, } from '@grafana/runtime'; // Types import { @@ -17,8 +16,6 @@ import { DataSourceSelectItem, ScopedVars, } from '@grafana/data'; -import { auto } from 'angular'; -import { GrafanaRootScope } from 'app/routes/GrafanaCtrl'; // Pretend Datasource import { dataSource as expressionDatasource, @@ -27,6 +24,8 @@ import { } from 'app/features/expressions/ExpressionDatasource'; import { DataSourceVariableModel } from '../variables/types'; import { ExpressionDatasourceRef } from '@grafana/runtime/src/utils/DataSourceWithBackend'; +import appEvents from 'app/core/app_events'; +import { getAngularInjector } from 'app/angular/lazyBootAngular'; export class DatasourceSrv implements DataSourceService { private datasources: Record = {}; // UID @@ -35,12 +34,7 @@ export class DatasourceSrv implements DataSourceService { private settingsMapById: Record = {}; private defaultName = ''; // actually UID - /** @ngInject */ - constructor( - private $injector: auto.IInjectorService, - private $rootScope: GrafanaRootScope, - private templateSrv: TemplateSrv - ) {} + constructor(private templateSrv: TemplateSrv = getTemplateSrv()) {} init(settingsMapByName: Record, defaultName: string) { this.datasources = {}; @@ -164,11 +158,15 @@ export class DatasourceSrv implements DataSourceService { // If there is only one constructor argument it is instanceSettings const useAngular = dsPlugin.DataSourceClass.length !== 1; - const instance: DataSourceApi = useAngular - ? this.$injector.instantiate(dsPlugin.DataSourceClass, { - instanceSettings: dsConfig, - }) - : new dsPlugin.DataSourceClass(dsConfig); + let instance: DataSourceApi; + + if (useAngular) { + instance = (await getAngularInjector()).instantiate(dsPlugin.DataSourceClass, { + instanceSettings: dsConfig, + }); + } else { + instance = new dsPlugin.DataSourceClass(dsConfig); + } instance.components = dsPlugin.components; instance.meta = dsConfig.meta; @@ -178,9 +176,7 @@ export class DatasourceSrv implements DataSourceService { this.datasources[instance.uid] = instance; return instance; } catch (err) { - if (this.$rootScope) { - this.$rootScope.appEvent(AppEvents.alertError, [dsConfig.name + ' plugin failed', err.toString()]); - } + appEvents.emit(AppEvents.alertError, [dsConfig.name + ' plugin failed', err.toString()]); return Promise.reject({ message: `Datasource: ${key} was not found` }); } } @@ -321,5 +317,4 @@ export const getDatasourceSrv = (): DatasourceSrv => { return getDataSourceService() as DatasourceSrv; }; -coreModule.service('datasourceSrv', DatasourceSrv); export default DatasourceSrv; diff --git a/public/app/features/plugins/plugin_component.ts b/public/app/features/plugins/plugin_component.ts index b66ec7c1c4a..6567a737b0f 100644 --- a/public/app/features/plugins/plugin_component.ts +++ b/public/app/features/plugins/plugin_component.ts @@ -8,7 +8,7 @@ import { DataSourceApi, PanelEvents } from '@grafana/data'; import { importDataSourcePlugin, importAppPlugin } from './plugin_loader'; import { importPanelPlugin } from './importPanelPlugin'; import DatasourceSrv from './datasource_srv'; -import { GrafanaRootScope } from 'app/routes/GrafanaCtrl'; +import { GrafanaRootScope } from 'app/angular/GrafanaCtrl'; /** @ngInject */ function pluginDirectiveLoader( diff --git a/public/app/features/plugins/plugin_page_ctrl.ts b/public/app/features/plugins/plugin_page_ctrl.ts index 2d68f3b4d9e..34bb136c148 100644 --- a/public/app/features/plugins/plugin_page_ctrl.ts +++ b/public/app/features/plugins/plugin_page_ctrl.ts @@ -3,7 +3,7 @@ import { find } from 'lodash'; import { getPluginSettings } from './PluginSettingsCache'; import { PluginMeta, AppEvents } from '@grafana/data'; -import { GrafanaRootScope } from 'app/routes/GrafanaCtrl'; +import { GrafanaRootScope } from 'app/angular/GrafanaCtrl'; import { promiseToDigest } from '../../angular/promiseToDigest'; import { NavModelSrv } from 'app/angular/services/nav_model_srv'; diff --git a/public/app/features/plugins/specs/datasource_srv.test.ts b/public/app/features/plugins/specs/datasource_srv.test.ts index 81eaf5442e6..f13d2dcf01e 100644 --- a/public/app/features/plugins/specs/datasource_srv.test.ts +++ b/public/app/features/plugins/specs/datasource_srv.test.ts @@ -37,7 +37,7 @@ jest.mock('../plugin_loader', () => ({ })); describe('datasource_srv', () => { - const dataSourceSrv = new DatasourceSrv({} as any, {} as any, templateSrv); + const dataSourceSrv = new DatasourceSrv(templateSrv); const dataSourceInit = { mmm: { type: 'test-db', diff --git a/public/app/features/query/state/DashboardQueryRunner/AnnotationsQueryRunner.test.ts b/public/app/features/query/state/DashboardQueryRunner/AnnotationsQueryRunner.test.ts index 945e1b42a32..220363dde2f 100644 --- a/public/app/features/query/state/DashboardQueryRunner/AnnotationsQueryRunner.test.ts +++ b/public/app/features/query/state/DashboardQueryRunner/AnnotationsQueryRunner.test.ts @@ -4,7 +4,7 @@ import { AnnotationsQueryRunner } from './AnnotationsQueryRunner'; import { AnnotationQueryRunnerOptions } from './types'; import { silenceConsoleOutput } from '../../../../../test/core/utils/silenceConsoleOutput'; import * as store from '../../../../store/store'; -import * as annotationsSrv from '../../../annotations/annotations_srv'; +import * as annotationsSrv from '../../../annotations/executeAnnotationQuery'; import { Observable, of, throwError } from 'rxjs'; import { toAsyncOfResult } from './testHelpers'; diff --git a/public/app/features/query/state/DashboardQueryRunner/AnnotationsQueryRunner.ts b/public/app/features/query/state/DashboardQueryRunner/AnnotationsQueryRunner.ts index 919399ce886..36592258f7d 100644 --- a/public/app/features/query/state/DashboardQueryRunner/AnnotationsQueryRunner.ts +++ b/public/app/features/query/state/DashboardQueryRunner/AnnotationsQueryRunner.ts @@ -4,7 +4,7 @@ import { AnnotationEvent, DataSourceApi } from '@grafana/data'; import { AnnotationQueryRunner, AnnotationQueryRunnerOptions } from './types'; import { PanelModel } from '../../../dashboard/state'; -import { executeAnnotationQuery } from '../../../annotations/annotations_srv'; +import { executeAnnotationQuery } from '../../../annotations/executeAnnotationQuery'; import { handleAnnotationQueryRunnerError } from './utils'; export class AnnotationsQueryRunner implements AnnotationQueryRunner { diff --git a/public/app/features/query/state/DashboardQueryRunner/AnnotationsWorker.test.ts b/public/app/features/query/state/DashboardQueryRunner/AnnotationsWorker.test.ts index 169a4e7994a..daf7bc5dba1 100644 --- a/public/app/features/query/state/DashboardQueryRunner/AnnotationsWorker.test.ts +++ b/public/app/features/query/state/DashboardQueryRunner/AnnotationsWorker.test.ts @@ -2,7 +2,7 @@ import { Subject, throwError } from 'rxjs'; import { setDataSourceSrv } from '@grafana/runtime'; import { AnnotationsWorker } from './AnnotationsWorker'; -import * as annotationsSrv from '../../../annotations/annotations_srv'; +import * as annotationsSrv from '../../../annotations/executeAnnotationQuery'; import { getDefaultOptions, LEGACY_DS_NAME, NEXT_GEN_DS_NAME, toAsyncOfResult } from './testHelpers'; import { silenceConsoleOutput } from '../../../../../test/core/utils/silenceConsoleOutput'; import { createDashboardQueryRunner, setDashboardQueryRunnerFactory } from './DashboardQueryRunner'; diff --git a/public/app/features/query/state/DashboardQueryRunner/DashboardQueryRunner.test.ts b/public/app/features/query/state/DashboardQueryRunner/DashboardQueryRunner.test.ts index 9f8b3a1ae7c..4875bbe6dd3 100644 --- a/public/app/features/query/state/DashboardQueryRunner/DashboardQueryRunner.test.ts +++ b/public/app/features/query/state/DashboardQueryRunner/DashboardQueryRunner.test.ts @@ -3,7 +3,7 @@ import { delay } from 'rxjs/operators'; import { setDataSourceSrv } from '@grafana/runtime'; import { AlertState, AlertStateInfo } from '@grafana/data'; -import * as annotationsSrv from '../../../annotations/annotations_srv'; +import * as annotationsSrv from '../../../annotations/executeAnnotationQuery'; import { getDefaultOptions, LEGACY_DS_NAME, NEXT_GEN_DS_NAME, toAsyncOfResult } from './testHelpers'; import { backendSrv } from '../../../../core/services/backend_srv'; import { DashboardQueryRunner, DashboardQueryRunnerResult } from './types'; diff --git a/public/app/plugins/datasource/loki/configuration/DebugSection.test.tsx b/public/app/plugins/datasource/loki/configuration/DebugSection.test.tsx index 1d71a9dc933..177eb167481 100644 --- a/public/app/plugins/datasource/loki/configuration/DebugSection.test.tsx +++ b/public/app/plugins/datasource/loki/configuration/DebugSection.test.tsx @@ -1,7 +1,7 @@ import React from 'react'; import { DebugSection } from './DebugSection'; import { mount } from 'enzyme'; -import { getLinkSrv, LinkService, LinkSrv, setLinkSrv } from '../../../../angular/panel/panellinks/link_srv'; +import { getLinkSrv, LinkService, LinkSrv, setLinkSrv } from '../../../../features/panel/panellinks/link_srv'; import { dateTime } from '@grafana/data'; // We do not need more here and TimeSrv is hard to setup fully. diff --git a/public/app/features/annotations/annotation_tooltip.ts b/public/app/plugins/panel/graph/annotation_tooltip.ts similarity index 95% rename from public/app/features/annotations/annotation_tooltip.ts rename to public/app/plugins/panel/graph/annotation_tooltip.ts index cef5ff43aa6..ce7d8b6af81 100644 --- a/public/app/features/annotations/annotation_tooltip.ts +++ b/public/app/plugins/panel/graph/annotation_tooltip.ts @@ -1,8 +1,8 @@ import { isString, escape } from 'lodash'; import $ from 'jquery'; import coreModule from 'app/angular/core_module'; -import alertDef from '../alerting/state/alertDef'; -import { DashboardSrv } from '../dashboard/services/DashboardSrv'; +import alertDef from 'app/features/alerting/state/alertDef'; +import { DashboardSrv } from 'app/features/dashboard/services/DashboardSrv'; import { ContextSrv } from 'app/core/services/context_srv'; /** @ngInject */ diff --git a/public/app/features/annotations/event_editor.ts b/public/app/plugins/panel/graph/event_editor.ts similarity index 94% rename from public/app/features/annotations/event_editor.ts rename to public/app/plugins/panel/graph/event_editor.ts index 580b48488cf..a02ef28e89d 100644 --- a/public/app/features/annotations/event_editor.ts +++ b/public/app/plugins/panel/graph/event_editor.ts @@ -2,8 +2,8 @@ import { cloneDeep, isNumber } from 'lodash'; import { coreModule } from 'app/angular/core_module'; import { AnnotationEvent, dateTime } from '@grafana/data'; import { MetricsPanelCtrl } from 'app/angular/panel/metrics_panel_ctrl'; -import { deleteAnnotation, saveAnnotation, updateAnnotation } from './api'; -import { getDashboardQueryRunner } from '../query/state/DashboardQueryRunner/DashboardQueryRunner'; +import { deleteAnnotation, saveAnnotation, updateAnnotation } from '../../../features/annotations/api'; +import { getDashboardQueryRunner } from '../../../features/query/state/DashboardQueryRunner/DashboardQueryRunner'; export class EventEditorCtrl { // @ts-ignore initialized through Angular not constructor diff --git a/public/app/features/annotations/event_manager.ts b/public/app/plugins/panel/graph/event_manager.ts similarity index 100% rename from public/app/features/annotations/event_manager.ts rename to public/app/plugins/panel/graph/event_manager.ts diff --git a/public/app/plugins/panel/graph/graph.ts b/public/app/plugins/panel/graph/graph.ts index 2f445549f39..55692cf35be 100644 --- a/public/app/plugins/panel/graph/graph.ts +++ b/public/app/plugins/panel/graph/graph.ts @@ -16,7 +16,7 @@ import { coreModule } from 'app/angular/core_module'; import GraphTooltip from './graph_tooltip'; import { ThresholdManager } from './threshold_manager'; import { TimeRegionManager } from './time_region_manager'; -import { EventManager } from 'app/features/annotations/all'; +import { EventManager } from './event_manager'; import { convertToHistogramData } from './histogram'; import { alignYLevel } from './align_yaxes'; import config from 'app/core/config'; @@ -52,7 +52,7 @@ import { import { GraphContextMenuCtrl } from './GraphContextMenuCtrl'; import { TimeSrv } from 'app/features/dashboard/services/TimeSrv'; import { ContextSrv } from 'app/core/services/context_srv'; -import { getFieldLinksSupplier } from 'app/angular/panel/panellinks/linkSuppliers'; +import { getFieldLinksSupplier } from 'app/features/panel/panellinks/linkSuppliers'; import { DashboardModel } from '../../../features/dashboard/state'; import { isLegacyGraphHoverEvent } from './utils'; diff --git a/public/app/plugins/panel/graph/module.ts b/public/app/plugins/panel/graph/module.ts index 896e290a319..2e0a408eed5 100644 --- a/public/app/plugins/panel/graph/module.ts +++ b/public/app/plugins/panel/graph/module.ts @@ -2,6 +2,8 @@ import './graph'; import './series_overrides_ctrl'; import './thresholds_form'; import './time_regions_form'; +import './annotation_tooltip'; +import './event_editor'; import template from './template'; import { defaults, find, without } from 'lodash'; diff --git a/public/app/plugins/panel/graph/specs/graph.test.ts b/public/app/plugins/panel/graph/specs/graph.test.ts index 8334afff4f0..105b1c47769 100644 --- a/public/app/plugins/panel/graph/specs/graph.test.ts +++ b/public/app/plugins/panel/graph/specs/graph.test.ts @@ -9,7 +9,7 @@ import { graphDirective, GraphElement } from '../graph'; import { dateTime, EventBusSrv } from '@grafana/data'; import { DashboardModel } from '../../../../features/dashboard/state'; -jest.mock('app/features/annotations/all', () => ({ +jest.mock('../event_manager', () => ({ EventManager: () => { return { on: () => {}, diff --git a/public/test/specs/helpers.ts b/public/test/specs/helpers.ts index f2d3b2bf7f7..6be980a8c18 100644 --- a/public/test/specs/helpers.ts +++ b/public/test/specs/helpers.ts @@ -4,7 +4,7 @@ import config from 'app/core/config'; import { angularMocks, sinon } from '../lib/common'; import { PanelModel } from 'app/features/dashboard/state/PanelModel'; import { RawTimeRange, PanelPluginMeta, dateMath } from '@grafana/data'; -import { GrafanaRootScope } from 'app/routes/GrafanaCtrl'; +import { GrafanaRootScope } from 'app/angular/GrafanaCtrl'; export function ControllerTestContext(this: any) { const self = this;