mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
DashboardScene: Fix broken error handling and error rendering (#93680)
This commit is contained in:
parent
038d9cabde
commit
05dbba4c85
@ -3,6 +3,7 @@ import { useEffect, useMemo } from 'react';
|
|||||||
|
|
||||||
import { PageLayoutType } from '@grafana/data';
|
import { PageLayoutType } from '@grafana/data';
|
||||||
import { UrlSyncContextProvider } from '@grafana/scenes';
|
import { UrlSyncContextProvider } from '@grafana/scenes';
|
||||||
|
import { Alert, Box } from '@grafana/ui';
|
||||||
import { Page } from 'app/core/components/Page/Page';
|
import { Page } from 'app/core/components/Page/Page';
|
||||||
import PageLoader from 'app/core/components/PageLoader/PageLoader';
|
import PageLoader from 'app/core/components/PageLoader/PageLoader';
|
||||||
import { GrafanaRouteComponentProps } from 'app/core/navigation/types';
|
import { GrafanaRouteComponentProps } from 'app/core/navigation/types';
|
||||||
@ -68,9 +69,15 @@ export function DashboardScenePage({ match, route, queryParams, history }: Props
|
|||||||
|
|
||||||
if (!dashboard) {
|
if (!dashboard) {
|
||||||
return (
|
return (
|
||||||
<Page layout={PageLayoutType.Canvas} data-testid={'dashboard-scene-page'}>
|
<Page navId="dashboards/browse" layout={PageLayoutType.Canvas} data-testid={'dashboard-scene-page'}>
|
||||||
{isLoading && <PageLoader />}
|
<Box paddingY={4} display="flex" direction="column" alignItems="center">
|
||||||
{loadError && <h2>{loadError}</h2>}
|
{isLoading && <PageLoader />}
|
||||||
|
{loadError && (
|
||||||
|
<Alert title="Dashboard failed to load" severity="error" data-testid="dashboard-not-found">
|
||||||
|
{loadError}
|
||||||
|
</Alert>
|
||||||
|
)}
|
||||||
|
</Box>
|
||||||
</Page>
|
</Page>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ describe('DashboardScenePageStateManager', () => {
|
|||||||
const loader = new DashboardScenePageStateManager({});
|
const loader = new DashboardScenePageStateManager({});
|
||||||
await loader.loadDashboard({ uid: 'fake-dash', route: DashboardRoutes.Normal });
|
await loader.loadDashboard({ uid: 'fake-dash', route: DashboardRoutes.Normal });
|
||||||
|
|
||||||
expect(loader.state.dashboard).toBeDefined();
|
expect(loader.state.dashboard).toBeUndefined();
|
||||||
expect(loader.state.isLoading).toBe(false);
|
expect(loader.state.isLoading).toBe(false);
|
||||||
expect(loader.state.loadError).toBe('Dashboard not found');
|
expect(loader.state.loadError).toBe('Dashboard not found');
|
||||||
});
|
});
|
||||||
@ -107,8 +107,7 @@ describe('DashboardScenePageStateManager', () => {
|
|||||||
const loader = new DashboardScenePageStateManager({});
|
const loader = new DashboardScenePageStateManager({});
|
||||||
await loader.loadDashboard({ uid: '', route: DashboardRoutes.Home });
|
await loader.loadDashboard({ uid: '', route: DashboardRoutes.Home });
|
||||||
|
|
||||||
expect(loader.state.dashboard).toBeDefined();
|
expect(loader.state.dashboard).toBeUndefined();
|
||||||
expect(loader.state.dashboard?.state.title).toEqual('Failed to load home dashboard');
|
|
||||||
expect(loader.state.loadError).toEqual('Failed to load home dashboard');
|
expect(loader.state.loadError).toEqual('Failed to load home dashboard');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,13 +1,11 @@
|
|||||||
import { locationUtil } from '@grafana/data';
|
import { locationUtil } from '@grafana/data';
|
||||||
import { config, getBackendSrv, isFetchError, locationService } from '@grafana/runtime';
|
import { config, getBackendSrv, isFetchError, locationService } from '@grafana/runtime';
|
||||||
import { defaultDashboard } from '@grafana/schema';
|
|
||||||
import { StateManagerBase } from 'app/core/services/StateManagerBase';
|
import { StateManagerBase } from 'app/core/services/StateManagerBase';
|
||||||
import { default as localStorageStore } from 'app/core/store';
|
import { default as localStorageStore } from 'app/core/store';
|
||||||
import { getMessageFromError } from 'app/core/utils/errors';
|
import { getMessageFromError } from 'app/core/utils/errors';
|
||||||
import { startMeasure, stopMeasure } from 'app/core/utils/metrics';
|
import { startMeasure, stopMeasure } from 'app/core/utils/metrics';
|
||||||
import { dashboardLoaderSrv } from 'app/features/dashboard/services/DashboardLoaderSrv';
|
import { dashboardLoaderSrv } from 'app/features/dashboard/services/DashboardLoaderSrv';
|
||||||
import { getDashboardSrv } from 'app/features/dashboard/services/DashboardSrv';
|
import { getDashboardSrv } from 'app/features/dashboard/services/DashboardSrv';
|
||||||
import { DashboardModel } from 'app/features/dashboard/state';
|
|
||||||
import { emitDashboardViewEvent } from 'app/features/dashboard/state/analyticsProcessor';
|
import { emitDashboardViewEvent } from 'app/features/dashboard/state/analyticsProcessor';
|
||||||
import {
|
import {
|
||||||
DASHBOARD_FROM_LS_KEY,
|
DASHBOARD_FROM_LS_KEY,
|
||||||
@ -20,10 +18,7 @@ import { DashboardDTO, DashboardRoutes } from 'app/types';
|
|||||||
import { PanelEditor } from '../panel-edit/PanelEditor';
|
import { PanelEditor } from '../panel-edit/PanelEditor';
|
||||||
import { DashboardScene } from '../scene/DashboardScene';
|
import { DashboardScene } from '../scene/DashboardScene';
|
||||||
import { buildNewDashboardSaveModel } from '../serialization/buildNewDashboardSaveModel';
|
import { buildNewDashboardSaveModel } from '../serialization/buildNewDashboardSaveModel';
|
||||||
import {
|
import { transformSaveModelToScene } from '../serialization/transformSaveModelToScene';
|
||||||
createDashboardSceneFromDashboardModel,
|
|
||||||
transformSaveModelToScene,
|
|
||||||
} from '../serialization/transformSaveModelToScene';
|
|
||||||
import { restoreDashboardStateFromLocalStorage } from '../utils/dashboardSessionState';
|
import { restoreDashboardStateFromLocalStorage } from '../utils/dashboardSessionState';
|
||||||
|
|
||||||
import { updateNavModel } from './utils';
|
import { updateNavModel } from './utils';
|
||||||
@ -203,11 +198,7 @@ export class DashboardScenePageStateManager extends StateManagerBase<DashboardSc
|
|||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const msg = getMessageFromError(err);
|
const msg = getMessageFromError(err);
|
||||||
this.setState({
|
this.setState({ isLoading: false, loadError: msg });
|
||||||
isLoading: false,
|
|
||||||
loadError: msg,
|
|
||||||
dashboard: getErrorScene(msg),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -318,59 +309,3 @@ export function getDashboardScenePageStateManager(): DashboardScenePageStateMana
|
|||||||
|
|
||||||
return stateManager;
|
return stateManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getErrorScene(msg: string) {
|
|
||||||
const dto: DashboardDTO = {
|
|
||||||
dashboard: {
|
|
||||||
...defaultDashboard,
|
|
||||||
uid: 'error-dash',
|
|
||||||
title: msg,
|
|
||||||
annotations: {
|
|
||||||
list: [
|
|
||||||
{
|
|
||||||
builtIn: 1,
|
|
||||||
datasource: {
|
|
||||||
type: 'grafana',
|
|
||||||
uid: '-- Grafana --',
|
|
||||||
},
|
|
||||||
enable: false,
|
|
||||||
hide: true,
|
|
||||||
iconColor: 'rgba(0, 211, 255, 1)',
|
|
||||||
name: 'Annotations & Alerts',
|
|
||||||
type: 'dashboard',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
|
|
||||||
panels: [
|
|
||||||
{
|
|
||||||
fieldConfig: {
|
|
||||||
defaults: {},
|
|
||||||
overrides: [],
|
|
||||||
},
|
|
||||||
gridPos: {
|
|
||||||
h: 6,
|
|
||||||
w: 12,
|
|
||||||
x: 7,
|
|
||||||
y: 0,
|
|
||||||
},
|
|
||||||
id: 1,
|
|
||||||
options: {
|
|
||||||
code: {
|
|
||||||
language: 'plaintext',
|
|
||||||
showLineNumbers: false,
|
|
||||||
showMiniMap: false,
|
|
||||||
},
|
|
||||||
content: `<br/><br/><center><h1>${msg}</h1></center>`,
|
|
||||||
mode: 'html',
|
|
||||||
},
|
|
||||||
title: '',
|
|
||||||
transparent: true,
|
|
||||||
type: 'text',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
meta: { canSave: false, canEdit: false },
|
|
||||||
};
|
|
||||||
return createDashboardSceneFromDashboardModel(new DashboardModel(dto.dashboard, dto.meta), dto.dashboard);
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user