Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Dashboard De-Angular] Cypress fix #4521

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix cypress
Signed-off-by: abbyhu2000 <[email protected]>
abbyhu2000 committed Jul 7, 2023
commit 56e6668bd5dbf5b8227c0d5e80a6925646227032
Original file line number Diff line number Diff line change
@@ -112,6 +112,7 @@ export class DashboardContainer extends Container<InheritedChildInput, Dashboard

public renderEmpty?: undefined | (() => React.ReactNode);
public getChangesFromAppStateForContainerState?: (containerInput: any) => any;
public updateAppStateUrl?: undefined | ((pathname: string, replace: boolean) => void);

private embeddablePanel: EmbeddableStart['EmbeddablePanel'];

Original file line number Diff line number Diff line change
@@ -75,14 +75,6 @@ export const createDashboardGlobalAndAppState = ({
pureTransitions
);

const toUrlState = (state: DashboardAppState): DashboardAppStateInUrl => {
if (state.viewMode === ViewMode.VIEW) {
const { panels, ...stateWithoutPanels } = state;
return stateWithoutPanels;
}
return state;
};

const { start: startStateSync, stop: stopStateSync } = syncState({
storageKey: APP_STATE_STORAGE_KEY,
stateContainer: {
@@ -133,12 +125,37 @@ export const createDashboardGlobalAndAppState = ({
we update the state format at all and want to handle BWC, we must not only migrate the
data stored with saved vis, but also any old state in the url.
*/
osdUrlStateStorage.set(APP_STATE_STORAGE_KEY, toUrlState(initialState), { replace: true });
const updateStateUrl = ({ state, replace }: { state: DashboardAppState; replace: boolean }) => {
osdUrlStateStorage.set(APP_STATE_STORAGE_KEY, toUrlState(state), { replace });
// immediately forces scheduled updates and changes location
return osdUrlStateStorage.flush({ replace });
};

// immediately forces scheduled updates and changes location
osdUrlStateStorage.flush({ replace: true });
updateStateUrl({ state: initialState, replace: true });

// start syncing the appState with the ('_a') url
startStateSync();
return { stateContainer, stopStateSync, stopSyncingQueryServiceStateWithUrl };
return { stateContainer, stopStateSync, updateStateUrl, stopSyncingQueryServiceStateWithUrl };
};

const toUrlState = (state: DashboardAppState): DashboardAppStateInUrl => {
if (state.viewMode === ViewMode.VIEW) {
const { panels, ...stateWithoutPanels } = state;
return stateWithoutPanels;
}
return state;
};

export const updateStateUrl = ({
osdUrlStateStorage,
state,
replace,
}: {
osdUrlStateStorage: IOsdUrlStateStorage;
state: DashboardAppState;
replace: boolean;
}) => {
osdUrlStateStorage.set(APP_STATE_STORAGE_KEY, toUrlState(state), { replace });
// immediately forces scheduled updates and changes location
return osdUrlStateStorage.flush({ replace });
};
Original file line number Diff line number Diff line change
@@ -311,7 +311,8 @@ export const getNavActions = (
const pathname = savedDashboard.id
? createDashboardEditUrl(savedDashboard.id)
: DashboardConstants.CREATE_NEW_DASHBOARD_URL;
history.push(pathname);

dashboardContainer?.updateAppStateUrl?.(pathname, false);

// This is only necessary for new dashboards, which will default to Edit mode.
stateContainer.transitions.set('viewMode', ViewMode.VIEW);
Original file line number Diff line number Diff line change
@@ -51,6 +51,7 @@ import { getSavedObjectFinder } from '../../../../../saved_objects/public';
import { DashboardConstants } from '../../../dashboard_constants';
import { SavedObjectDashboard } from '../../../saved_dashboards';
import { Dashboard } from '../../../dashboard';
import { updateStateUrl } from '../create_dashboard_app_state';

export const useDashboardContainer = (
services: DashboardServices,
@@ -128,6 +129,8 @@ const createDashboardEmbeddable = (
notifications,
overlays,
savedObjects,
history,
osdUrlStateStorage,
} = dashboardServices;
const { query: queryService } = data;
const filterManager = queryService.filterManager;
@@ -299,6 +302,18 @@ const createDashboardEmbeddable = (
) : null;
};

dashboardContainer.updateAppStateUrl = (pathname: string, replace: boolean) => {
const updated = updateStateUrl({
osdUrlStateStorage,
state: appState.getState(),
replace,
});
history[updated ? 'replace' : 'push']({
...history.location,
pathname,
});
};

dashboardContainer.getChangesFromAppStateForContainerState = (currentContainer: any) => {
const appStateDashboardInput = getDashboardInput();
if (!dashboardContainer || isErrorEmbeddable(dashboardContainer)) {