From 78bdcede7042b8e855eeabdc2bc1458149757043 Mon Sep 17 00:00:00 2001 From: Eric Leijonmarck Date: Mon, 4 Apr 2022 17:09:51 +0100 Subject: [PATCH] Service accounts: polish UI and refactoring (#47269) * no other tab has title * made Add service button not visable and upper right * renaming and added space between token number * aligned button (:css:) * refactor: out component listitem * unused import --- .../ServiceAccountCreatePage.tsx | 4 +- .../serviceaccounts/ServiceAccountPage.tsx | 16 +- .../serviceaccounts/ServiceAccountProfile.tsx | 2 +- .../ServiceAccountsListItem.tsx | 127 ++++++++++++++++ .../ServiceAccountsListPage.tsx | 139 ++---------------- .../features/serviceaccounts/state/actions.ts | 2 +- 6 files changed, 151 insertions(+), 139 deletions(-) create mode 100644 public/app/features/serviceaccounts/ServiceAccountsListItem.tsx diff --git a/public/app/features/serviceaccounts/ServiceAccountCreatePage.tsx b/public/app/features/serviceaccounts/ServiceAccountCreatePage.tsx index 56a4d35b331..2e58ee1faf4 100644 --- a/public/app/features/serviceaccounts/ServiceAccountCreatePage.tsx +++ b/public/app/features/serviceaccounts/ServiceAccountCreatePage.tsx @@ -31,7 +31,7 @@ const ServiceAccountCreatePage: React.FC = ({ nav return ( -

Add new service account

+

Create service account

{({ register, errors }) => { return ( @@ -44,7 +44,7 @@ const ServiceAccountCreatePage: React.FC = ({ nav > - + ); }} diff --git a/public/app/features/serviceaccounts/ServiceAccountPage.tsx b/public/app/features/serviceaccounts/ServiceAccountPage.tsx index f3b4469ddd5..94ef57e3f5c 100644 --- a/public/app/features/serviceaccounts/ServiceAccountPage.tsx +++ b/public/app/features/serviceaccounts/ServiceAccountPage.tsx @@ -16,7 +16,7 @@ import { } from './state/actions'; import { ServiceAccountTokensTable } from './ServiceAccountTokensTable'; import { getTimeZone, NavModel } from '@grafana/data'; -import { Button, VerticalGroup } from '@grafana/ui'; +import { Button } from '@grafana/ui'; import { CreateTokenModal } from './CreateTokenModal'; import { contextSrv } from 'app/core/core'; @@ -110,13 +110,15 @@ const ServiceAccountPageUnconnected = ({ /> )} - +
+

+ Tokens +

-

Tokens

- {tokens && ( - - )} - +
+ {tokens && ( + + )} diff --git a/public/app/features/serviceaccounts/ServiceAccountProfile.tsx b/public/app/features/serviceaccounts/ServiceAccountProfile.tsx index 98df4a391a9..2c94e38b171 100644 --- a/public/app/features/serviceaccounts/ServiceAccountProfile.tsx +++ b/public/app/features/serviceaccounts/ServiceAccountProfile.tsx @@ -87,7 +87,7 @@ export function ServiceAccountProfile({ builtInRoles={builtInRoles} roleOptions={roleOptions} /> - + {/* */} void; + roleOptions: Role[]; + builtInRoles: Record; + onSetToRemove: (serviceAccount: ServiceAccountDTO) => void; +}; + +const getServiceAccountsAriaLabel = (name: string) => { + return `Edit service account's ${name} details`; +}; +const getServiceAccountsEnabledStatus = (disabled: boolean) => { + return disabled ? 'Disabled' : 'Enabled'; +}; + +const ServiceAccountListItem = memo( + ({ serviceAccount, onRoleChange, roleOptions, builtInRoles, onSetToRemove }: ServiceAccountListItemProps) => { + const editUrl = `org/serviceaccounts/${serviceAccount.id}`; + const styles = useStyles2(getStyles); + const canUpdateRole = contextSrv.hasPermissionInMetadata(AccessControlAction.ServiceAccountsWrite, serviceAccount); + const rolePickerDisabled = !canUpdateRole; + + return ( + + + + {`Avatar + + + + + {serviceAccount.name} + + + + + {serviceAccount.login} + + + + {contextSrv.licensedAccessControlEnabled() ? ( + onRoleChange(newRole, serviceAccount)} + roleOptions={roleOptions} + builtInRoles={builtInRoles} + disabled={rolePickerDisabled} + /> + ) : ( + onRoleChange(newRole, serviceAccount)} + /> + )} + + + + {getServiceAccountsEnabledStatus(serviceAccount.isDisabled)} + + + + + + + +   + {serviceAccount.tokens} + + + {contextSrv.hasPermissionInMetadata(AccessControlAction.ServiceAccountsDelete, serviceAccount) && ( + +