Skip to content
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

Merged

Conversation

bnussman-akamai
Copy link
Member

@bnussman-akamai bnussman-akamai commented Mar 16, 2023

Description 📝

  • Firewalls used react query but this moves firewalls away from the "fetch all" approach

How to test 🧪

  • Test all firewall create, update, delete actions
  • Test adding and removing Linodes from a Firewall
  • yarn test Firewall
  • Run migrate-linode-with-firewall.spec.ts with yarn cy:debug

@bnussman-akamai bnussman-akamai added the React Query Relating to the transition to use React Query label Mar 16, 2023
@bnussman-akamai bnussman-akamai self-assigned this Mar 16, 2023

return (
<Select
Copy link
Contributor

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?

Copy link
Member Author

@bnussman-akamai bnussman-akamai Mar 17, 2023

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

@jdamore-linode
Copy link
Contributor

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:

Old:
Screen Shot 2023-03-17 at 11 55 54 AM

New:
Screen Shot 2023-03-17 at 11 55 47 AM

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.

@jaalah-akamai
Copy link
Contributor

If we want to use the same icon as before, we can do popupIcon={<DropdownIndicator />} except we'll either have to add an sx prop to remove the marginRight or some custom class for now. The other styles should be easy to replicate 🤞

Copy link
Contributor

@jaalah-akamai jaalah-akamai left a 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!

Copy link
Contributor

@cpathipa cpathipa left a 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.

Comment on lines +66 to +110
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.'
);
});
},
Copy link
Contributor

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', () => {
Copy link
Contributor

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!

@cpathipa cpathipa added the Approved Multiple approvals and ready to merge! label Mar 22, 2023
@bnussman-akamai bnussman-akamai merged commit 4b44457 into linode:develop Mar 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Approved Multiple approvals and ready to merge! React Query Relating to the transition to use React Query
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants