Skip to content

Commit

Permalink
remove panels from url
Browse files Browse the repository at this point in the history
  • Loading branch information
Dosant committed Apr 3, 2020
1 parent e85941f commit 72665cb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@ import {
TimefilterContract as Timefilter,
} from '../../../../../../plugins/data/public';

import { getAppStateDefaults, migrateAppState, getDashboardIdFromUrl } from './lib';
import { getAppStateDefaults, getDashboardIdFromUrl, migrateAppState } from './lib';
import { convertPanelStateToSavedDashboardPanel } from './lib/embeddable_saved_object_converters';
import { FilterUtils } from './lib/filter_utils';
import {
DashboardAppState,
DashboardAppStateDefaults,
DashboardAppStateInUrl,
DashboardAppStateTransitions,
SavedDashboardPanel,
} from './types';
Expand Down Expand Up @@ -164,14 +165,21 @@ export class DashboardStateManager {
});

// make sure url ('_a') matches initial state
this.kbnUrlStateStorage.set(this.STATE_STORAGE_KEY, initialState, { replace: true });
this.kbnUrlStateStorage.set<DashboardAppStateInUrl>(
this.STATE_STORAGE_KEY,
this.toUrlState(initialState),
{
replace: true,
}
);

// setup state syncing utils. state container will be synced with url into `this.STATE_STORAGE_KEY` query param
this.stateSyncRef = syncState<DashboardAppState>({
this.stateSyncRef = syncState<DashboardAppStateInUrl>({
storageKey: this.STATE_STORAGE_KEY,
stateContainer: {
...this.stateContainer,
set: (state: DashboardAppState | null) => {
get: () => this.toUrlState(this.stateContainer.get()),
set: (state: DashboardAppStateInUrl | null) => {
// sync state required state container to be able to handle null
// overriding set() so it could handle null coming from url
if (state) {
Expand Down Expand Up @@ -558,9 +566,9 @@ export class DashboardStateManager {
*/
public saveState({ replace }: { replace: boolean }): boolean {
// schedules setting current state to url
this.kbnUrlStateStorage.set<DashboardAppState>(
this.kbnUrlStateStorage.set<DashboardAppStateInUrl>(
this.STATE_STORAGE_KEY,
this.stateContainer.get()
this.toUrlState(this.stateContainer.get())
);
// immediately forces scheduled updates and changes location
return this.kbnUrlStateStorage.flush({ replace });
Expand Down Expand Up @@ -620,4 +628,13 @@ export class DashboardStateManager {
const current = _.omit(this.stateContainer.get(), propsToIgnore);
return !_.isEqual(initial, current);
}

private toUrlState(state: DashboardAppState): DashboardAppStateInUrl {
if (state.viewMode === ViewMode.VIEW) {
const { panels, ...stateWithoutPanels } = state;
return stateWithoutPanels;
} else {
return state;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ export type DashboardAppStateDefaults = DashboardAppState & {
description?: string;
};

/**
* In URL panels are optional,
* Panels are not added to the URL when in "view" mode
*/
export type DashboardAppStateInUrl = Omit<DashboardAppState, 'panels'> & {
panels?: SavedDashboardPanel[];
};

export interface DashboardAppStateTransitions {
set: (
state: DashboardAppState
Expand Down

0 comments on commit 72665cb

Please sign in to comment.