From 03d5a210b747334c48f794a280a40690284dabde Mon Sep 17 00:00:00 2001 From: abbyhu2000 Date: Wed, 30 Nov 2022 22:49:08 +0000 Subject: [PATCH] Move osdUrlTracker out of mount Move osdUrlTracker to its original location, and replace data dependency with pluginsStart.data Signed-off-by: abbyhu2000 --- src/plugins/vis_builder/public/plugin.ts | 69 ++++++++++++------------ src/plugins/vis_builder/public/types.ts | 2 - 2 files changed, 33 insertions(+), 38 deletions(-) diff --git a/src/plugins/vis_builder/public/plugin.ts b/src/plugins/vis_builder/public/plugin.ts index c4b01a8e7fc4..15a3cc74e6cf 100644 --- a/src/plugins/vis_builder/public/plugin.ts +++ b/src/plugins/vis_builder/public/plugin.ts @@ -74,8 +74,36 @@ export class VisBuilderPlugin public setup( core: CoreSetup, - { embeddable, visualizations }: VisBuilderPluginSetupDependencies + { embeddable, visualizations, data }: VisBuilderPluginSetupDependencies ) { + const { appMounted, appUnMounted, stop: stopUrlTracker } = createOsdUrlTracker({ + baseUrl: core.http.basePath.prepend('/app/vis-builder'), + defaultSubUrl: '#/', + storageKey: `lastUrl:${core.http.basePath.get()}:vis-builder`, + navLinkUpdater$: this.appStateUpdater, + toastNotifications: core.notifications.toasts, + stateParams: [ + { + osdUrlKey: '_g', + stateUpdate$: data.query.state$.pipe( + filter( + ({ changes }) => !!(changes.globalFilters || changes.time || changes.refreshInterval) + ), + map(({ state }) => ({ + ...state, + filters: state.filters?.filter(opensearchFilters.isFilterPinned), + })) + ), + }, + ], + getHistory: () => { + return this.currentHistory!; + }, + }); + this.stopUrlTracking = () => { + stopUrlTracker(); + }; + // Register Default Visualizations const typeService = this.typeService; registerDefaultTypes(typeService.setup()); @@ -92,40 +120,11 @@ export class VisBuilderPlugin // Get start services as specified in opensearch_dashboards.json const [coreStart, pluginsStart, selfStart] = await core.getStartServices(); - const { data, savedObjects, navigation, expressions } = pluginsStart; + const { savedObjects, navigation, expressions } = pluginsStart; this.currentHistory = params.history; - const { appMounted, appUnMounted, stop: stopUrlTracker } = createOsdUrlTracker({ - baseUrl: core.http.basePath.prepend('/app/vis-builder'), - defaultSubUrl: '#/', - storageKey: `lastUrl:${core.http.basePath.get()}:vis-builder`, - navLinkUpdater$: this.appStateUpdater, - toastNotifications: core.notifications.toasts, - stateParams: [ - { - osdUrlKey: '_g', - stateUpdate$: data.query.state$.pipe( - filter( - ({ changes }) => - !!(changes.globalFilters || changes.time || changes.refreshInterval) - ), - map(({ state }) => ({ - ...state, - filters: state.filters?.filter(opensearchFilters.isFilterPinned), - })) - ), - }, - ], - getHistory: () => { - return this.currentHistory!; - }, - }); - this.stopUrlTracking = () => { - stopUrlTracker(); - }; - // make sure the index pattern list is up to date - data.indexPatterns.clearCache(); + pluginsStart.data.indexPatterns.clearCache(); // make sure a default index pattern exists // if not, the page will be redirected to management and visualize won't be rendered // TODO: Add the redirect @@ -150,7 +149,7 @@ export class VisBuilderPlugin ...withNotifyOnErrors(coreStart.notifications.toasts), }), toastNotifications: coreStart.notifications.toasts, - data, + data: pluginsStart.data, savedObjectsPublic: savedObjects, navigation, expressions, @@ -158,8 +157,6 @@ export class VisBuilderPlugin types: typeService.start(), savedVisBuilderLoader: selfStart.savedVisBuilderLoader, embeddable: pluginsStart.embeddable, - setActiveUrl, - restorePreviousUrl, dashboard: pluginsStart.dashboard, }; @@ -220,7 +217,7 @@ export class VisBuilderPlugin public start( core: CoreStart, - { data, expressions }: VisBuilderPluginStartDependencies + { expressions, data }: VisBuilderPluginStartDependencies ): VisBuilderStart { const typeService = this.typeService.start(); diff --git a/src/plugins/vis_builder/public/types.ts b/src/plugins/vis_builder/public/types.ts index 5780702be9cf..e73e279e05a9 100644 --- a/src/plugins/vis_builder/public/types.ts +++ b/src/plugins/vis_builder/public/types.ts @@ -50,8 +50,6 @@ export interface VisBuilderServices extends CoreStart { embeddable: EmbeddableStart; scopedHistory: ScopedHistory; osdUrlStateStorage: IOsdUrlStateStorage; - setActiveUrl: (newUrl: string) => void; - restorePreviousUrl: () => void; dashboard: DashboardStart; }