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 <abigailhu2000@gmail.com>

* refactor css files

Signed-off-by: abbyhu2000 <abigailhu2000@gmail.com>

---------

Signed-off-by: abbyhu2000 <abigailhu2000@gmail.com>
  • Loading branch information
abbyhu2000 committed Jul 7, 2023
1 parent 5c915f0 commit 7a99eaa
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({

Check warning on line 78 in src/plugins/dashboard/public/application/utils/create_dashboard_app_state.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/dashboard/public/application/utils/create_dashboard_app_state.tsx#L78

Added line #L78 was not covered by tests
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 });

Check warning on line 129 in src/plugins/dashboard/public/application/utils/create_dashboard_app_state.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/dashboard/public/application/utils/create_dashboard_app_state.tsx#L128-L129

Added lines #L128 - L129 were not covered by tests
// immediately forces scheduled updates and changes location
return osdUrlStateStorage.flush({ replace });

Check warning on line 131 in src/plugins/dashboard/public/application/utils/create_dashboard_app_state.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/dashboard/public/application/utils/create_dashboard_app_state.tsx#L131

Added line #L131 was not covered by tests
};

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

Check warning on line 134 in src/plugins/dashboard/public/application/utils/create_dashboard_app_state.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/dashboard/public/application/utils/create_dashboard_app_state.tsx#L134

Added line #L134 was not covered by tests

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

Check warning on line 138 in src/plugins/dashboard/public/application/utils/create_dashboard_app_state.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/dashboard/public/application/utils/create_dashboard_app_state.tsx#L137-L138

Added lines #L137 - L138 were not covered by tests
};

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

Check warning on line 144 in src/plugins/dashboard/public/application/utils/create_dashboard_app_state.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/dashboard/public/application/utils/create_dashboard_app_state.tsx#L143-L144

Added lines #L143 - L144 were not covered by tests
}
return state;

Check warning on line 146 in src/plugins/dashboard/public/application/utils/create_dashboard_app_state.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/dashboard/public/application/utils/create_dashboard_app_state.tsx#L146

Added line #L146 was not covered by tests
};

export const updateStateUrl = ({
osdUrlStateStorage,
state,
replace,
}: {
osdUrlStateStorage: IOsdUrlStateStorage;
state: DashboardAppState;
replace: boolean;
}) => {
osdUrlStateStorage.set(APP_STATE_STORAGE_KEY, toUrlState(state), { replace });

Check warning on line 158 in src/plugins/dashboard/public/application/utils/create_dashboard_app_state.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/dashboard/public/application/utils/create_dashboard_app_state.tsx#L158

Added line #L158 was not covered by tests
// immediately forces scheduled updates and changes location
return osdUrlStateStorage.flush({ replace });

Check warning on line 160 in src/plugins/dashboard/public/application/utils/create_dashboard_app_state.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/dashboard/public/application/utils/create_dashboard_app_state.tsx#L160

Added line #L160 was not covered by tests
};
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);

Check warning on line 315 in src/plugins/dashboard/public/application/utils/get_nav_actions.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/dashboard/public/application/utils/get_nav_actions.tsx#L315

Added line #L315 was not covered by tests

// This is only necessary for new dashboards, which will default to Edit mode.
stateContainer.transitions.set('viewMode', ViewMode.VIEW);

Check warning on line 318 in src/plugins/dashboard/public/application/utils/get_nav_actions.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/dashboard/public/application/utils/get_nav_actions.tsx#L318

Added line #L318 was not covered by tests
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({

Check warning on line 306 in src/plugins/dashboard/public/application/utils/use/use_dashboard_container.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/dashboard/public/application/utils/use/use_dashboard_container.tsx#L305-L306

Added lines #L305 - L306 were not covered by tests
osdUrlStateStorage,
state: appState.getState(),
replace,
});
history[updated ? 'replace' : 'push']({
...history.location,
pathname,
});
};

dashboardContainer.getChangesFromAppStateForContainerState = (currentContainer: any) => {
const appStateDashboardInput = getDashboardInput();

Check warning on line 318 in src/plugins/dashboard/public/application/utils/use/use_dashboard_container.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/dashboard/public/application/utils/use/use_dashboard_container.tsx#L317-L318

Added lines #L317 - L318 were not covered by tests
if (!dashboardContainer || isErrorEmbeddable(dashboardContainer)) {
Expand Down

0 comments on commit 7a99eaa

Please sign in to comment.