diff --git a/public/app/features/admin/Users/UsersTable.tsx b/public/app/features/admin/Users/UsersTable.tsx index f945d818d4d..fd7cdbb6813 100644 --- a/public/app/features/admin/Users/UsersTable.tsx +++ b/public/app/features/admin/Users/UsersTable.tsx @@ -1,4 +1,5 @@ import React, { useMemo } from 'react'; +import { UseTableRowProps } from 'react-table'; import { Avatar, @@ -38,6 +39,7 @@ export const UsersTable = ({ fetchData, }: UsersTableProps) => { const showLicensedRole = useMemo(() => users.some((user) => user.licensedRole), [users]); + const showBelongsTo = useMemo(() => users.some((user) => user.orgs), [users]); const columns: Array> = useMemo( () => [ { @@ -63,23 +65,28 @@ export const UsersTable = ({ cell: ({ cell: { value } }: Cell<'name'>) => value, sortType: 'string', }, - { - id: 'orgs', - header: 'Belongs to', - cell: ({ cell: { value, row } }: Cell<'orgs'>) => { - return ( - - - {row.original.isAdmin && ( - - - - )} - - ); - }, - sortType: (a, b) => (a.original.orgs?.length || 0) - (b.original.orgs?.length || 0), - }, + ...(showBelongsTo + ? [ + { + id: 'orgs', + header: 'Belongs to', + cell: ({ cell: { value, row } }: Cell<'orgs'>) => { + return ( + + + {row.original.isAdmin && ( + + + + )} + + ); + }, + sortType: (a: UseTableRowProps, b: UseTableRowProps) => + (a.original.orgs?.length || 0) - (b.original.orgs?.length || 0), + }, + ] + : []), ...(showLicensedRole ? [ { @@ -140,7 +147,7 @@ export const UsersTable = ({ }, }, ], - [showLicensedRole] + [showLicensedRole, showBelongsTo] ); return (