From 9c50131c2c71d15a23e0e65d07f0094b89c6ec75 Mon Sep 17 00:00:00 2001 From: Leo <108552997+lpskdl@users.noreply.github.com> Date: Fri, 7 Oct 2022 17:52:13 +0200 Subject: [PATCH] Navigation: Added organisation switcher next to grafana logo (#56361) * added org dropdown to topnav * render icon and dropdown for mobile screen * remove switch org from profile node * adjust styles to be mobile first * add test for select * hide profile node only when topnav is on * replace margin with gap instead * improve tests * add aria labels * fix broken test --- .../components/ValuePicker/ValuePicker.tsx | 13 ++- .../Organization/OrganizationPicker.tsx | 26 +++++ .../Organization/OrganizationSelect.tsx | 46 +++++++++ .../OrganizationSwitcher.test.tsx | 95 +++++++++++++++++++ .../Organization/OrganizationSwitcher.tsx | 45 +++++++++ .../AppChrome/Organization/types.ts | 7 ++ .../components/AppChrome/TopSearchBar.tsx | 4 + public/app/core/components/NavBar/utils.ts | 4 +- 8 files changed, 235 insertions(+), 5 deletions(-) create mode 100644 public/app/core/components/AppChrome/Organization/OrganizationPicker.tsx create mode 100644 public/app/core/components/AppChrome/Organization/OrganizationSelect.tsx create mode 100644 public/app/core/components/AppChrome/Organization/OrganizationSwitcher.test.tsx create mode 100644 public/app/core/components/AppChrome/Organization/OrganizationSwitcher.tsx create mode 100644 public/app/core/components/AppChrome/Organization/types.ts diff --git a/packages/grafana-ui/src/components/ValuePicker/ValuePicker.tsx b/packages/grafana-ui/src/components/ValuePicker/ValuePicker.tsx index 1f0f132a0cc..9b15d46e4da 100644 --- a/packages/grafana-ui/src/components/ValuePicker/ValuePicker.tsx +++ b/packages/grafana-ui/src/components/ValuePicker/ValuePicker.tsx @@ -6,10 +6,12 @@ import { selectors } from '@grafana/e2e-selectors'; import { useTheme2 } from '../../themes'; import { IconName } from '../../types'; import { ComponentSize } from '../../types/size'; -import { Button, ButtonVariant } from '../Button'; +import { Button, ButtonFill, ButtonVariant } from '../Button'; import { Select } from '../Select/Select'; export interface ValuePickerProps { + /** Aria label applied to the input field */ + ['aria-label']?: string; /** Label to display on the picker button */ label: string; /** Icon to display on the picker button */ @@ -28,9 +30,12 @@ export interface ValuePickerProps { isFullWidth?: boolean; /** Control where the menu is rendered */ menuPlacement?: 'auto' | 'bottom' | 'top'; + /** Which ButtonFill to use */ + fill?: ButtonFill; } export function ValuePicker({ + 'aria-label': ariaLabel, label, icon, options, @@ -40,6 +45,7 @@ export function ValuePicker({ size = 'sm', isFullWidth = true, menuPlacement, + fill, }: ValuePickerProps) { const [isPicking, setIsPicking] = useState(false); const theme = useTheme2(); @@ -52,8 +58,9 @@ export function ValuePicker({ icon={icon || 'plus'} onClick={() => setIsPicking(true)} variant={variant} + fill={fill} fullWidth={isFullWidth} - aria-label={selectors.components.ValuePicker.button(label)} + aria-label={selectors.components.ValuePicker.button(ariaLabel ?? label)} > {label} @@ -64,7 +71,7 @@ export function ValuePicker({