Skip to content

Commit

Permalink
[Dashboard De-Angular] Cypress fix (#4521)
Browse files Browse the repository at this point in the history
* fix cypress

Signed-off-by: abbyhu2000 <[email protected]>

* refactor css files

Signed-off-by: abbyhu2000 <[email protected]>

---------

Signed-off-by: abbyhu2000 <[email protected]>
  • Loading branch information
abbyhu2000 committed Jul 7, 2023
1 parent 2ea2885 commit cfa9087
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@import "../../../../embeddable/public/variables";
@import "./grid/index";
@import "./panel/index";
@import "./viewport/index";
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
* under the License.
*/

import './_dashboard_container.scss';

import React from 'react';
import ReactDOM from 'react-dom';
import { I18nProvider } from '@osd/i18n/react';
Expand Down Expand Up @@ -112,6 +114,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'];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@

&:hover,
&:focus {
// TODO: this is a sass error, $embEditingModeHoverColor is undefined, comment it out for now
// background-color: $embEditingModeHoverColor;
background-color: $embEditingModeHoverColor;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

import 'react-grid-layout/css/styles.css';
import 'react-resizable/css/styles.css';
import './_dashboard_grid.scss';

// @ts-ignore
import sizeMe from 'react-sizeme';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -128,6 +129,8 @@ const createDashboardEmbeddable = (
notifications,
overlays,
savedObjects,
history,
osdUrlStateStorage,
} = dashboardServices;
const { query: queryService } = data;
const filterManager = queryService.filterManager;
Expand Down Expand Up @@ -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)) {
Expand Down

0 comments on commit cfa9087

Please sign in to comment.