forked from grafana/grafana
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSubMenuItems.tsx
44 lines (36 loc) · 1.23 KB
/
SubMenuItems.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
import React, { useEffect, useState } from 'react';
import { selectors } from '@grafana/e2e-selectors';
import { useSelector } from 'app/types';
import { PickerRenderer } from '../../../variables/pickers/PickerRenderer';
import { VariableHide, VariableModel } from '../../../variables/types';
interface Props {
variables: VariableModel[];
readOnly?: boolean;
}
export const SubMenuItems = ({ variables, readOnly }: Props) => {
const [visibleVariables, setVisibleVariables] = useState<VariableModel[]>([]);
const hiddenVariables = useSelector((state) => state.fnGlobalState.hiddenVariables);
useEffect(() => {
setVisibleVariables(
variables.filter((state) => state.hide !== VariableHide.hideVariable && !hiddenVariables?.includes(state.id))
);
}, [variables, hiddenVariables]);
if (visibleVariables.length === 0) {
return null;
}
return (
<>
{visibleVariables.map((variable) => {
return (
<div
key={variable.id}
className="submenu-item gf-form-inline"
data-testid={selectors.pages.Dashboard.SubMenu.submenuItem}
>
<PickerRenderer variable={variable} readOnly={readOnly} />
</div>
);
})}
</>
);
};