-
Notifications
You must be signed in to change notification settings - Fork 371
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: [M3-6757] - Create VPC page #9537
Conversation
const validateVPCSubnets = () => { | ||
const validatedSubnets = validateSubnets(values.subnets, { | ||
labelError: | ||
'Label is required. Must only be ASCII letters, numbers, and dashes', | ||
ipv4Error: 'The IPv4 range must be in CIDR format', | ||
}); | ||
|
||
if ( | ||
validatedSubnets.some( | ||
(subnet) => subnet.labelError || subnet.ip.ipv4Error | ||
) | ||
) { | ||
setFieldValue('subnets', validatedSubnets); | ||
return false; | ||
} else { | ||
setFieldValue( | ||
'subnets', | ||
validatedSubnets.map((subnet) => { | ||
delete subnet.labelError; | ||
delete subnet.ip.ipv4Error; | ||
return { ...subnet }; | ||
}) | ||
); | ||
return 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.
This method is pretty similar to the validateIP method in DatabaseCreate -- I'm not the biggest fan of this validation outside of using the createVPCSchema, but was having trouble trying to parse through the errors returned from the schema. Playing around with this on my branch create-vpc-offshoot1, but it's messy rn
update: see coliu-akamai#1!
export const determineIPType = (ip: string) => { | ||
try { | ||
let addr; | ||
const [, mask] = ip.split('/'); | ||
if (mask) { | ||
const parsed = ipaddr.parseCIDR(ip); | ||
addr = parsed[0]; | ||
} else { | ||
addr = ipaddr.parse(ip); | ||
} | ||
return addr.kind(); | ||
} catch (e) { | ||
return undefined; | ||
} | ||
}; | ||
|
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.
moved this functionality outside of vpcsValidateIP and into its own function in order to be able to determine ip type for calculating the number of available ipv4s of a subnet mask
// janky solution to enable SubnetNode to be an independent component or be part of MultipleSubnetInput | ||
// (not the biggest fan tbh) | ||
onChange: ( | ||
subnet: SubnetFieldState, | ||
subnetIdx?: number, | ||
remove?: boolean | ||
) => void; | ||
removable?: boolean; |
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.
Trying to make SubnetNode its own component in order for it to have future use cases (like the edit/create Subnet drawers), but that led to packing the onChange method with some parameters that wouldn't be necessary (and some props, like removable) if this file was combined with MultiplleSubnetInput.tsx. The MultipleSubnetInput.tsx functionality is otherwise along the same idea as the MultipleIpInput component
onChange={(subnet, subnetIdx, removable) => | ||
handleSubnetChange(subnet, subnetIdx ?? 0, !!removable) | ||
} |
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.
see comment at SubnetNode.tsx
9da3ba2
to
2ebdafd
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.
The UI is looking solid so far and I was able to create a VPC successfully 🎉
I still have a lot of code to comb through but I left some initial comments. Will be sure to dedicate some time tomorrow to looking at this more thoroughly.
Second version of validation here: coliu-akamai#1 |
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.
Can we display general API errors and scroll errors into view as well? You can see this error by trying to create a VPC on the prod env
Screen.Recording.2023-08-17.at.4.17.25.PM.mov
@dwiley-akamai not sure why I'm not seeing the sort-imports and related suggestions, but I ran eslint on all the VPC related files which reorganized them all |
Co-authored-by: Hana Xu <115299789+hana-linode@users.noreply.github.com>
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.
Great work! I'm in favor of rolling with the validation in this PR as opposed to the one on the other branch given the drawbacks of that other approach.
packages/validation/.changeset/pr-9537-changed-1692640036055.md
Outdated
Show resolved
Hide resolved
Co-authored-by: Dajahi Wiley <114682940+dwiley-akamai@users.noreply.github.com>
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.
@hana-linode nice catch, thanks! It's probably gonna be a change to line 114 on VPCCreate --> fixed! ty :D |
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.
Awesome work! 🚀 🚀
Unsure why the Banks-bot is saying this is not approved, but will be merging now since two approvals |
* add landing header for vpc create * initial page layout, still need all the logic + more styling * the form persists :o * tiny bit of styling (honestly should wait til the end to do this) * form logic * mock service worker * some unit tests, calculating subnet * test updates * add multipleSubnetInput wrapper (may potentially undo) * unnecessary divider in v2 of subnet inputs * there's a lot of issues with validation * updated validation * update diabled factors * Added changeset: VPC Create page * fix failing vpc create tests * address feedback * address feedback (+ dev account working now :D) * fix failing tests after scrollErrorIntoView * address feedback, update tests * subnet ip default value * default subnet ip value when adding new subnets too * eslint and move constant to utility file * Update packages/manager/src/features/VPC/VPCCreate/VPCCreate.tsx Co-authored-by: Hana Xu <115299789+hana-linode@users.noreply.github.com> * Update packages/validation/.changeset/pr-9537-changed-1692640036055.md Co-authored-by: Dajahi Wiley <114682940+dwiley-akamai@users.noreply.github.com> * feedback + starting some tests * finish tests + update availIPv4 state location due to react key entry * make subnet errors show up @hana-linode --------- Co-authored-by: Hana Xu <115299789+hana-linode@users.noreply.github.com> Co-authored-by: Dajahi Wiley <114682940+dwiley-akamai@users.noreply.github.com>
* add landing header for vpc create * initial page layout, still need all the logic + more styling * the form persists :o * tiny bit of styling (honestly should wait til the end to do this) * form logic * mock service worker * some unit tests, calculating subnet * test updates * add multipleSubnetInput wrapper (may potentially undo) * unnecessary divider in v2 of subnet inputs * there's a lot of issues with validation * updated validation * update diabled factors * Added changeset: VPC Create page * fix failing vpc create tests * address feedback * address feedback (+ dev account working now :D) * fix failing tests after scrollErrorIntoView * address feedback, update tests * subnet ip default value * default subnet ip value when adding new subnets too * eslint and move constant to utility file * Update packages/manager/src/features/VPC/VPCCreate/VPCCreate.tsx Co-authored-by: Hana Xu <115299789+hana-linode@users.noreply.github.com> * Update packages/validation/.changeset/pr-9537-changed-1692640036055.md Co-authored-by: Dajahi Wiley <114682940+dwiley-akamai@users.noreply.github.com> * feedback + starting some tests * finish tests + update availIPv4 state location due to react key entry * make subnet errors show up @hana-linode --------- Co-authored-by: Hana Xu <115299789+hana-linode@users.noreply.github.com> Co-authored-by: Dajahi Wiley <114682940+dwiley-akamai@users.noreply.github.com>
Description 📝
Preview 📷
How to test 🧪
yarn test VPCCreate
yarn test subnets.test.ts