import { css } from '@emotion/css'; import { useEffect, useState } from 'react'; import { GrafanaTheme2, OrgRole, TimeZone, dateTimeFormat } from '@grafana/data'; import { Label, TextLink, useStyles2 } from '@grafana/ui'; import { fetchRoleOptions } from 'app/core/components/RolePicker/api'; import { contextSrv } from 'app/core/core'; import { AccessControlAction, Role, ServiceAccountDTO } from 'app/types'; import { ServiceAccountProfileRow } from './ServiceAccountProfileRow'; import { ServiceAccountRoleRow } from './ServiceAccountRoleRow'; interface Props { serviceAccount: ServiceAccountDTO; timeZone: TimeZone; onChange: (serviceAccount: ServiceAccountDTO) => void; } export function ServiceAccountProfile({ serviceAccount, timeZone, onChange }: Props): JSX.Element { const styles = useStyles2(getStyles); const ableToWrite = contextSrv.hasPermission(AccessControlAction.ServiceAccountsWrite); const [roles, setRoleOptions] = useState([]); const onRoleChange = (role: OrgRole) => { onChange({ ...serviceAccount, role: role }); }; const onNameChange = (newValue: string) => { onChange({ ...serviceAccount, name: newValue }); }; useEffect(() => { async function fetchOptions() { try { if (contextSrv.hasPermission(AccessControlAction.ActionRolesList)) { let options = await fetchRoleOptions(serviceAccount.orgId); setRoleOptions(options); } } catch (e) { console.error('Error loading options for service account'); } } if (contextSrv.licensedAccessControlEnabled()) { fetchOptions(); } }, [serviceAccount.orgId]); return (

Information

{serviceAccount.id && ( )} {serviceAccount.isExternal && serviceAccount.requiredBy && ( )}
{serviceAccount.requiredBy}
); } export const getStyles = (theme: GrafanaTheme2) => ({ section: css({ marginBottom: theme.spacing(4), }), });