Skip to content

Commit

Permalink
move createOsdUrlTracker in mount function
Browse files Browse the repository at this point in the history
Signed-off-by: abbyhu2000 <abigailhu2000@gmail.com>
  • Loading branch information
abbyhu2000 committed Dec 1, 2022
1 parent 6bcdd0c commit f273396
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface MetadataState {
};
state: EditorState;
};
originatingApp: string | undefined;
originatingApp?: string;
}

const initialState: MetadataState = {
Expand Down Expand Up @@ -52,7 +52,7 @@ export const slice = createSlice({
setEditorState: (state, action: PayloadAction<{ state: EditorState }>) => {
state.editor.state = action.payload.state;
},
setOriginatingApp: (state, action: PayloadAction<{ state: string | undefined }>) => {
setOriginatingApp: (state, action: PayloadAction<{ state?: string }>) => {
state.originatingApp = action.payload.state;
},
setState: (_state, action: PayloadAction<MetadataState>) => {
Expand Down
66 changes: 31 additions & 35 deletions src/plugins/vis_builder/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,42 +74,9 @@ export class VisBuilderPlugin

public setup(
core: CoreSetup<VisBuilderPluginStartDependencies, VisBuilderStart>,
{ embeddable, visualizations, data: dataSetup }: VisBuilderPluginSetupDependencies
{ embeddable, visualizations }: VisBuilderPluginSetupDependencies
) {
const {
appMounted,
appUnMounted,
stop: stopUrlTracker,
setActiveUrl,
restorePreviousUrl,
} = 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$: dataSetup.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 @@ -128,6 +95,35 @@ export class VisBuilderPlugin
const { data, 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();
// make sure a default index pattern exists
Expand Down

0 comments on commit f273396

Please sign in to comment.