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 <[email protected]>
  • Loading branch information
abbyhu2000 committed Nov 28, 2022
1 parent 82b49a8 commit e1305e3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 31 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 @@ -58,7 +58,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
59 changes: 30 additions & 29 deletions src/plugins/vis_builder/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,36 +74,8 @@ export class VisBuilderPlugin

public setup(
core: CoreSetup<VisBuilderPluginStartDependencies, VisBuilderStart>,
{ embeddable, visualizations, data: dataSetup }: VisBuilderPluginSetupDependencies
{ embeddable, visualizations }: VisBuilderPluginSetupDependencies
) {
const { appMounted, appUnMounted, stop: stopUrlTracker } = createOsdUrlTracker({
baseUrl: core.http.basePath.prepend(`/app/${PLUGIN_ID}`),
defaultSubUrl: '#/',
storageKey: `lastUrl:${core.http.basePath.get()}:${PLUGIN_ID}`,
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 @@ -123,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 e1305e3

Please sign in to comment.