-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add user group modal #1673
Add user group modal #1673
Conversation
bd704cf
to
c1ac030
Compare
@@ -86,7 +122,7 @@ const UserGroupsTable: React.FunctionComponent = () => { | |||
group.roleCount, | |||
group.workspaces || '?', // not currently in API | |||
formatDistanceToNow(new Date(group.modified), { addSuffix: true }), | |||
{ | |||
enableActions && { | |||
cell: <ActionsColumn items={ROW_ACTIONS} />, | |||
props: { isActionCell: true }, | |||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@CodyWMitchell you can also pass ID to the rows like so
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 },
},
],
}));
this way you can get rid of the useEffect, you can use the ID in matchOption
, and the add modal can receive just a list of IDs that will be sent to the API
const selectedUsernames = selectedUsers.map((user) => ({username: user[0]})); // TODO: fix - this seems gross | ||
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't get 404 locally, but I got 400 - we should not try to update system roles, these have to be excluded from the list. Please, let me know if you still have issues figuring that out
affc69f
to
8ed12b1
Compare
title={'Add to user group'} | ||
isOpen={isOpen} | ||
onClose={handleCloseModal} | ||
actions={[ | ||
<Button key="add" variant="primary" onClick={handleAddUsers} isDisabled={selectedGroups.length === 0}> | ||
Add | ||
</Button>, | ||
<Button key="cancel" variant="link" onClick={handleCloseModal}> | ||
Cancel | ||
</Button>, | ||
]} | ||
ouiaId={'add-user-group-modal'} | ||
> | ||
Select a user group to add{' '} | ||
<span className="pf-v5-u-font-weight-bold"> | ||
{selectedUsers.length} user{selectedUsers.length > 1 && 's'}{' '} | ||
</span> | ||
to. These are all the user groups in your account. To manage user groups, go to user groups. | ||
<UserGroupsTable | ||
defaultPerPage={10} | ||
useUrlParams={false} | ||
ouiaId="iam-add-users-modal-table" | ||
onChange={handleUserGroupsChange} | ||
enableActions={false} | ||
/> | ||
</Modal> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the strings should be localized
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because this is dynamic, I'm not sure the best way to localize it:
Select a user group to add{' '}
<span className="pf-v5-u-font-weight-bold">
{selectedUsers.length} user{selectedUsers.length > 1 && 's'}{' '}
</span>
to. These are all the user groups in your account. To manage user groups, go to user groups.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is a similar use case present in remove-group-service-accounts.tsx
<FormattedMessage
{...messages.removeServiceAccountsText}
values={{
b: (text) => <b>{text}</b>,
count: accountsCount,
name: selectedServiceAccounts[0]?.name,
group: group.name,
}}
/>
Let me know if you have more questions 🙂
if (onChange) { | ||
onChange(selected); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (onChange) { | |
onChange(selected); | |
} | |
onChange?.(selected); |
<span>{group.description.length > 23 ? group.description.slice(0, 20) + '...' : group.description}</span> | ||
</Tooltip> | ||
) : ( | ||
<div className="pf-v5-u-color-400">No description</div> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be localized
user.is_active ? 'Active' : 'Inactive', | ||
user.is_org_admin ? 'Yes' : 'No', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
^^
isDisabled={selected.length === 0} | ||
ouiaId={`${OUIA_ID}-add-user-button`} | ||
> | ||
Add to user group |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
^^
@CodyWMitchell looks great, can you please add a simple cypress tests checking that the new modal works? |
{intl.formatMessage(messages['usersAndUserGroupsCancel'])} | ||
</Button>, | ||
]} | ||
ouiaId={'add-user-group-modal'} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ouiaId={'add-user-group-modal'} | |
ouiaId="add-user-group-modal" |
Select a user group to add{' '} | ||
<span className="pf-v5-u-font-weight-bold"> | ||
{selectedUsers.length} user{selectedUsers.length > 1 && 's'}{' '} | ||
</span> | ||
to. These are all the user groups in your account. To manage user groups, go to user groups. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one can be localized using FormattedMessage
{ title: 'Add to user group', onClick: () => onAddUserClick([user]) }, | ||
{ title: 'Remove from user group', onClick: () => console.log('REMOVE FROM USER GROUP') }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs to be localized
Just found two more strings, it looks great! |
95cc2bf
to
de85942
Compare
de85942
to
0112379
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Description
Creates Add to user group modal that can be triggered by selecting rows and clicking "Add to user group" button or by selecting "Add to user group" in the action menu for a row. Inactive users cannot be added to user groups.
Modal reuses the existing
UserGroupsTable
component.RHCLOUD-34262
Screenshots
Checklist ☑️