Skip to content

Commit

Permalink
Move osdUrlTracker out of mount
Browse files Browse the repository at this point in the history
Move osdUrlTracker to its original location, and replace data dependency with pluginsStart.data

Signed-off-by: abbyhu2000 <abigailhu2000@gmail.com>
  • Loading branch information
abbyhu2000 committed Dec 1, 2022
1 parent f273396 commit 03d5a21
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 38 deletions.
69 changes: 33 additions & 36 deletions src/plugins/vis_builder/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,36 @@ export class VisBuilderPlugin

public setup(
core: CoreSetup<VisBuilderPluginStartDependencies, VisBuilderStart>,
{ 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());
Expand All @@ -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
Expand All @@ -150,16 +149,14 @@ export class VisBuilderPlugin
...withNotifyOnErrors(coreStart.notifications.toasts),
}),
toastNotifications: coreStart.notifications.toasts,
data,
data: pluginsStart.data,
savedObjectsPublic: savedObjects,
navigation,
expressions,
setHeaderActionMenu: params.setHeaderActionMenu,
types: typeService.start(),
savedVisBuilderLoader: selfStart.savedVisBuilderLoader,
embeddable: pluginsStart.embeddable,
setActiveUrl,
restorePreviousUrl,
dashboard: pluginsStart.dashboard,
};

Expand Down Expand Up @@ -220,7 +217,7 @@ export class VisBuilderPlugin

public start(
core: CoreStart,
{ data, expressions }: VisBuilderPluginStartDependencies
{ expressions, data }: VisBuilderPluginStartDependencies
): VisBuilderStart {
const typeService = this.typeService.start();

Expand Down
2 changes: 0 additions & 2 deletions src/plugins/vis_builder/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ export interface VisBuilderServices extends CoreStart {
embeddable: EmbeddableStart;
scopedHistory: ScopedHistory;
osdUrlStateStorage: IOsdUrlStateStorage;
setActiveUrl: (newUrl: string) => void;
restorePreviousUrl: () => void;
dashboard: DashboardStart;
}

Expand Down

0 comments on commit 03d5a21

Please sign in to comment.