mirror of
https://github.com/grafana/grafana.git
synced 2025-08-01 21:22:12 +08:00

* update eslint, tsconfig + esbuild to handle new jsx transform * remove thing that breaks the new jsx transform * remove react imports * adjust grafana-icons build * is this the correct syntax? * try this * well this was much easier than expected... * change grafana-plugin-configs webpack config * fixes * fix lockfile * fix 2 more violations * use path.resolve instead of require.resolve * remove react import * fix react imports * more fixes * remove React import * remove import React from docs * remove another react import
56 lines
1.4 KiB
TypeScript
56 lines
1.4 KiB
TypeScript
import { css } from '@emotion/css';
|
|
import { useEffect, useState } from 'react';
|
|
|
|
import { GrafanaTheme2, TypedVariableModel, VariableHide } from '@grafana/data';
|
|
import { selectors } from '@grafana/e2e-selectors';
|
|
import { useStyles2 } from '@grafana/ui';
|
|
|
|
import { PickerRenderer } from '../../../variables/pickers/PickerRenderer';
|
|
|
|
interface Props {
|
|
variables: TypedVariableModel[];
|
|
readOnly?: boolean;
|
|
}
|
|
|
|
export const SubMenuItems = ({ variables, readOnly }: Props) => {
|
|
const [visibleVariables, setVisibleVariables] = useState<TypedVariableModel[]>([]);
|
|
const styles = useStyles2(getStyles);
|
|
|
|
useEffect(() => {
|
|
setVisibleVariables(variables.filter((state) => state.hide !== VariableHide.hideVariable));
|
|
}, [variables]);
|
|
|
|
if (visibleVariables.length === 0) {
|
|
return null;
|
|
}
|
|
|
|
return (
|
|
<>
|
|
{visibleVariables.map((variable) => (
|
|
<div
|
|
key={variable.id}
|
|
className={styles.submenuItem}
|
|
data-testid={selectors.pages.Dashboard.SubMenu.submenuItem}
|
|
>
|
|
<PickerRenderer variable={variable} readOnly={readOnly} />
|
|
</div>
|
|
))}
|
|
</>
|
|
);
|
|
};
|
|
|
|
const getStyles = (theme: GrafanaTheme2) => ({
|
|
submenuItem: css({
|
|
display: 'inline-block',
|
|
|
|
'.fa-caret-down': {
|
|
fontSize: '75%',
|
|
paddingLeft: theme.spacing(1),
|
|
},
|
|
|
|
'.gf-form': {
|
|
marginBottom: 0,
|
|
},
|
|
}),
|
|
});
|