diff --git a/CHANGELOG.md b/CHANGELOG.md index 6bc3842e294d..e583fb9a96a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -68,8 +68,13 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - [Table Visualization] Fix first column sort issue ([#2828](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2828)) - Temporary workaround for task-kill exceptions on Windows when it is passed a pid for a process that is already dead ([#2842](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2842)) - [Vis Builder] Fix empty workspace animation does not work in firefox ([#2853](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2853)) +<<<<<<< HEAD - Bumped `del` version to fix MacOS race condition ([#2847](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2873)) - [Vis Builder] global data persistence for vis builder #2896 ([#2896](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2896)) +======= +- [Vis Builder] global data persistence for vis builder #2896 ([#2896](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2896)) + +>>>>>>> 6afe345231bc48ead6f9361d43a99f153302d8a4 ### 🚞 Infrastructure - Add CHANGELOG.md and related workflows ([#2414](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2414)) 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 c7b6a2353b47..8013b46c5cab 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,9 +35,15 @@ 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 b8a6f886237b..1d12afe824f1 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) {} @@ -76,16 +76,10 @@ export class VisBuilderPlugin core: CoreSetup, { embeddable, visualizations, data: dataSetup }: VisBuilderPluginSetupDependencies ) { - const { - appMounted, - appUnMounted, - stop: stopUrlTracker, - setActiveUrl, - restorePreviousUrl, - } = createOsdUrlTracker({ - baseUrl: core.http.basePath.prepend('/app/vis-builder'), + const { appMounted, appUnMounted, stop: stopUrlTracker } = createOsdUrlTracker({ + 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: [ @@ -110,6 +104,7 @@ export class VisBuilderPlugin stopUrlTracker(); }; + // Register Default Visualizations const typeService = this.typeService; registerDefaultTypes(typeService.setup()); @@ -143,13 +138,12 @@ export class VisBuilderPlugin 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,15 +156,12 @@ export class VisBuilderPlugin types: typeService.start(), savedVisBuilderLoader: selfStart.savedVisBuilderLoader, embeddable: pluginsStart.embeddable, - setActiveUrl, - restorePreviousUrl, - dashboard: pluginsStart.dashboard, }; // 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 5780702be9cf..b07d73ddf256 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; @@ -50,9 +49,6 @@ export interface VisBuilderServices extends CoreStart { embeddable: EmbeddableStart; scopedHistory: ScopedHistory; osdUrlStateStorage: IOsdUrlStateStorage; - setActiveUrl: (newUrl: string) => void; - restorePreviousUrl: () => void; - dashboard: DashboardStart; } export interface ISavedVis {