import { useMemo } from 'react'; import { Avatar, CellProps, Column, FetchDataFunc, Icon, InteractiveTable, LinkButton, Pagination, Stack, Tag, Text, TextLink, Tooltip, } from '@grafana/ui'; import { TagBadge } from 'app/core/components/TagFilter/TagBadge'; import { Trans } from 'app/core/internationalization'; import { UserDTO } from 'app/types'; import { OrgUnits } from './OrgUnits'; type Cell = CellProps; export interface UsersTableProps { users: UserDTO[]; showPaging?: boolean; totalPages: number; onChangePage: (page: number) => void; currentPage: number; fetchData?: FetchDataFunc; } export const UsersTable = ({ users, showPaging, totalPages, onChangePage, currentPage, fetchData, }: UsersTableProps) => { const showLicensedRole = useMemo(() => users.some((user) => user.licensedRole), [users]); const showBelongsTo = useMemo(() => users.some((user) => user.orgs), [users]); const columns: Array> = useMemo( () => [ { id: 'avatarUrl', header: '', cell: ({ cell: { value } }: Cell<'avatarUrl'>) => value && , }, { id: 'login', header: 'Login', cell: ({ row: { original } }: Cell<'login'>) => { return ( {original.login} ); }, sortType: 'string', }, { id: 'email', header: 'Email', cell: ({ cell: { value } }: Cell<'email'>) => value, sortType: 'string', }, { id: 'name', header: 'Name', cell: ({ cell: { value } }: Cell<'name'>) => value, sortType: 'string', }, ...(showBelongsTo ? [ { id: 'orgs', header: 'Belongs to', cell: ({ cell: { value, row } }: Cell<'orgs'>) => { return ( {row.original.isAdmin && ( )} ); }, }, ] : []), ...(showLicensedRole ? [ { id: 'licensedRole', header: 'Licensed role', cell: ({ cell: { value } }: Cell<'licensedRole'>) => { return value === 'None' ? ( Not assigned ) : ( value ); }, }, ] : []), { id: 'lastSeenAtAge', header: 'Last active', headerTooltip: { content: 'Time since user was seen using Grafana', iconName: 'question-circle', }, cell: ({ cell: { value } }: Cell<'lastSeenAtAge'>) => { return ( <> {value && ( <> {value === '10 years' ? ( Never ) : ( value )} )} ); }, sortType: (a, b) => new Date(a.original.lastSeenAt!).getTime() - new Date(b.original.lastSeenAt!).getTime(), }, { id: 'authLabels', header: 'Origin', cell: ({ cell: { value } }: Cell<'authLabels'>) => ( <>{Array.isArray(value) && value.length > 0 && } ), }, { id: 'isDisabled', header: '', cell: ({ cell: { value } }: Cell<'isDisabled'>) => <>{value && }, }, { id: 'edit', header: '', cell: ({ row: { original } }: Cell) => { return ( ); }, }, ], [showLicensedRole, showBelongsTo] ); return ( String(user.id)} fetchData={fetchData} /> {showPaging && ( )} ); };