Skip to content

Conversation

charliepark
Copy link
Contributor

@charliepark charliepark commented Nov 8, 2024

Currently, it's possible to "create" multiple new disks with the same name in the instance create form. This is a little goofy, because the user isn't actually creating the new disks at this point in the form, they're queuing them up to be created shortly. So we have an issue where multiple matching domain names are problematic, and deleting one of those disks will end up deleting both disks.

This PR fixes that by adding validation check to the name field for disk-create, as well as a validation on the boot disk name in the instance-create form. It was already the case that an existing disk name couldn't be used for the boot disk name, but we were not checking the names of the liminal disks (set to be created, but not yet actually created). We are now.

Closes #2519

Copy link

vercel bot commented Nov 8, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
console ✅ Ready (Inspect) Visit Preview Nov 14, 2024 9:46pm

@charliepark charliepark changed the title Fix disk name issue Prevent creating multiple disks with the same name Nov 8, 2024
@charliepark
Copy link
Contributor Author

see-it-works

*/
onDismiss: (navigate: NavigateFunction) => void
onSuccess?: (disk: Disk) => void
unavailableDiskNames?: string[]
Copy link
Collaborator

Choose a reason for hiding this comment

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

I do like this a lot better without adding disks from the API in here. I'd add a comment here on the prop saying this is for client-side use-cases like the form embedded in instance create, where submitting the form does not tell you whether it's taken.

disabled={isSubmitting}
validate={(name) => {
// don't allow the user to use an existing disk name for the boot disk's name
if ([...namesOfDisksToBeCreated, ...existingDiskNames].includes(name)) {
Copy link
Collaborator

@david-crespo david-crespo Nov 14, 2024

Choose a reason for hiding this comment

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

Very small thing, but I think it would be easier to follow if this list concatenation was done next to the other disk name list logic. You can even wrap it in a function to avoid mapping over a potentially large list of disks on every render.

const otherDisks = useWatch({ control, name: 'otherDisks' })

function unavailableDiskNames() {
  const existingDiskNames = allDisks.map((disk) => disk.name)
  const namesOfDisksToBeCreated = otherDisks
    .filter((disk) => disk.type === 'create')
    .map((disk) => disk.name)
  return [...namesOfDisksToBeCreated, ...existingDiskNames]
}

Copy link
Collaborator

@david-crespo david-crespo Nov 14, 2024

Choose a reason for hiding this comment

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

Hm, actually, depending on whether every keypress causes a render, this could be worse because you're mapping on every validate. Initially I pictured this as only happening on submit, but once you're revalidating after an error, it runs on every keypress.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I just confirmed that typing in the disk name field of disk create does not render the overall form, so it is better to leave it as-is.

@david-crespo david-crespo enabled auto-merge (squash) November 14, 2024 21:46
@david-crespo david-crespo merged commit 0517a28 into main Nov 14, 2024
8 checks passed
@david-crespo david-crespo deleted the fix-disk-name-issue branch November 14, 2024 21:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Disallow duplicate disk names on instance create form
2 participants