mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
DashboardScene: Fixes urlsync issue when going from normal to home dashboard (#93758)
* DashboardScene: Fixes urlsync issue when going from normal to home dashboard * Better fix * Update
This commit is contained in:
parent
40bcd0df41
commit
2cfba519f1
@ -1,5 +1,6 @@
|
||||
// Libraries
|
||||
import { useEffect, useMemo } from 'react';
|
||||
import { usePrevious } from 'react-use';
|
||||
|
||||
import { PageLayoutType } from '@grafana/data';
|
||||
import { UrlSyncContextProvider } from '@grafana/scenes';
|
||||
@ -19,8 +20,8 @@ import { getDashboardScenePageStateManager } from './DashboardScenePageStateMana
|
||||
export interface Props extends GrafanaRouteComponentProps<DashboardPageRouteParams, DashboardPageRouteSearchParams> {}
|
||||
|
||||
export function DashboardScenePage({ match, route, queryParams, history }: Props) {
|
||||
const prevMatch = usePrevious(match);
|
||||
const stateManager = getDashboardScenePageStateManager();
|
||||
|
||||
const { dashboard, isLoading, loadError } = stateManager.useState();
|
||||
|
||||
// After scene migration is complete and we get rid of old dashboard we should refactor dashboardWatcher so this route reload is not need
|
||||
@ -83,12 +84,10 @@ export function DashboardScenePage({ match, route, queryParams, history }: Props
|
||||
}
|
||||
|
||||
// Do not render anything when transitioning from one dashboard to another
|
||||
if (
|
||||
match.params.type !== 'snapshot' &&
|
||||
match.params.uid &&
|
||||
dashboard.state.uid !== match.params.uid &&
|
||||
route.routeName !== DashboardRoutes.Home
|
||||
) {
|
||||
// A bit tricky for transition to or from Home dashbord that does not have a uid in the url (but could have it in the dashboard model)
|
||||
// if prevMatch is undefined we are going from normal route to home route or vice versa
|
||||
if (match.params.type !== 'snapshot' && (!prevMatch || match.params.uid !== prevMatch?.params.uid)) {
|
||||
console.log('skipping rendering');
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -40,6 +40,22 @@ describe('DashboardScenePageStateManager', () => {
|
||||
expect(loader.state.loadError).toBe('Dashboard not found');
|
||||
});
|
||||
|
||||
it('should clear current dashboard while loading next', async () => {
|
||||
setupLoadDashboardMock({ dashboard: { uid: 'fake-dash', editable: true }, meta: {} });
|
||||
|
||||
const loader = new DashboardScenePageStateManager({});
|
||||
await loader.loadDashboard({ uid: 'fake-dash', route: DashboardRoutes.Normal });
|
||||
|
||||
expect(loader.state.dashboard).toBeDefined();
|
||||
|
||||
setupLoadDashboardMock({ dashboard: { uid: 'fake-dash2', editable: true }, meta: {} });
|
||||
|
||||
loader.loadDashboard({ uid: 'fake-dash2', route: DashboardRoutes.Normal });
|
||||
|
||||
expect(loader.state.isLoading).toBe(true);
|
||||
expect(loader.state.dashboard).toBeUndefined();
|
||||
});
|
||||
|
||||
it('shoud fetch dashboard from local storage and remove it after if it exists', async () => {
|
||||
const loader = new DashboardScenePageStateManager({});
|
||||
const localStorageDashboard = { uid: 'fake-dash' };
|
||||
|
@ -208,7 +208,7 @@ export class DashboardScenePageStateManager extends StateManagerBase<DashboardSc
|
||||
options.keepDashboardFromExploreInLocalStorage === false
|
||||
);
|
||||
|
||||
this.setState({ isLoading: true });
|
||||
this.setState({ dashboard: undefined, isLoading: true });
|
||||
|
||||
const rsp = await this.fetchDashboard(options);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user