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

feat(subnets): Add form to reserve DHCP lease MAASENG-2975 WIP #5420

Merged
merged 13 commits into from
May 7, 2024

Conversation

ndv99
Copy link
Contributor

@ndv99 ndv99 commented Apr 26, 2024

Done

  • Created ReserveDHCPLease
  • Created PrefixedIpInput
  • Created PrefixedInput

QA steps

  • Go to /subnet/2/address-reservation (any subnet will do)
  • Click on "Reserve static DHCP lease"
  • Ensure the side panel opens to the form
  • Ensure the placeholder in the IP address field is correct
  • Ensure the help text under the IP address field is correct
  • Type in an invalid IP address and press tab
  • Ensure an appropriate error message is displayed
  • Type an out-of-range IP address for that subnet
  • Ensure the error message matches the spec
  • Paste in a valid IP address for that subnet
  • Ensure only the required octets are pasted
  • Fill out the rest of the form
  • Click "Reserve static DHCP lease"
  • Ensure nothing happens
  • Click "Cancel"
  • Ensure the side panel closes

Fixes

Fixes MAASENG-2975

Screenshots

image

Notes

PrefixedInput was initally meant to be a component added to maas-react-components, but due to some strange visual bugs that only occurred in storybook, I've decided to implement it here for now and make the upstreaming future work: https://warthogs.atlassian.net/browse/MAASENG-3113

@webteam-app
Copy link

@ndv99 ndv99 marked this pull request as ready for review April 29, 2024 11:15
Copy link
Contributor

@petermakowski petermakowski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some very good ideas, well done.

It's very likely we'll need this component in MSM at some point, have you considered adding this to maas react components?

name: string;
};

const LimitedIpInput = ({ cidr, name, ...props }: Props) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not suggesting you rewrite your implementation, just wanted to point out that there is a library that could help with this in case you weren't aware. Have you looked at it?
https://www.npmjs.com/package/react-input-mask

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've not heard of that, this could definitely be useful! My only concern is that it was last updated 4 years ago, would be nice if there was something similar that's still in active development

Comment on lines 42 to 43
setInputWrapper(document.querySelector(".limited-ip-input__input-wrapper"));
setInputElement(document.querySelector(".limited-ip-input__input"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's generally best to cache selectors and not perform lookup unnecessarily multiple times (document.querySelector).

Also, this will only work as expected if there's a single instance of LimitedIpInput component on the page at a time (lessons learnt from DynamicTable) 😉 . I'd suggest to use ref as an entry point for access and manipulation of individual DOM nodes.

Copy link
Contributor Author

@ndv99 ndv99 Apr 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only problem with using ref is that the element we're trying to access is the wrapper of the input, rather than the input itself. react-components doesn't let us pass a ref through to the wrapper, only a classname

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nvm, figured it out - we can put the ref on the top-level div that wraps everything, and then access children from there.


return (
<FormikForm<FormValues>
aria-label="Reserve static DHCP lease"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 for not forgetting about accessibility.

padding-left: $spv--small;
padding-bottom: calc(0.4rem - 1px);
padding-top: calc(0.4rem - 1px);
content: var(--immutable, "");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very interesting approach, although it makes it somewhat harder to track where the "immutable" comes from as it's hidden in JS logic. This could be also made simpler.

Have you considered using an additional hidden element in JSX encapsulating rendering logic in a single place? Similar idea is used in MainToolbar in maas-react-components: https://github.com/canonical/maas-react-components/blob/main/src/lib/sections/MainToolbar/MainToolbar.tsx#L122-L129

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After our discussion, I've created a jira ticket to investigate a replacement for this logic: https://warthogs.atlassian.net/browse/MAASENG-3116

@ndv99
Copy link
Contributor Author

ndv99 commented Apr 29, 2024

It's very likely we'll need this component in MSM at some point, have you considered adding this to maas react components?

Honestly, I wasn't sure what it could be used for there, but I'm happy to upstream it regardless. The prop types may be a little looser (e.g. cidr not coming from Subnet type) but I don't think that'll be a problem

@petermakowski
Copy link
Contributor

Honestly, I wasn't sure what it could be used for there, but I'm happy to upstream it regardless. The prop types may be a little looser (e.g. cidr not coming from Subnet type) but I don't think that'll be a problem

OK. For now let's make sure it's a little more generic (partial input/input mask logic is extracted to a separate component which is then used by LimitedIpInput). This will make it easier to extend and to move over to maas-react-components/used in a different context in the future if needed.

@ndv99
Copy link
Contributor Author

ndv99 commented Apr 29, 2024

OK. For now let's make sure it's a little more generic (partial input/input mask logic is extracted to a separate component which is then used by LimitedIpInput). This will make it easier to extend and to move over to maas-react-components/used in a different context in the future if needed.

Sounds good to me. I'll address your other comments in this new component.

@ndv99 ndv99 removed the request for review from Jay-Topher May 3, 2024 15:58
ndv99 and others added 2 commits May 7, 2024 08:33
replace .lastChild.firstChild with querySelector

Co-authored-by: Peter Makowski <[email protected]>
@petermakowski petermakowski merged commit 1bad2df into canonical:main May 7, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants