DashboardScene: Add mapping for hoverHeader and displayMode to DashboardsLoader (#64870)

Dashboard scene fixes
This commit is contained in:
Torkel Ödegaard 2023-03-16 09:19:50 +01:00 committed by GitHub
parent 5d8ec2756e
commit 07305c72bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 1 deletions

View File

@ -1,6 +1,7 @@
// Libraries
import React, { useEffect } from 'react';
import { PageLayoutType } from '@grafana/data';
import { Page } from 'app/core/components/Page/Page';
import PageLoader from 'app/core/components/PageLoader/PageLoader';
import { GrafanaRouteComponentProps } from 'app/core/navigation/types';
@ -15,11 +16,14 @@ export const DashboardScenePage = ({ match }: Props) => {
useEffect(() => {
loader.load(match.params.uid);
return () => {
loader.clearState();
};
}, [loader, match.params.uid]);
if (!dashboard) {
return (
<Page navId="dashboards/browse">
<Page layout={PageLayoutType.Canvas}>
{isLoading && <PageLoader />}
{!isLoading && <h2>Dashboard not found</h2>}
</Page>

View File

@ -312,6 +312,20 @@ describe('DashboardLoader', () => {
panel.transformations
);
});
it('should initalize the VizPanel without title and transparent true', () => {
const panel = {
title: '',
type: 'test-plugin',
gridPos: { x: 0, y: 0, w: 12, h: 8 },
transparent: true,
};
const vizPanelSceneObject = createVizPanelFromPanelModel(new PanelModel(panel));
expect(vizPanelSceneObject.state.displayMode).toEqual('transparent');
expect(vizPanelSceneObject.state.hoverHeader).toEqual(true);
});
});
describe('when creating variables objects', () => {

View File

@ -73,6 +73,10 @@ export class DashboardLoader extends StateManagerBase<DashboardLoaderState> {
this.cache[rsp.dashboard.uid] = dashboard;
this.setState({ dashboard, isLoading: false });
}
public clearState() {
this.setState({ dashboard: undefined, loadError: undefined, isLoading: false });
}
}
export function createSceneObjectsForPanels(oldPanels: PanelModel[]): SceneObject[] {
@ -264,6 +268,9 @@ export function createVizPanelFromPanelModel(panel: PanelModel) {
options: panel.options,
fieldConfig: panel.fieldConfig,
pluginVersion: panel.pluginVersion,
displayMode: panel.transparent ? 'transparent' : undefined,
// To be replaced with it's own option persited option instead derived
hoverHeader: !panel.title && !panel.timeFrom && !panel.timeShift,
$data: new SceneDataTransformer({
$data: new SceneQueryRunner({
queries: panel.targets,