mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
DashboardScene: Add support for showing notices in panel header (#79146)
This commit is contained in:
parent
393711c3a1
commit
dfc139b2ff
50
public/app/features/dashboard-scene/scene/PanelNotices.tsx
Normal file
50
public/app/features/dashboard-scene/scene/PanelNotices.tsx
Normal file
@ -0,0 +1,50 @@
|
||||
import React from 'react';
|
||||
|
||||
import { SceneComponentProps, SceneObjectBase, VizPanel, sceneGraph } from '@grafana/scenes';
|
||||
import { PanelHeaderNotices } from 'app/features/dashboard/dashgrid/PanelHeader/PanelHeaderNotices';
|
||||
|
||||
import { getPanelIdForVizPanel } from '../utils/utils';
|
||||
|
||||
export class PanelNotices extends SceneObjectBase {
|
||||
static Component = PanelNoticesRenderer;
|
||||
|
||||
constructor() {
|
||||
super({});
|
||||
this.addActivationHandler(this.onActivate);
|
||||
}
|
||||
|
||||
private onActivate = () => {
|
||||
const panel = this.parent;
|
||||
if (!panel || !(panel instanceof VizPanel)) {
|
||||
throw new Error('PanelNotices can be used only as title items for VizPanel');
|
||||
}
|
||||
};
|
||||
|
||||
public getPanel() {
|
||||
const panel = this.parent;
|
||||
|
||||
if (panel && panel instanceof VizPanel) {
|
||||
return panel;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function PanelNoticesRenderer({ model }: SceneComponentProps<PanelNotices>) {
|
||||
const panel = model.getPanel();
|
||||
const dataObject = sceneGraph.getData(model);
|
||||
const data = dataObject.useState();
|
||||
|
||||
if (!panel) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const panelId = getPanelIdForVizPanel(panel);
|
||||
|
||||
if (data.data?.series) {
|
||||
return <PanelHeaderNotices frames={data.data?.series} panelId={panelId} />;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
@ -40,6 +40,7 @@ import { DashboardScene } from '../scene/DashboardScene';
|
||||
import { LibraryVizPanel } from '../scene/LibraryVizPanel';
|
||||
import { VizPanelLinks, VizPanelLinksMenu } from '../scene/PanelLinks';
|
||||
import { getPanelLinksBehavior, panelMenuBehavior } from '../scene/PanelMenuBehavior';
|
||||
import { PanelNotices } from '../scene/PanelNotices';
|
||||
import { PanelRepeaterGridItem } from '../scene/PanelRepeaterGridItem';
|
||||
import { PanelTimeRange } from '../scene/PanelTimeRange';
|
||||
import { RowRepeaterBehavior } from '../scene/RowRepeaterBehavior';
|
||||
@ -391,14 +392,18 @@ export function buildGridItemForLibPanel(panel: PanelModel) {
|
||||
|
||||
export function buildGridItemForPanel(panel: PanelModel): SceneGridItemLike {
|
||||
const hasPanelLinks = panel.links && panel.links.length > 0;
|
||||
const titleItems: SceneObject[] = [];
|
||||
let panelLinks;
|
||||
|
||||
if (hasPanelLinks) {
|
||||
panelLinks = new VizPanelLinks({
|
||||
menu: new VizPanelLinksMenu({ $behaviors: [getPanelLinksBehavior(panel)] }),
|
||||
});
|
||||
titleItems.push(panelLinks);
|
||||
}
|
||||
|
||||
titleItems.push(new PanelNotices());
|
||||
|
||||
const vizPanelState: VizPanelState = {
|
||||
key: getVizPanelKeyForPanelId(panel.id),
|
||||
title: panel.title,
|
||||
@ -414,7 +419,7 @@ export function buildGridItemForPanel(panel: PanelModel): SceneGridItemLike {
|
||||
menu: new VizPanelMenu({
|
||||
$behaviors: [panelMenuBehavior],
|
||||
}),
|
||||
titleItems: panelLinks,
|
||||
titleItems,
|
||||
|
||||
extendPanelContext: setDashboardPanelContext,
|
||||
_UNSAFE_customMigrationHandler: getAngularPanelMigrationHandler(panel),
|
||||
|
Loading…
Reference in New Issue
Block a user