Skip to content

Commit

Permalink
show count on system groups/users and toggle users on by default
Browse files Browse the repository at this point in the history
  • Loading branch information
DaveDarsa committed Jul 8, 2024
1 parent 17843f4 commit ada3a84
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
37 changes: 31 additions & 6 deletions src/components/Organizations/PaginatedTable/PaginatedTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ import {
TableRow,
} from './Styles';

interface NestedData {
[key: string]: string | Record<string, string> | string[];
}

type DataType = {
[key: string]:
| string
| Record<string, string>
| Record<string, Pick<Props, 'data'> | string[]>
| Array<Record<string, string>>;
[key: string]: string | NestedData | Record<string, string> | Array<Record<string, string>>;
name: string;
id: string;
};
Expand Down Expand Up @@ -321,6 +321,31 @@ const PaginatedTable: FC<Props> = ({
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 (
<StyledTable className="paginatedTable">
<Filters className="filters">
Expand All @@ -333,7 +358,7 @@ const PaginatedTable: FC<Props> = ({
)}
{defaultViewOptions ? (
<Checkbox>
{defaultViewOptions.type === 'group' ? 'Show system groups' : 'Show default users'}
{defaultViewOptions.type === 'group' ? 'Show system groups' : 'Show default users'} ({systemDefaultCount})
<input
type="checkbox"
checked={defaultsSelected}
Expand Down
4 changes: 1 addition & 3 deletions src/components/Organizations/Users/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ const DELETE_USER = gql`
* The primary list of users.
*/
const Users = ({ users = [], organization, organizationId, organizationName, refetch, orgFriendlyName }) => {
const [userModalOpen, setUserModalOpen] = useState(false);
const [selectedUser, setSelectedUser] = useState('');

const [addUserModalOpen, setAddUserModalOpen] = useState(false);
Expand All @@ -52,7 +51,6 @@ const Users = ({ users = [], organization, organizationId, organizationName, ref

const closeUserModal = () => {
setSelectedUser('');
setUserModalOpen(false);
};

useEffect(() => {
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit ada3a84

Please sign in to comment.