forked from grafana/grafana
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPanelHeader.tsx
108 lines (100 loc) · 3.91 KB
/
PanelHeader.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import { css, cx } from '@emotion/css';
import { Box } from '@mui/material';
import React from 'react';
import { DataLink, GrafanaTheme2, PanelData } from '@grafana/data';
import { selectors } from '@grafana/e2e-selectors';
import { reportInteraction } from '@grafana/runtime';
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 { 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 function PanelHeader({ panel, error, isViewing, isEditing, data, alertState, dashboard }: Props) {
const onCancelQuery = () => panel.getQueryRunner().cancelQuery();
const title = panel.getDisplayTitle();
const className = cx('panel-header', !(isViewing || isEditing) ? 'grid-drag-handle' : '');
const styles = useStyles2(panelStyles);
const onOpenMenu = () => {
reportInteraction('dashboards_panelheader_menu', { item: 'menu' });
};
return (
<>
<PanelHeaderLoadingIndicator state={data.state} onClick={onCancelQuery} />
<PanelHeaderCorner
panel={panel}
title={panel.title}
description={panel.description}
scopedVars={panel.scopedVars}
links={getPanelLinksSupplier(panel)}
error={error}
/>
<Box className={className} sx={{ '&:hover': { backgroundColor: 'transparent !important' } }}>
<PanelHeaderMenuTrigger data-testid={selectors.components.Panels.Panel.title(title)} onOpenMenu={onOpenMenu}>
{({ closeMenu, panelMenuOpen }) => {
return (
<ClickOutsideWrapper onClick={closeMenu} parent={document}>
<div className="panel-title">
<PanelHeaderNotices frames={data.series} panelId={panel.id} />
{alertState ? (
<Icon
name={alertState === 'alerting' ? 'heart-break' : 'heart'}
className="icon-gf panel-alert-icon"
style={{ marginRight: '4px' }}
size="sm"
/>
) : null}
<h2 className={styles.titleText}>{title}</h2>
{!dashboard.meta.publicDashboardAccessToken && (
<div data-testid="panel-dropdown">
{/* <Icon name="angle-down" className="panel-menu-toggle" />
{panelMenuOpen ? <PanelHeaderMenuWrapper panel={panel} dashboard={dashboard} /> : null} */}
</div>
)}
{data.request && data.request.timeInfo && (
<span className="panel-time-info">
<Icon name="clock-nine" size="sm" /> {data.request.timeInfo}
</span>
)}
</div>
</ClickOutsideWrapper>
);
}}
</PanelHeaderMenuTrigger>
</Box>
</>
);
}
const panelStyles = (theme: GrafanaTheme2) => {
return {
titleText: css`
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
max-width: calc(100% - 38px);
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);
}
`,
};
};