From 599dbda8a38213993214a803e01c6f9c35e607c8 Mon Sep 17 00:00:00 2001 From: abbyhu2000 Date: Fri, 2 Dec 2022 19:13:48 +0000 Subject: [PATCH] resolve comments Signed-off-by: abbyhu2000 --- .../application/utils/get_top_nav_config.tsx | 2 +- .../utils/state_management/metadata_slice.ts | 8 +++++++- .../application/utils/state_management/store.ts | 7 +------ src/plugins/vis_builder/public/plugin.ts | 17 ++++++++--------- src/plugins/vis_builder/public/types.ts | 1 - yarn.lock | 5 ----- 6 files changed, 17 insertions(+), 23 deletions(-) diff --git a/src/plugins/vis_builder/public/application/utils/get_top_nav_config.tsx b/src/plugins/vis_builder/public/application/utils/get_top_nav_config.tsx index 0d1ca409bcca..9df321822852 100644 --- a/src/plugins/vis_builder/public/application/utils/get_top_nav_config.tsx +++ b/src/plugins/vis_builder/public/application/utils/get_top_nav_config.tsx @@ -46,7 +46,7 @@ export interface TopNavConfigParams { savedVisBuilderVis: VisBuilderVisSavedObject; saveDisabledReason?: string; dispatch: AppDispatch; - originatingApp: string | undefined; + originatingApp?: string; } export const getTopNavConfig = ( diff --git a/src/plugins/vis_builder/public/application/utils/state_management/metadata_slice.ts b/src/plugins/vis_builder/public/application/utils/state_management/metadata_slice.ts index fc73f22b173d..c1e23b52823d 100644 --- a/src/plugins/vis_builder/public/application/utils/state_management/metadata_slice.ts +++ b/src/plugins/vis_builder/public/application/utils/state_management/metadata_slice.ts @@ -35,8 +35,14 @@ const initialState: MetadataState = { export const getPreloadedState = async ({ types, data, + embeddable, + scopedHistory, }: VisBuilderServices): Promise => { - const preloadedState = { ...initialState }; + const { originatingApp } = + embeddable + .getStateTransfer(scopedHistory) + .getIncomingEditorState({ keysToRemoveAfterFetch: ['id', 'input'] }) || {}; + const preloadedState = { ...initialState, originatingApp }; return preloadedState; }; diff --git a/src/plugins/vis_builder/public/application/utils/state_management/store.ts b/src/plugins/vis_builder/public/application/utils/state_management/store.ts index ff54c0dbb94f..f02fc5e946dd 100644 --- a/src/plugins/vis_builder/public/application/utils/state_management/store.ts +++ b/src/plugins/vis_builder/public/application/utils/state_management/store.ts @@ -6,7 +6,7 @@ import { combineReducers, configureStore, PreloadedState } from '@reduxjs/toolkit'; import { reducer as styleReducer } from './style_slice'; import { reducer as visualizationReducer } from './visualization_slice'; -import { reducer as metadataReducer, setOriginatingApp } from './metadata_slice'; +import { reducer as metadataReducer } from './metadata_slice'; import { VisBuilderServices } from '../../..'; import { getPreloadedState } from './preload'; import { setEditorState } from './metadata_slice'; @@ -25,10 +25,6 @@ export const configurePreloadedStore = (preloadedState: PreloadedState { - const { originatingApp } = - services.embeddable - .getStateTransfer(services.scopedHistory) - .getIncomingEditorState({ keysToRemoveAfterFetch: ['id', 'input'] }) || {}; const preloadedState = await getPreloadedState(services); const store = configurePreloadedStore(preloadedState); @@ -38,7 +34,6 @@ export const getPreloadedStore = async (services: VisBuilderServices) => { style: styleState, }; let previousMetadata = metadataState; - store.dispatch(setOriginatingApp({ state: originatingApp })); // Listen to changes const handleChange = () => { diff --git a/src/plugins/vis_builder/public/plugin.ts b/src/plugins/vis_builder/public/plugin.ts index 15a3cc74e6cf..a619958653b6 100644 --- a/src/plugins/vis_builder/public/plugin.ts +++ b/src/plugins/vis_builder/public/plugin.ts @@ -67,8 +67,8 @@ export class VisBuilderPlugin > { private typeService = new TypeService(); private appStateUpdater = new BehaviorSubject(() => ({})); - private stopUrlTracking: (() => void) | undefined = undefined; - private currentHistory: ScopedHistory | undefined = undefined; + private stopUrlTracking?: () => void; + private currentHistory?: ScopedHistory; constructor(public initializerContext: PluginInitializerContext) {} @@ -77,9 +77,9 @@ export class VisBuilderPlugin { embeddable, visualizations, data }: VisBuilderPluginSetupDependencies ) { const { appMounted, appUnMounted, stop: stopUrlTracker } = createOsdUrlTracker({ - baseUrl: core.http.basePath.prepend('/app/vis-builder'), + baseUrl: core.http.basePath.prepend(`/app/${PLUGIN_ID}`), defaultSubUrl: '#/', - storageKey: `lastUrl:${core.http.basePath.get()}:vis-builder`, + storageKey: `lastUrl:${core.http.basePath.get()}:${PLUGIN_ID}`, navLinkUpdater$: this.appStateUpdater, toastNotifications: core.notifications.toasts, stateParams: [ @@ -134,17 +134,16 @@ export class VisBuilderPlugin // dispatch synthetic hash change event to update hash history objects // this is necessary because hash updates triggered by using popState won't trigger this event naturally. - const unlistenParentHistory = params.history.listen(() => { + const unlistenParentHistory = this.currentHistory.listen(() => { window.dispatchEvent(new HashChangeEvent('hashchange')); }); - // Register Default Visualizations const services: VisBuilderServices = { ...coreStart, scopedHistory: this.currentHistory, - history: params.history, + history: this.currentHistory, osdUrlStateStorage: createOsdUrlStateStorage({ - history: params.history, + history: this.currentHistory, useHash: coreStart.uiSettings.get('state:storeInSessionStorage'), ...withNotifyOnErrors(coreStart.notifications.toasts), }), @@ -162,8 +161,8 @@ export class VisBuilderPlugin // Instantiate the store const store = await getPreloadedStore(services); - const unmount = renderApp(params, services, store); + // Render the application return () => { unlistenParentHistory(); diff --git a/src/plugins/vis_builder/public/types.ts b/src/plugins/vis_builder/public/types.ts index e73e279e05a9..2d323a13b213 100644 --- a/src/plugins/vis_builder/public/types.ts +++ b/src/plugins/vis_builder/public/types.ts @@ -15,7 +15,6 @@ import { TypeServiceSetup, TypeServiceStart } from './services/type_service'; import { SavedObjectLoader } from '../../saved_objects/public'; import { AppMountParameters, CoreStart, ToastsStart, ScopedHistory } from '../../../core/public'; import { IOsdUrlStateStorage } from '../../opensearch_dashboards_utils/public'; -import { UrlForwardingSetup } from '../../url_forwarding/public'; import { DataPublicPluginSetup } from '../../data/public'; export type VisBuilderSetup = TypeServiceSetup; diff --git a/yarn.lock b/yarn.lock index 822684d097bd..b40434b8fc20 100644 --- a/yarn.lock +++ b/yarn.lock @@ -16566,11 +16566,6 @@ strip-json-comments@3.1.1, strip-json-comments@^3.0.1, strip-json-comments@^3.1. resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-3.1.1.tgz#31f1281b3832630434831c310c01cccda8cbe006" integrity sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig== -strip-json-comments@~2.0.1: - version "2.0.1" - resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-2.0.1.tgz#3c531942e908c2697c0ec344858c286c7ca0a60a" - integrity sha1-PFMZQukIwml8DsNEhYwobHygpgo= - strong-log-transformer@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/strong-log-transformer/-/strong-log-transformer-2.1.0.tgz#0f5ed78d325e0421ac6f90f7f10e691d6ae3ae10"