SubMenuItems.tsx 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import React, { FunctionComponent, useEffect, useState } from 'react';
  2. import { selectors } from '@grafana/e2e-selectors';
  3. import { PickerRenderer } from '../../../variables/pickers/PickerRenderer';
  4. import { VariableHide, VariableModel } from '../../../variables/types';
  5. interface Props {
  6. variables: VariableModel[];
  7. }
  8. export const SubMenuItems: FunctionComponent<Props> = ({ variables }) => {
  9. const [visibleVariables, setVisibleVariables] = useState<VariableModel[]>([]);
  10. useEffect(() => {
  11. setVisibleVariables(variables.filter((state) => state.hide !== VariableHide.hideVariable));
  12. }, [variables]);
  13. if (visibleVariables.length === 0) {
  14. return null;
  15. }
  16. return (
  17. <>
  18. {visibleVariables.map((variable) => {
  19. return (
  20. <div
  21. key={variable.id}
  22. className="submenu-item gf-form-inline"
  23. data-testid={selectors.pages.Dashboard.SubMenu.submenuItem}
  24. >
  25. <PickerRenderer variable={variable} />
  26. </div>
  27. );
  28. })}
  29. </>
  30. );
  31. };