feat: [UIE-8140] - IAM RBAC - Assign New Roles drawer update#11834
feat: [UIE-8140] - IAM RBAC - Assign New Roles drawer update#11834cpathipa merged 9 commits intolinode:developfrom
Conversation
jaalah-akamai
left a comment
There was a problem hiding this comment.
@rodonnel-akamai I tried to explain things as thoroughly as I could this time around since you've asked. There may be some gaps in what I suggested, but read our docs and look at some other examples already in IAM. Happy to clarify any questions! 👍
There was a problem hiding this comment.
We're going to want to refactor this to use React Hook Form so a lot of this is going to change.
Essentially, you'll want to do something like:
const form = useForm<AssignNewRoleFormValues>({
defaultValues: {
roles: [{ role: null }],
},
});
// shared/utilities
export interface AssignNewRoleFormValues {
roles: {
role: RolesType | null;
}[];
}
There was a problem hiding this comment.
Removing roles will be handled by remove handler provided by RHF
const { control, handleSubmit, watch, reset } = form;
const { append, fields, remove } = useFieldArray({
control,
name: 'roles',
});
// We want to watch changes to this value since we're conditionally rendering "Add another role"
const roles = watch('roles');
There was a problem hiding this comment.
Now that we're getting the roles from our RHF fields, this will have to change:
fields.map((field, index) => (
<AssignSingleRole
index={index}
key={field.id}
onRemove={() => remove(index)}
options={allRoles}
permissions={accountPermissions}
selectedOption={field.role}
/>
))}
There was a problem hiding this comment.
Use values from RHF
values.roles.map((r) => r.role).filter(Boolean)
There was a problem hiding this comment.
Use the roles that we're watching:
{roles.length > 0 && roles.every((field) => field.role) && (
There was a problem hiding this comment.
We can use the built in append:
<LinkButton onClick={() => append({ role: null })}>
There was a problem hiding this comment.
There will no need for selectedOption anymore with RHF
There was a problem hiding this comment.
We can just inline this now that things are simpler:
<AssignedPermissionsPanel
role={getRoleByName(permissions, value.value)}
/>
There was a problem hiding this comment.
In addition, we'll need to pass down the control via context:
const { control } = useFormContext<AssignNewRoleFormValues>();
There was a problem hiding this comment.
We'll need to wrap this in a Controller from RHF so that it can update the parent fields:
<Controller
render={({ field: { onChange, value } }) => (
<>
<Autocomplete
onChange={(event, newValue) => {
onChange(newValue);
}}
renderOption={(props, option) => (
<li {...props} key={option.label}>
{option.label}
</li>
)}
label="Assign New Roles"
options={options}
placeholder="Select a Role"
textFieldProps={{ hideLabel: true }}
value={value || null}
/>
{value && (
<AssignedPermissionsPanel
role={getRoleByName(permissions, value.value)}
/>
)}
</>
)}
control={control}
name={`roles.${index}.role`}
/>
There was a problem hiding this comment.
Same thing with spacing tokens
There was a problem hiding this comment.
I'd petition UX to revisit having an X button that's always disabled rather than just not showing it. Less code, cleaner, and better accessibility.
packages/manager/src/features/IAM/Users/UserRoles/AssignNewRoleDrawer.tsx
Outdated
Show resolved
Hide resolved
packages/manager/.changeset/pr-11834-upcoming-features-1741795011556.md
Outdated
Show resolved
Hide resolved
packages/manager/src/features/IAM/Users/UserRoles/AssignSingleRole.tsx
Outdated
Show resolved
Hide resolved
dwiley-akamai
left a comment
There was a problem hiding this comment.
Do you have the ESLint extension on the IDE you are using?
There was a problem hiding this comment.
| display={'flex'} | |
| flexDirection={'column'} | |
| display="flex" | |
| flexDirection="column" |
There was a problem hiding this comment.
| <Divider | |
| sx={(theme) => ({ | |
| marginBottom: theme.spacing(1.5), | |
| })} | |
| ></Divider> | |
| <Divider | |
| sx={(theme) => ({ | |
| marginBottom: theme.spacing(1.5), | |
| })} | |
| /> |
76e4605 to
41bceb9
Compare
|
@jaalah-akamai thanks a lot for such a detailed explanation - it helped a lot! I’ve updated this PR according to your comments. |
cpathipa
left a comment
There was a problem hiding this comment.
@aaleksee-akamai This looks much better now. Thank you for addressing the feedback.
|
Coverage Report: ✅ |
41bceb9 to
ba507a1
Compare
ba507a1 to
9066886
Compare
|
@cpathipa , I've resolved conflicts |
Cloud Manager UI test results🎉 533 passing tests on test run #11 ↗︎
|
…11834) * UIE-8140: Assign New Roles drawer update * Added changeset: Adding in the functionality behind the Assign New Roles drawer for a single user in IAM * fix with using FormProvider * resolve conflicts and update the drawer for changing role --------- Co-authored-by: Anastasiia Alekseenko <aaleksee@akamai.com> Co-authored-by: cpathipa <119517080+cpathipa@users.noreply.github.com>
Description 📝
Adding in the functionality behind the Assign New Roles drawer for a single user
Changes 🔄
List any change(s) relevant to the reviewer.
Does not include (will be introduced in a future PR - TODO are listed in code):
Target release date 🗓️
(dev)
Preview 📷
Include a screenshot or screen recording of the change.
🔒 Use the Mask Sensitive Data setting for security.
💡 Use
<video src="" />tag when including recordings in table.How to test 🧪
Prerequisites
(How to setup test environment)
Verification steps
(How to verify changes)
Author Checklists
As an Author, to speed up the review process, I considered 🤔
👀 Doing a self review
❔ Our contribution guidelines
🤏 Splitting feature into small PRs
➕ Adding a changeset
🧪 Providing/improving test coverage
🔐 Removing all sensitive information from the code and PR description
🚩 Using a feature flag to protect the release
👣 Providing comprehensive reproduction steps
📑 Providing or updating our documentation
🕛 Scheduling a pair reviewing session
📱 Providing mobile support
♿ Providing accessibility support
As an Author, before moving this PR from Draft to Open, I confirmed ✅