forked from grafana/grafana
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSubMenu.tsx
115 lines (96 loc) · 3.37 KB
/
SubMenu.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
109
110
111
112
113
114
115
import { css } from '@emotion/css';
import FilterListIcon from '@mui/icons-material/FilterList';
import { Box, styled } from '@mui/material';
import React, { FC, PureComponent } from 'react';
import { connect, MapStateToProps } from 'react-redux';
import { AnnotationQuery, DataQuery } from '@grafana/data';
import { FnGlobalState } from 'app/core/reducers/fn-slice';
import { StoreState } from '../../../../types';
import { getSubMenuVariables, getVariablesState } from '../../../variables/state/selectors';
import { VariableModel } from '../../../variables/types';
import { DashboardModel } from '../../state';
import { DashboardLink } from '../../state/DashboardModel';
import { Annotations } from './Annotations';
import { DashboardLinks } from './DashboardLinks';
import { SubMenuItems } from './SubMenuItems';
interface OwnProps {
dashboard: DashboardModel;
links: DashboardLink[];
annotations: AnnotationQuery[];
}
interface ConnectedProps {
variables: VariableModel[];
hiddenVariables: FnGlobalState['hiddenVariables'];
}
interface DispatchProps {}
type Props = OwnProps & ConnectedProps & DispatchProps;
class SubMenuUnConnected extends PureComponent<Props> {
onAnnotationStateChanged = (updatedAnnotation: AnnotationQuery<DataQuery>) => {
// we're mutating dashboard state directly here until annotations are in Redux.
for (let index = 0; index < this.props.dashboard.annotations.list.length; index++) {
const annotation = this.props.dashboard.annotations.list[index];
if (annotation.name === updatedAnnotation.name) {
annotation.enable = !annotation.enable;
break;
}
}
this.props.dashboard.startRefresh();
this.forceUpdate();
};
render() {
const { dashboard, variables, links, annotations } = this.props;
if (!dashboard.isSubMenuVisible()) {
return null;
}
const readOnlyVariables = dashboard.meta.isSnapshot ?? false;
return (
<div className="submenu-controls">
<form aria-label="Template variables" className={styles}>
<FilterWithIcon />
<SubMenuItems
variables={variables}
readOnly={readOnlyVariables}
hiddenVariables={this.props.hiddenVariables}
/>
</form>
<Annotations
annotations={annotations}
onAnnotationChanged={this.onAnnotationStateChanged}
events={dashboard.events}
/>
<div className="gf-form gf-form--grow" />
{dashboard && <DashboardLinks dashboard={dashboard} links={links} />}
</div>
);
}
}
const mapStateToProps: MapStateToProps<ConnectedProps, OwnProps, StoreState> = (state, ownProps) => {
const { uid } = ownProps.dashboard;
const templatingState = getVariablesState(uid, state);
return {
variables: getSubMenuVariables(uid, templatingState.variables),
hiddenVariables: state.fnGlobalState.hiddenVariables,
};
};
const styles = css`
display: flex;
flex-wrap: wrap;
display: contents;
`;
export const SubMenu = connect(mapStateToProps)(SubMenuUnConnected);
SubMenu.displayName = 'SubMenu';
const FilterWithIcon: FC = () => (
<FilterWithIconStyled>
<FilterListIcon sx={{ color: '#3A785E' }} />
FILTERS
</FilterWithIconStyled>
);
const FilterWithIconStyled = styled(Box)({
display: 'flex',
gap: 1,
alignItems: 'center',
color: '#3A785E',
fontWeight: 600,
lineHeight: '160%',
fontSize: 12,
});