The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/public/app/features/dashboard-scene/scene/PanelLinks.tsx

48 lines
1.3 KiB

import React from 'react';
import { LinkModel } from '@grafana/data';
import { SceneComponentProps, SceneObjectBase, SceneObjectState } from '@grafana/scenes';
import { Dropdown, Menu, ToolbarButton } from '@grafana/ui';
interface VizPanelLinksState extends SceneObjectState {
links?: LinkModel[];
menu: VizPanelLinksMenu;
}
export class VizPanelLinks extends SceneObjectBase<VizPanelLinksState> {
static Component = VizPanelLinksRenderer;
}
function VizPanelLinksRenderer({ model }: SceneComponentProps<VizPanelLinks>) {
const { menu } = model.useState();
return (
<Dropdown
overlay={() => {
return <menu.Component model={menu} key={menu.state.key} />;
}}
>
<ToolbarButton icon="external-link-alt" iconSize="md" aria-label="panel links" />
</Dropdown>
);
}
export class VizPanelLinksMenu extends SceneObjectBase<Omit<VizPanelLinksState, 'menu'>> {
static Component = VizPanelLinksMenuRenderer;
}
function VizPanelLinksMenuRenderer({ model }: SceneComponentProps<VizPanelLinks>) {
const { links } = model.useState();
if (!links) {
return null;
}
return (
<Menu>
{links?.map((link, idx) => {
return <Menu.Item key={idx} label={link.title} url={link.href} target={link.target} onClick={link.onClick} />;
})}
</Menu>
);
}