From ada3a84e23e28e8dba10375e91f7947a7992c9bc Mon Sep 17 00:00:00 2001 From: Davit Date: Mon, 8 Jul 2024 12:04:02 +0400 Subject: [PATCH] show count on system groups/users and toggle users on by default --- .../PaginatedTable/PaginatedTable.tsx | 37 ++++++++++++++++--- src/components/Organizations/Users/index.js | 4 +- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/components/Organizations/PaginatedTable/PaginatedTable.tsx b/src/components/Organizations/PaginatedTable/PaginatedTable.tsx index 9389fc14..8643f419 100644 --- a/src/components/Organizations/PaginatedTable/PaginatedTable.tsx +++ b/src/components/Organizations/PaginatedTable/PaginatedTable.tsx @@ -17,12 +17,12 @@ import { TableRow, } from './Styles'; +interface NestedData { + [key: string]: string | Record | string[]; +} + type DataType = { - [key: string]: - | string - | Record - | Record | string[]> - | Array>; + [key: string]: string | NestedData | Record | Array>; name: string; id: string; }; @@ -321,6 +321,31 @@ const PaginatedTable: FC = ({ const startPage = Math.max(currentPage - Math.floor(maxPagination / 2), 1); const endPage = Math.min(startPage + maxPagination - 1, totalPages); + const systemDefaultCount = useMemo(() => { + let count = 0; + + if (defaultViewOptions) { + if (defaultViewOptions?.type === 'group') { + count = unfilteredData.filter(dataItem => dataItem.type === 'project-default-group').length; + } + if (defaultViewOptions?.type === 'user') { + count = unfilteredData.filter(dataItem => { + let filterItem = ''; + + if (dataItem.email) { + filterItem = dataItem.email as string; + } + if (dataItem.user && typeof dataItem.user === 'object' && 'email' in dataItem.user) { + filterItem = dataItem.user.email as string; + } + + return filterItem.startsWith('default-user'); + }).length; + } + } + return count; + }, [defaultViewOptions, unfilteredData]); + return ( @@ -333,7 +358,7 @@ const PaginatedTable: FC = ({ )} {defaultViewOptions ? ( - {defaultViewOptions.type === 'group' ? 'Show system groups' : 'Show default users'} + {defaultViewOptions.type === 'group' ? 'Show system groups' : 'Show default users'} ({systemDefaultCount}) { - const [userModalOpen, setUserModalOpen] = useState(false); const [selectedUser, setSelectedUser] = useState(''); const [addUserModalOpen, setAddUserModalOpen] = useState(false); @@ -52,7 +51,6 @@ const Users = ({ users = [], organization, organizationId, organizationName, ref const closeUserModal = () => { setSelectedUser(''); - setUserModalOpen(false); }; useEffect(() => { @@ -201,7 +199,7 @@ const Users = ({ users = [], organization, organizationId, organizationName, ref usersTable={true} defaultViewOptions={{ type: 'user', - selected: false, + selected: true, }} labelText="Users" emptyText="No Users"