Skip to content

Commit

Permalink
resolve comments
Browse files Browse the repository at this point in the history
Signed-off-by: abbyhu2000 <abigailhu2000@gmail.com>
  • Loading branch information
abbyhu2000 committed Dec 2, 2022
1 parent a146674 commit e372335
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export interface TopNavConfigParams {
savedVisBuilderVis: VisBuilderVisSavedObject;
saveDisabledReason?: string;
dispatch: AppDispatch;
originatingApp: string | undefined;
originatingApp?: string;
}

export const getTopNavConfig = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,14 @@ const initialState: MetadataState = {
export const getPreloadedState = async ({
types,
data,
embeddable,
scopedHistory,
}: VisBuilderServices): Promise<MetadataState> => {
const preloadedState = { ...initialState };
const { originatingApp } =
embeddable
.getStateTransfer(scopedHistory)
.getIncomingEditorState({ keysToRemoveAfterFetch: ['id', 'input'] }) || {};
const preloadedState = { ...initialState, originatingApp };

return preloadedState;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -25,10 +25,6 @@ export const configurePreloadedStore = (preloadedState: PreloadedState<RootState
};

export const getPreloadedStore = async (services: VisBuilderServices) => {
const { originatingApp } =
services.embeddable
.getStateTransfer(services.scopedHistory)
.getIncomingEditorState({ keysToRemoveAfterFetch: ['id', 'input'] }) || {};
const preloadedState = await getPreloadedState(services);
const store = configurePreloadedStore(preloadedState);

Expand All @@ -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 = () => {
Expand Down
17 changes: 8 additions & 9 deletions src/plugins/vis_builder/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ export class VisBuilderPlugin
> {
private typeService = new TypeService();
private appStateUpdater = new BehaviorSubject<AppUpdater>(() => ({}));
private stopUrlTracking: (() => void) | undefined = undefined;
private currentHistory: ScopedHistory | undefined = undefined;
private stopUrlTracking?: () => void;
private currentHistory?: ScopedHistory;

constructor(public initializerContext: PluginInitializerContext<ConfigSchema>) {}

Expand All @@ -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: [
Expand Down Expand Up @@ -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),
}),
Expand All @@ -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();
Expand Down
1 change: 0 additions & 1 deletion src/plugins/vis_builder/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit e372335

Please sign in to comment.