-
Notifications
You must be signed in to change notification settings - Fork 16
Add floating IP edit form #2033
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
Changes from all commits
e04f489
76286b3
21e2989
ab22747
4c7ca63
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| d514878f417a94247791bd5564fbaafa9b4170a0 | ||
| 1f26c66921b9215bfe11d750514939bcdc11ae12 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| /* | ||
| * This Source Code Form is subject to the terms of the Mozilla Public | ||
| * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| * file, you can obtain one at https://mozilla.org/MPL/2.0/. | ||
| * | ||
| * Copyright Oxide Computer Company | ||
| */ | ||
| import { useNavigate, type LoaderFunctionArgs } from 'react-router-dom' | ||
|
|
||
| import { | ||
| apiQueryClient, | ||
| useApiMutation, | ||
| useApiQueryClient, | ||
| usePrefetchedApiQuery, | ||
| } from '@oxide/api' | ||
|
|
||
| import { DescriptionField } from '~/components/form/fields/DescriptionField' | ||
| import { NameField } from '~/components/form/fields/NameField' | ||
| import { SideModalForm } from '~/components/form/SideModalForm' | ||
| import { getFloatingIpSelector, useFloatingIpSelector, useForm, useToast } from 'app/hooks' | ||
| import { pb } from 'app/util/path-builder' | ||
|
|
||
| EditFloatingIpSideModalForm.loader = async ({ params }: LoaderFunctionArgs) => { | ||
| const { floatingIp, project } = getFloatingIpSelector(params) | ||
| await apiQueryClient.prefetchQuery('floatingIpView', { | ||
| path: { floatingIp }, | ||
| query: { project }, | ||
| }) | ||
| return null | ||
| } | ||
|
|
||
| export function EditFloatingIpSideModalForm() { | ||
| const queryClient = useApiQueryClient() | ||
| const addToast = useToast() | ||
| const navigate = useNavigate() | ||
|
|
||
| const floatingIpSelector = useFloatingIpSelector() | ||
|
|
||
| const onDismiss = () => navigate(pb.floatingIps({ project: floatingIpSelector.project })) | ||
|
|
||
| const { data: floatingIp } = usePrefetchedApiQuery('floatingIpView', { | ||
| path: { floatingIp: floatingIpSelector.floatingIp }, | ||
| query: { project: floatingIpSelector.project }, | ||
| }) | ||
|
|
||
| const editFloatingIp = useApiMutation('floatingIpUpdate', { | ||
| onSuccess(_floatingIp) { | ||
| queryClient.invalidateQueries('floatingIpList') | ||
| addToast({ content: 'Your floating IP has been updated' }) | ||
| onDismiss() | ||
| }, | ||
| }) | ||
|
|
||
| const form = useForm({ defaultValues: floatingIp }) | ||
|
|
||
| return ( | ||
| <SideModalForm | ||
| id="edit-floating-ip-form" | ||
| form={form} | ||
| title="Edit floating IP" | ||
| onDismiss={onDismiss} | ||
| onSubmit={({ name, description }) => { | ||
| editFloatingIp.mutate({ | ||
| path: { floatingIp: floatingIpSelector.floatingIp }, | ||
| query: { project: floatingIpSelector.project }, | ||
| body: { name, description }, | ||
| }) | ||
| }} | ||
| loading={editFloatingIp.isPending} | ||
| submitError={editFloatingIp.error} | ||
| submitLabel="Save changes" | ||
| > | ||
| <NameField name="name" control={form.control} /> | ||
| <DescriptionField name="description" control={form.control} /> | ||
| </SideModalForm> | ||
| ) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| /* | ||
| * This Source Code Form is subject to the terms of the Mozilla Public | ||
| * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| * file, you can obtain one at https://mozilla.org/MPL/2.0/. | ||
| * | ||
| * Copyright Oxide Computer Company | ||
| */ | ||
|
|
||
| import { clickRowAction, expect, expectRowVisible, expectVisible, test } from './utils' | ||
|
|
||
| const floatingIpsPage = '/projects/mock-project/floating-ips' | ||
| const originalName = 'cola-float' | ||
| const updatedName = 'updated-cola-float' | ||
| const updatedDescription = 'An updated description for this Floating IP' | ||
| const expectedFormElements = [ | ||
| 'role=heading[name*="Edit floating IP"]', | ||
| 'role=textbox[name="Name"]', | ||
| 'role=textbox[name="Description"]', | ||
| 'role=button[name="Save changes"]', | ||
| ] | ||
|
|
||
| test('can update a floating IP', async ({ page }) => { | ||
| await page.goto(floatingIpsPage) | ||
| await clickRowAction(page, 'cola-float', 'Edit') | ||
| await expectVisible(page, expectedFormElements) | ||
|
|
||
| await page.fill('input[name=name]', updatedName) | ||
| await page.getByRole('textbox', { name: 'Description' }).fill(updatedDescription) | ||
| await page.getByRole('button', { name: 'Save changes' }).click() | ||
| await expect(page).toHaveURL(floatingIpsPage) | ||
| await expectRowVisible(page.getByRole('table'), { | ||
| name: updatedName, | ||
| description: updatedDescription, | ||
| }) | ||
| }) | ||
|
|
||
| // Make sure that it still works even if the name doesn't change | ||
| test('can update *just* the floating IP description', async ({ page }) => { | ||
| // Go to the edit page for the original floating IP | ||
| await page.goto(`${floatingIpsPage}/${originalName}/edit`) | ||
| await expectVisible(page, expectedFormElements) | ||
|
|
||
| await page.getByRole('textbox', { name: 'Description' }).fill(updatedDescription) | ||
| await page.getByRole('button', { name: 'Save changes' }).click() | ||
| await expect(page).toHaveURL(floatingIpsPage) | ||
| await expectRowVisible(page.getByRole('table'), { | ||
| name: originalName, | ||
| description: updatedDescription, | ||
| }) | ||
| }) |
Uh oh!
There was an error while loading. Please reload this page.