import React, { FC, useEffect, useState } from 'react'; import { OrgRole } from '@grafana/data'; import { Button, ConfirmModal } from '@grafana/ui'; import { UserRolePicker } from 'app/core/components/RolePicker/UserRolePicker'; import { fetchBuiltinRoles, fetchRoleOptions } from 'app/core/components/RolePicker/api'; import { contextSrv } from 'app/core/core'; import { AccessControlAction, OrgUser, Role } from 'app/types'; import { OrgRolePicker } from '../admin/OrgRolePicker'; export interface Props { users: OrgUser[]; orgId?: number; onRoleChange: (role: OrgRole, user: OrgUser) => void; onRemoveUser: (user: OrgUser) => void; } const UsersTable: FC = (props) => { const { users, orgId, onRoleChange, onRemoveUser } = props; const [userToRemove, setUserToRemove] = useState(null); const [roleOptions, setRoleOptions] = useState([]); const [builtinRoles, setBuiltinRoles] = useState<{ [key: string]: Role[] }>({}); useEffect(() => { async function fetchOptions() { try { if (contextSrv.hasPermission(AccessControlAction.ActionRolesList)) { let options = await fetchRoleOptions(orgId); setRoleOptions(options); } if ( contextSrv.accessControlBuiltInRoleAssignmentEnabled() && contextSrv.hasPermission(AccessControlAction.ActionBuiltinRolesList) ) { const builtInRoles = await fetchBuiltinRoles(orgId); setBuiltinRoles(builtInRoles); } } catch (e) { console.error('Error loading options'); } } if (contextSrv.licensedAccessControlEnabled()) { fetchOptions(); } }, [orgId]); return ( <> {users.map((user, index) => { return ( {contextSrv.hasPermissionInMetadata(AccessControlAction.OrgUsersRemove, user) && ( )} ); })}
Login Email Name Seen Role
User avatar {user.login} {user.email} {user.name} {user.lastSeenAtAge} {contextSrv.licensedAccessControlEnabled() ? ( onRoleChange(newRole, user)} roleOptions={roleOptions} builtInRoles={builtinRoles} disabled={!contextSrv.hasPermissionInMetadata(AccessControlAction.OrgUsersWrite, user)} /> ) : ( onRoleChange(newRole, user)} /> )}
{Boolean(userToRemove) && ( { setUserToRemove(null); }} isOpen={true} onConfirm={() => { if (!userToRemove) { return; } onRemoveUser(userToRemove); setUserToRemove(null); }} /> )} ); }; export default UsersTable;