-
Notifications
You must be signed in to change notification settings - Fork 364
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
refactor: [M3-6257] - React Query for Firewalls #8889
refactor: [M3-6257] - React Query for Firewalls #8889
Conversation
packages/manager/cypress/e2e/firewalls/migrate-linode-with-firewall.spec.ts
Outdated
Show resolved
Hide resolved
|
||
return ( | ||
<Select |
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.
Are we gradually replacing all of our multi selects with <TextField />
s wrapped in <Autocomplete />
s, or is there a specific technical need/UX convention/etc that dictates when to use one over the other?
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 moved to a <Autocomplete />
simply because it is built into MUI and is much more easy to use then our crazily abstracted EnhancedSelect component that has no type safety. I wanted to focus on the implementation of the pagination and filtering and I didn't want to fight with our "EnhancedSelect" component
Related to the question above, I'm noticing some visual differences between the old multi selects and the new auto complete text fields. The screenshots are from the Attach Volume form, but also applies to the LinodeMultiSelect: Specifically seeing differences in the placeholder text color, arrow/chevron icon on the right, size and positioning of the popper, and the selection highlight style. |
If we want to use the same icon as before, we can do |
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.
Approving pending style updates - Solid changes!
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.
Nice work! @bnussman. Overall, it looks great! I only left a comment for a minor change to improve readability.
onSubmit( | ||
values: CreateFirewallPayload, | ||
{ setSubmitting, setErrors, setStatus } | ||
) { | ||
// Clear drawer error state | ||
setStatus(undefined); | ||
setErrors({}); | ||
const payload = { ...values }; | ||
|
||
if (payload.label === '') { | ||
payload.label = undefined; | ||
} | ||
|
||
if ( | ||
Array.isArray(payload.rules.inbound) && | ||
payload.rules.inbound.length === 0 | ||
) { | ||
payload.rules.inbound = undefined; | ||
} | ||
|
||
if ( | ||
Array.isArray(payload.rules.outbound) && | ||
payload.rules.outbound.length === 0 | ||
) { | ||
payload.rules.outbound = undefined; | ||
} | ||
|
||
mutateAsync(payload) | ||
.then(() => { | ||
setSubmitting(false); | ||
onClose(); | ||
}) | ||
.catch((err) => { | ||
const mapErrorToStatus = () => | ||
setStatus({ generalError: getErrorMap([], err).none }); | ||
|
||
setSubmitting(false); | ||
handleFieldErrors(setErrors, err); | ||
handleGeneralErrors( | ||
mapErrorToStatus, | ||
err, | ||
'Error creating Firewall.' | ||
); | ||
}); | ||
}, |
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.
We can improve code readability by decoupling onSubmit logic from this code block. We could rename formikBag
and handleSubmitAsync
, I took it as example.
onSubmit: (values, formikBag) => handleSubmitAsync(values, formikBag),
const handleSubmitAsync = async (
values: any,
{ setSubmitting, setErrors, setStatus }: any
) => {
// Clear drawer error state
setStatus(undefined);
setErrors({});
const payload = { ...values };
if (payload.label === '') {
payload.label = undefined;
}
if (
Array.isArray(payload.rules.inbound) &&
payload.rules.inbound.length === 0
) {
payload.rules.inbound = undefined;
}
if (
Array.isArray(payload.rules.outbound) &&
payload.rules.outbound.length === 0
) {
payload.rules.outbound = undefined;
}
try {
await mutateAsync(payload);
setSubmitting(false);
onClose();
} catch (err) {
const mapErrorToStatus = () =>
setStatus({ generalError: getErrorMap([], err).none });
setSubmitting(false);
handleFieldErrors(setErrors, err);
handleGeneralErrors(mapErrorToStatus, err, 'Error creating Firewall.');
}
};
@@ -27,3 +27,15 @@ describe('truncateAndJoinList', () => { | |||
expect(result).toMatch(/, plus 900 more/); | |||
}); | |||
}); | |||
|
|||
describe('isNumeric', () => { |
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.
Thank you for adding test coverage!
Description 📝
How to test 🧪
migrate-linode-with-firewall.spec.ts
withyarn cy:debug