Skip to content

Commit

Permalink
define ids for user and user group rows
Browse files Browse the repository at this point in the history
  • Loading branch information
CodyWMitchell committed Oct 18, 2024
1 parent f09db10 commit 9f68118
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 39 deletions.
6 changes: 3 additions & 3 deletions src/smart-components/access-management/AddUserGroupModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ export const AddUserGroupModal: React.FunctionComponent<AddUserGroupModalProps>
const handleCloseModal = () => setIsOpen(false);

const handleAddUsers = () => {
const selectedUsernames = selectedUsers.map((user) => ({username: user[0]})); // TODO: fix - this seems gross
const selectedUsernames = selectedUsers.map((user) => ({username: user.id}));
selectedGroups.forEach((group) => {
console.log(`Adding ${JSON.stringify(selectedUsernames)} to group ${group.name} - ${group.uuid}`);
//dispatch(addMembersToGroup(group.uuid, selectedUsernames)); // TODO: fix 'user' not found 404 error
console.log(`Adding ${JSON.stringify(selectedUsernames)} to group ${group.id}`);
//dispatch(addMembersToGroup(group.id, selectedUsernames)); // TODO: fix 'user' not found 404 error
});
setIsOpen(false);
};
Expand Down
48 changes: 25 additions & 23 deletions src/smart-components/access-management/UserGroupsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const UserGroupsTable: React.FunctionComponent<UserGroupsTableProps> = ({
}
const { page, perPage, onSetPage, onPerPageSelect } = pagination;

const selection = useDataViewSelection({ matchOption: (a, b) => a[0] === b[0] });
const selection = useDataViewSelection({ matchOption: (a, b) => a.id === b.id });
const { selected, onSelect, isSelected } = selection;

const fetchData = useCallback(
Expand All @@ -93,10 +93,9 @@ const UserGroupsTable: React.FunctionComponent<UserGroupsTableProps> = ({

useEffect(() => {
if (onChange) {
const selectedGroups = groups.filter((group) => selected.some((s) => s[0] === group.name)); // TODO: need better way to handle this :(
onChange(selectedGroups);
onChange(selected);
}
}, [selected, groups]);
}, [selected]);

const handleBulkSelect = (value: BulkSelectValue) => {
if (value === BulkSelectValue.none) {
Expand All @@ -108,25 +107,28 @@ const UserGroupsTable: React.FunctionComponent<UserGroupsTableProps> = ({
}
};

const rows = groups.map((group: any) => [
group.name,
group.description ? (
<Tooltip isContentLeftAligned content={group.description}>
<span>{group.description.length > 23 ? group.description.slice(0, 20) + '...' : group.description}</span>
</Tooltip>
) : (
<div className="pf-v5-u-color-400">No description</div>
),
group.principalCount,
group.serviceAccounts || '?', // not currently in API
group.roleCount,
group.workspaces || '?', // not currently in API
formatDistanceToNow(new Date(group.modified), { addSuffix: true }),
enableActions && {
cell: <ActionsColumn items={ROW_ACTIONS} />,
props: { isActionCell: true },
},
]);
const rows = groups.map((group: any) => ({
id: group.uuid,
row: [
group.name,
group.description ? (
<Tooltip isContentLeftAligned content={group.description}>
<span>{group.description.length > 23 ? group.description.slice(0, 20) + '...' : group.description}</span>
</Tooltip>
) : (
<div className="pf-v5-u-color-400">No description</div>
),
group.principalCount,
group.serviceAccounts || '?', // not currently in API
group.roleCount,
group.workspaces || '?', // not currently in API
formatDistanceToNow(new Date(group.modified), { addSuffix: true }),
enableActions && {
cell: <ActionsColumn items={ROW_ACTIONS} />,
props: { isActionCell: true },
},
],
}));

const pageSelected = rows.length > 0 && rows.every(isSelected);
const pagePartiallySelected = !pageSelected && rows.some(isSelected);
Expand Down
29 changes: 16 additions & 13 deletions src/smart-components/access-management/UsersTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const UsersTable: React.FunctionComponent<UsersTableProps> = ({ onAddUserClick }
const pagination = useDataViewPagination({ perPage: 20, searchParams, setSearchParams });
const { page, perPage, onSetPage, onPerPageSelect } = pagination;

const selection = useDataViewSelection({ matchOption: (a, b) => a[0] === b[0] });
const selection = useDataViewSelection({ matchOption: (a, b) => a.id === b.id });
const { selected, onSelect, isSelected } = selection;

const fetchData = useCallback(
Expand Down Expand Up @@ -78,18 +78,21 @@ const UsersTable: React.FunctionComponent<UsersTableProps> = ({ onAddUserClick }
}
};

const rows = users.map((user: UserProps) => [
user.username,
user.email,
user.first_name,
user.last_name,
user.is_active ? 'Active' : 'Inactive',
user.is_org_admin ? 'Yes' : 'No',
{
cell: <ActionsColumn items={rowActions(user)} />,
props: { isActionCell: true },
},
]);
const rows = users.map((user: UserProps) => ({
id: user.username,
row: [
user.username,
user.email,
user.first_name,
user.last_name,
user.is_active ? 'Active' : 'Inactive',
user.is_org_admin ? 'Yes' : 'No',
{
cell: <ActionsColumn items={rowActions(user)} />,
props: { isActionCell: true },
},
],
}));

const pageSelected = rows.length > 0 && rows.every(isSelected);
const pagePartiallySelected = !pageSelected && rows.some(isSelected);
Expand Down

0 comments on commit 9f68118

Please sign in to comment.