import { cx } from '@emotion/css'; import React, { memo } from 'react'; import { OrgRole } from '@grafana/data'; import { Button, Icon, useStyles2 } from '@grafana/ui'; import { UserRolePicker } from 'app/core/components/RolePicker/UserRolePicker'; import { contextSrv } from 'app/core/core'; import { AccessControlAction, Role, ServiceAccountDTO } from 'app/types'; import { OrgRolePicker } from '../admin/OrgRolePicker'; import { getStyles } from './ServiceAccountsListPage'; type ServiceAccountListItemProps = { serviceAccount: ServiceAccountDTO; onRoleChange: (role: OrgRole, serviceAccount: ServiceAccountDTO) => 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 displayRolePicker = contextSrv.hasPermission(AccessControlAction.ActionRolesList) && contextSrv.hasPermission(AccessControlAction.ActionUserRolesList); const enableRolePicker = contextSrv.hasPermission(AccessControlAction.OrgUsersWrite) && canUpdateRole; return ( {`Avatar {serviceAccount.name} {serviceAccount.login} {contextSrv.licensedAccessControlEnabled() ? ( {displayRolePicker && ( onRoleChange(newRole, serviceAccount)} roleOptions={roleOptions} builtInRoles={builtInRoles} disabled={!enableRolePicker} /> )} ) : ( onRoleChange(newRole, serviceAccount)} /> )} {getServiceAccountsEnabledStatus(serviceAccount.isDisabled)}   {serviceAccount.tokens} {contextSrv.hasPermissionInMetadata(AccessControlAction.ServiceAccountsDelete, serviceAccount) && (