Skip to content

Commit

Permalink
fix bug in IPv6 block field
Browse files Browse the repository at this point in the history
  • Loading branch information
david-crespo committed Aug 22, 2024
1 parent b4bab07 commit 76bf329
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
17 changes: 10 additions & 7 deletions app/forms/subnet-create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* Copyright Oxide Computer Company
*/
import { useNavigate } from 'react-router-dom'
import type { SetRequired } from 'type-fest'

import { useApiMutation, useApiQueryClient, type VpcSubnetCreate } from '@oxide/api'

Expand All @@ -24,13 +23,14 @@ import { useForm, useVpcSelector } from '~/hooks'
import { FormDivider } from '~/ui/lib/Divider'
import { pb } from '~/util/path-builder'

const defaultValues: SetRequired<VpcSubnetCreate, 'customRouter'> = {
const defaultValues: Required<VpcSubnetCreate> = {
name: '',
description: '',
ipv4Block: '',
ipv6Block: '',
// populate the form field with the value corresponding to an undefined custom
// router on a subnet response
customRouter: customRouterDataToForm(undefined),
description: '',
ipv4Block: '',
}

export function CreateSubnetForm() {
Expand All @@ -56,12 +56,15 @@ export function CreateSubnetForm() {
formType="create"
resourceName="subnet"
onDismiss={onDismiss}
onSubmit={(body) =>
onSubmit={({ name, description, ipv4Block, ipv6Block, customRouter }) =>
createSubnet.mutate({
query: vpcSelector,
body: {
...body,
customRouter: customRouterFormToData(body.customRouter),
name,
description,
ipv4Block,
ipv6Block: ipv6Block.trim() || undefined,
customRouter: customRouterFormToData(customRouter),
},
})
}
Expand Down
3 changes: 1 addition & 2 deletions app/forms/subnet-edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* Copyright Oxide Computer Company
*/
import { useNavigate, type LoaderFunctionArgs } from 'react-router-dom'
import type { SetRequired } from 'type-fest'

import {
apiQueryClient,
Expand Down Expand Up @@ -57,7 +56,7 @@ export function EditSubnetForm() {
},
})

const defaultValues: SetRequired<VpcSubnetUpdate, 'customRouter'> = {
const defaultValues: Required<VpcSubnetUpdate> = {
name: subnet.name,
description: subnet.description,
customRouter: customRouterDataToForm(subnet.customRouterId),
Expand Down
5 changes: 5 additions & 0 deletions test/e2e/vpcs.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ test('can create and delete subnet', async ({ page }) => {

await dialog.getByRole('textbox', { name: 'Name' }).fill('mock-subnet-2')
await dialog.getByRole('textbox', { name: 'IPv4 block' }).fill('10.1.1.2/24')

// little hack to catch a bug where we weren't handling empty input here properly
await dialog.getByRole('textbox', { name: 'IPv6 block' }).fill('abc')
await dialog.getByRole('textbox', { name: 'IPv6 block' }).clear()

await dialog.getByRole('button', { name: 'Create subnet' }).click()

await expect(dialog).toBeHidden()
Expand Down

0 comments on commit 76bf329

Please sign in to comment.