import { css, cx } from '@emotion/css'; import React, { FC } from 'react'; import { DataLink, GrafanaTheme2, PanelData } from '@grafana/data'; import { selectors } from '@grafana/e2e-selectors'; import { Icon, useStyles2, ClickOutsideWrapper } from '@grafana/ui'; import { DashboardModel } from 'app/features/dashboard/state/DashboardModel'; import { PanelModel } from 'app/features/dashboard/state/PanelModel'; import { getPanelLinksSupplier } from 'app/features/panel/panellinks/linkSuppliers'; import PanelHeaderCorner from './PanelHeaderCorner'; import { PanelHeaderLoadingIndicator } from './PanelHeaderLoadingIndicator'; import { PanelHeaderMenuTrigger } from './PanelHeaderMenuTrigger'; import { PanelHeaderMenuWrapper } from './PanelHeaderMenuWrapper'; import { PanelHeaderNotices } from './PanelHeaderNotices'; export interface Props { panel: PanelModel; dashboard: DashboardModel; title?: string; description?: string; links?: DataLink[]; error?: string; alertState?: string; isViewing: boolean; isEditing: boolean; data: PanelData; } export const PanelHeader: FC = ({ panel, error, isViewing, isEditing, data, alertState, dashboard }) => { const onCancelQuery = () => panel.getQueryRunner().cancelQuery(); const title = panel.getDisplayTitle(); const className = cx('panel-header', !(isViewing || isEditing) ? 'grid-drag-handle' : ''); const styles = useStyles2(panelStyles); return ( <>
{({ closeMenu, panelMenuOpen }) => { return (
{alertState ? ( ) : null}

{title}

{panelMenuOpen ? ( ) : null} {data.request && data.request.timeInfo && ( {data.request.timeInfo} )}
); }}
); }; const panelStyles = (theme: GrafanaTheme2) => { return { titleText: css` text-overflow: ellipsis; overflow: hidden; white-space: nowrap; max-width: calc(100% - 38px); cursor: pointer; font-weight: ${theme.typography.fontWeightMedium}; font-size: ${theme.typography.body.fontSize}; margin: 0; &:hover { color: ${theme.colors.text.primary}; } .panel-has-alert & { max-width: calc(100% - 54px); } `, }; };