From 816d70a7e5fa930a7833d694b0e5af3d3785a16a Mon Sep 17 00:00:00 2001 From: kay delaney <45561153+kaydelaney@users.noreply.github.com> Date: Fri, 1 Oct 2021 15:58:18 +0100 Subject: [PATCH] A11y: Fix fastpass issues for /org/ pages (#39902) * A11y: Fix fastpass issues for /org/ pages See #39429 --- .../grafana-ui/src/components/Modal/Modal.tsx | 2 +- public/app/features/api-keys/ApiKeysForm.tsx | 52 ++++++++++--------- .../features/api-keys/ApiKeysPage.test.tsx | 9 ++-- public/app/features/api-keys/ApiKeysTable.tsx | 2 +- public/app/features/org/OrgProfile.tsx | 2 +- public/app/features/org/UserInviteForm.tsx | 2 +- 6 files changed, 35 insertions(+), 34 deletions(-) diff --git a/packages/grafana-ui/src/components/Modal/Modal.tsx b/packages/grafana-ui/src/components/Modal/Modal.tsx index 1b14fb2ffd9..bdc734687d1 100644 --- a/packages/grafana-ui/src/components/Modal/Modal.tsx +++ b/packages/grafana-ui/src/components/Modal/Modal.tsx @@ -80,7 +80,7 @@ export function Modal(props: PropsWithChildren) { {typeof title === 'string' && } {typeof title !== 'string' && title}
- +
{children}
diff --git a/public/app/features/api-keys/ApiKeysForm.tsx b/public/app/features/api-keys/ApiKeysForm.tsx index 2238aec269c..9ad93b70f2a 100644 --- a/public/app/features/api-keys/ApiKeysForm.tsx +++ b/public/app/features/api-keys/ApiKeysForm.tsx @@ -1,11 +1,15 @@ import React, { ChangeEvent, FC, FormEvent, useEffect, useState } from 'react'; -import { EventsWithValidation, InlineFormLabel, LegacyForms, ValidationEvents, Button } from '@grafana/ui'; +import { EventsWithValidation, LegacyForms, ValidationEvents, Button, Select, InlineField } from '@grafana/ui'; import { NewApiKey, OrgRole } from '../../types'; -import { rangeUtil } from '@grafana/data'; +import { rangeUtil, SelectableValue } from '@grafana/data'; import { SlideDown } from '../../core/components/Animations/SlideDown'; import { CloseButton } from 'app/core/components/CloseButton/CloseButton'; const { Input } = LegacyForms; +const ROLE_OPTIONS: Array> = Object.keys(OrgRole).map((role) => ({ + label: role, + value: role as OrgRole, +})); interface Props { show: boolean; @@ -56,8 +60,8 @@ export const ApiKeysForm: FC = ({ show, onClose, onKeyAdded }) => { const onNameChange = (event: ChangeEvent) => { setName(event.currentTarget.value); }; - const onRoleChange = (event: ChangeEvent) => { - setRole(event.currentTarget.value as OrgRole); + const onRoleChange = (role: SelectableValue) => { + setRole(role.value!); }; const onSecondsToLiveChange = (event: ChangeEvent) => { setSecondsToLive(event.currentTarget.value); @@ -75,29 +79,27 @@ export const ApiKeysForm: FC = ({ show, onClose, onKeyAdded }) => {
- Role - - - + + + + +
diff --git a/public/app/features/api-keys/ApiKeysPage.test.tsx b/public/app/features/api-keys/ApiKeysPage.test.tsx index d81cc7a0511..08327546f93 100644 --- a/public/app/features/api-keys/ApiKeysPage.test.tsx +++ b/public/app/features/api-keys/ApiKeysPage.test.tsx @@ -124,8 +124,8 @@ describe('ApiKeysPage', () => { deleteApiKeyMock.mockClear(); expect(within(firstRow).getByRole('cell', { name: /cancel delete/i })).toBeInTheDocument(); userEvent.click(within(firstRow).getByRole('cell', { name: /cancel delete/i })); - expect(within(firstRow).getByRole('button', { name: /delete/i })).toBeInTheDocument(); - userEvent.click(within(firstRow).getByRole('button', { name: /delete/i })); + expect(within(firstRow).getByRole('button', { name: /delete$/i })).toBeInTheDocument(); + userEvent.click(within(firstRow).getByRole('button', { name: /delete$/i })); expect(deleteApiKeyMock).toHaveBeenCalledTimes(1); expect(deleteApiKeyMock).toHaveBeenCalledWith(1, false); @@ -134,8 +134,8 @@ describe('ApiKeysPage', () => { deleteApiKeyMock.mockClear(); expect(within(secondRow).getByRole('cell', { name: /cancel delete/i })).toBeInTheDocument(); userEvent.click(within(secondRow).getByRole('cell', { name: /cancel delete/i })); - expect(within(secondRow).getByRole('button', { name: /delete/i })).toBeInTheDocument(); - userEvent.click(within(secondRow).getByRole('button', { name: /delete/i })); + expect(within(secondRow).getByRole('button', { name: /delete$/i })).toBeInTheDocument(); + userEvent.click(within(secondRow).getByRole('button', { name: /delete$/i })); expect(deleteApiKeyMock).toHaveBeenCalledTimes(1); expect(deleteApiKeyMock).toHaveBeenCalledWith(2, true); }); @@ -194,7 +194,6 @@ function toggleShowExpired() { async function addAndVerifyApiKey(addApiKeyMock: jest.Mock, includeExpired: boolean) { expect(screen.getByRole('heading', { name: /add api key/i })).toBeInTheDocument(); expect(screen.getByPlaceholderText(/name/i)).toBeInTheDocument(); - expect(screen.getByRole('combobox')).toBeInTheDocument(); expect(screen.getByPlaceholderText(/1d/i)).toBeInTheDocument(); expect(screen.getByRole('button', { name: /^add$/i })).toBeInTheDocument(); diff --git a/public/app/features/api-keys/ApiKeysTable.tsx b/public/app/features/api-keys/ApiKeysTable.tsx index 56203850d87..0f1e519ad0b 100644 --- a/public/app/features/api-keys/ApiKeysTable.tsx +++ b/public/app/features/api-keys/ApiKeysTable.tsx @@ -30,7 +30,7 @@ export const ApiKeysTable: FC = ({ apiKeys, timeZone, onDelete }) => { {key.role} {formatDate(key.expiration, timeZone)} - onDelete(key)} /> + onDelete(key)} /> ); diff --git a/public/app/features/org/OrgProfile.tsx b/public/app/features/org/OrgProfile.tsx index d649348eaaa..7554a3e5465 100644 --- a/public/app/features/org/OrgProfile.tsx +++ b/public/app/features/org/OrgProfile.tsx @@ -16,7 +16,7 @@ const OrgProfile: FC = ({ onSubmit, orgName }) => { {({ register }) => (
- + diff --git a/public/app/features/org/UserInviteForm.tsx b/public/app/features/org/UserInviteForm.tsx index 1efdc485422..e85918c9d72 100644 --- a/public/app/features/org/UserInviteForm.tsx +++ b/public/app/features/org/UserInviteForm.tsx @@ -72,7 +72,7 @@ export const UserInviteForm: FC = ({}) => { /> - +