Skip to content

Commit 0de4210

Browse files
authored
Remove IP address field from floating IP create form (#2146)
remove IP address field from floating IP create form
1 parent 5cae211 commit 0de4210

File tree

2 files changed

+6
-43
lines changed

2 files changed

+6
-43
lines changed

app/forms/floating-ip-create.tsx

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import * as Accordion from '@radix-ui/react-accordion'
99
import { useState } from 'react'
1010
import { useNavigate } from 'react-router-dom'
11-
import type { SetRequired } from 'type-fest'
1211

1312
import {
1413
useApiMutation,
@@ -22,14 +21,12 @@ import { AccordionItem } from '~/components/AccordionItem'
2221
import { DescriptionField } from '~/components/form/fields/DescriptionField'
2322
import { ListboxField } from '~/components/form/fields/ListboxField'
2423
import { NameField } from '~/components/form/fields/NameField'
25-
import { TextField } from '~/components/form/fields/TextField'
2624
import { SideModalForm } from '~/components/form/SideModalForm'
2725
import { useForm, useProjectSelector } from '~/hooks'
2826
import { addToast } from '~/stores/toast'
2927
import { Badge } from '~/ui/lib/Badge'
3028
import { Message } from '~/ui/lib/Message'
3129
import { pb } from '~/util/path-builder'
32-
import { validateIp } from '~/util/str'
3330

3431
const toListboxItem = (p: SiloIpPool) => {
3532
if (!p.isDefault) {
@@ -50,11 +47,10 @@ const toListboxItem = (p: SiloIpPool) => {
5047
}
5148
}
5249

53-
const defaultValues: SetRequired<FloatingIpCreate, 'ip'> = {
50+
const defaultValues: Omit<FloatingIpCreate, 'ip'> = {
5451
name: '',
5552
description: '',
5653
pool: undefined,
57-
ip: '',
5854
}
5955

6056
export function CreateFloatingIpSideModalForm() {
@@ -78,7 +74,6 @@ export function CreateFloatingIpSideModalForm() {
7874
})
7975

8076
const form = useForm({ defaultValues })
81-
const isPoolSelected = !!form.watch('pool')
8277

8378
const [openItems, setOpenItems] = useState<string[]>([])
8479

@@ -88,13 +83,7 @@ export function CreateFloatingIpSideModalForm() {
8883
formType="create"
8984
resourceName="floating IP"
9085
onDismiss={() => navigate(pb.floatingIps(projectSelector))}
91-
onSubmit={({ ip, ...rest }) => {
92-
createFloatingIp.mutate({
93-
query: projectSelector,
94-
// if address is '', evaluate as false and send as undefined
95-
body: { ip: ip || undefined, ...rest },
96-
})
97-
}}
86+
onSubmit={(body) => createFloatingIp.mutate({ query: projectSelector, body })}
9887
loading={createFloatingIp.isPending}
9988
submitError={createFloatingIp.error}
10089
>
@@ -124,16 +113,6 @@ export function CreateFloatingIpSideModalForm() {
124113
control={form.control}
125114
placeholder="Select pool"
126115
/>
127-
<TextField
128-
name="ip"
129-
label="IP address"
130-
control={form.control}
131-
disabled={!isPoolSelected}
132-
transform={(v) => v.replace(/\s/g, '')}
133-
validate={(ip) =>
134-
ip && !validateIp(ip).valid ? 'Not a valid IP address' : true
135-
}
136-
/>
137116
</AccordionItem>
138117
</Accordion.Root>
139118
</SideModalForm>

test/e2e/floating-ip-create.e2e.ts

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,7 @@
66
* Copyright Oxide Computer Company
77
*/
88

9-
import {
10-
clickRowAction,
11-
expect,
12-
expectNotVisible,
13-
expectRowVisible,
14-
expectVisible,
15-
test,
16-
} from './utils'
9+
import { clickRowAction, expect, expectRowVisible, expectVisible, test } from './utils'
1710

1811
const floatingIpsPage = '/projects/mock-project/floating-ips'
1912

@@ -36,28 +29,19 @@ test('can create a floating IP', async ({ page }) => {
3629
.fill('A description for this Floating IP')
3730

3831
const poolListbox = page.getByRole('button', { name: 'IP pool' })
39-
const ipTextbox = page.getByRole('textbox', { name: 'IP address' })
4032

4133
// accordion content should be hidden
42-
await expectNotVisible(page, [ipTextbox])
34+
await expect(poolListbox).toBeHidden()
4335

4436
// open accordion
4537
await page.getByRole('button', { name: 'Advanced' }).click()
4638

4739
// accordion content should be visible
48-
await expectVisible(page, [poolListbox, ipTextbox])
40+
await expect(poolListbox).toBeVisible()
4941

50-
// test that the IP validation works
42+
// choose pool and submit
5143
await poolListbox.click()
5244
await page.getByRole('option', { name: 'ip-pool-1' }).click()
53-
await ipTextbox.fill('256.256.256.256')
54-
await page.getByRole('button', { name: 'Create floating IP' }).click()
55-
await expect(page.getByText('Not a valid IP address').first()).toBeVisible()
56-
57-
// correct IP and submit
58-
await ipTextbox.clear()
59-
await ipTextbox.fill('12.34.56.78')
60-
6145
await page.getByRole('button', { name: 'Create floating IP' }).click()
6246

6347
await expect(page).toHaveURL(floatingIpsPage)

0 commit comments

Comments
 (0)