-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add router tab and routes pages (#2359)
* first stub of Routers and RouterRoutes pages * continuing stub of router routes pages * Add more info to Router Route page * adjustments; TypeValueCell * deleting a route works * Updating strings in target / destination type-value rendering * Update based on feedback in oxide-product-eng * remove underscores in badge * add limit to route list prefetch to match QueryTable fetch * Progress on side modals to create router and route * Router create works * Route create working * Router and route creation / editing working, mostly * Move Router edit side modal to Routers overview page * Add TopBar pickers for VPC and Router * vpcRouterDelete implemented * Updating a router route now works * Update tests * Update to routes, path-builder spec * alphabetize routes * add in a missing route to the spec * Update test to match new error text in console * Update app/forms/vpc-router-create.tsx Co-authored-by: David Crespo <[email protected]> * Slight refactor on onDismiss * Clean up some duplicated code * Removed old stubbed code * Simpler table construction; add link to VPC in TopBar * refactoring * Optimize route fields * Adjust mock db values * Refactor * Paginate routes * Adding some error handling for issues unearthed when using this branch with dogfood * VPCs can not be used as destinations or targets in cusom routes * additional validations in forms; better comments * small test improvement * Additional restrictions on routes / routers * Update tests * switch to expectRowVisible * use clickRowAction * Refactoring post-review * More refactoring * Rename to RouterPage * git add womp womp * badge and IP Net updates * Add disabled link for 'New route' on system router page * Add DescriptionCell file and update imports * update msw handler for name/description for VPC Route * Update how form handles drop target * Move from useEffect to onChange for TargetType * refactor; pull onChange inline * Update handlers to error if route or router name already exists * Use VPC ID for testing Router uniqueness on update --------- Co-authored-by: David Crespo <[email protected]> Co-authored-by: David Crespo <[email protected]>
- Loading branch information
1 parent
11e29ed
commit 68e2dc8
Showing
27 changed files
with
1,269 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* 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 } from 'react-router-dom' | ||
|
||
import { useApiMutation, useApiQueryClient, type VpcRouterCreate } from '@oxide/api' | ||
|
||
import { DescriptionField } from '~/components/form/fields/DescriptionField' | ||
import { NameField } from '~/components/form/fields/NameField' | ||
import { SideModalForm } from '~/components/form/SideModalForm' | ||
import { useForm, useVpcSelector } from '~/hooks' | ||
import { addToast } from '~/stores/toast' | ||
import { pb } from '~/util/path-builder' | ||
|
||
const defaultValues: VpcRouterCreate = { | ||
name: '', | ||
description: '', | ||
} | ||
|
||
export function CreateRouterSideModalForm() { | ||
const queryClient = useApiQueryClient() | ||
const vpcSelector = useVpcSelector() | ||
const navigate = useNavigate() | ||
|
||
const onDismiss = () => navigate(pb.vpcRouters(vpcSelector)) | ||
|
||
const createRouter = useApiMutation('vpcRouterCreate', { | ||
onSuccess() { | ||
queryClient.invalidateQueries('vpcRouterList') | ||
addToast({ content: 'Your router has been created' }) | ||
onDismiss() | ||
}, | ||
}) | ||
|
||
const form = useForm({ defaultValues }) | ||
|
||
return ( | ||
<SideModalForm | ||
form={form} | ||
formType="create" | ||
resourceName="router" | ||
onDismiss={onDismiss} | ||
onSubmit={(body) => createRouter.mutate({ query: vpcSelector, body })} | ||
loading={createRouter.isPending} | ||
submitError={createRouter.error} | ||
> | ||
<NameField name="name" control={form.control} /> | ||
<DescriptionField name="description" control={form.control} /> | ||
</SideModalForm> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* 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, | ||
type NavigateFunction, | ||
} from 'react-router-dom' | ||
|
||
import { | ||
apiQueryClient, | ||
useApiMutation, | ||
useApiQueryClient, | ||
usePrefetchedApiQuery, | ||
type VpcRouterUpdate, | ||
} from '@oxide/api' | ||
|
||
import { DescriptionField } from '~/components/form/fields/DescriptionField' | ||
import { NameField } from '~/components/form/fields/NameField' | ||
import { SideModalForm } from '~/components/form/SideModalForm' | ||
import { getVpcRouterSelector, useForm, useVpcRouterSelector } from '~/hooks' | ||
import { addToast } from '~/stores/toast' | ||
import { pb } from '~/util/path-builder' | ||
|
||
EditRouterSideModalForm.loader = async ({ params }: LoaderFunctionArgs) => { | ||
const { router, project, vpc } = getVpcRouterSelector(params) | ||
await apiQueryClient.prefetchQuery('vpcRouterView', { | ||
path: { router }, | ||
query: { project, vpc }, | ||
}) | ||
return null | ||
} | ||
|
||
export function EditRouterSideModalForm() { | ||
const queryClient = useApiQueryClient() | ||
const routerSelector = useVpcRouterSelector() | ||
const { project, vpc, router } = routerSelector | ||
const { data: routerData } = usePrefetchedApiQuery('vpcRouterView', { | ||
path: { router }, | ||
query: { project, vpc }, | ||
}) | ||
const navigate = useNavigate() | ||
|
||
const onDismiss = (navigate: NavigateFunction) => { | ||
navigate(pb.vpcRouters({ project, vpc })) | ||
} | ||
|
||
const editRouter = useApiMutation('vpcRouterUpdate', { | ||
onSuccess() { | ||
queryClient.invalidateQueries('vpcRouterList') | ||
addToast({ content: 'Your router has been updated' }) | ||
navigate(pb.vpcRouters({ project, vpc })) | ||
}, | ||
}) | ||
|
||
const defaultValues: VpcRouterUpdate = { | ||
name: router, | ||
description: routerData.description, | ||
} | ||
|
||
const form = useForm({ defaultValues }) | ||
|
||
return ( | ||
<SideModalForm | ||
form={form} | ||
formType="edit" | ||
resourceName="router" | ||
onDismiss={() => onDismiss(navigate)} | ||
onSubmit={(body) => | ||
editRouter.mutate({ | ||
path: { router }, | ||
query: { project, vpc }, | ||
body, | ||
}) | ||
} | ||
loading={editRouter.isPending} | ||
submitError={editRouter.error} | ||
> | ||
<NameField name="name" control={form.control} /> | ||
<DescriptionField name="description" control={form.control} /> | ||
</SideModalForm> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
* 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 } from 'react-router-dom' | ||
|
||
import { useApiMutation, useApiQueryClient, type RouterRouteCreate } from '@oxide/api' | ||
|
||
import { DescriptionField } from '~/components/form/fields/DescriptionField' | ||
import { ListboxField } from '~/components/form/fields/ListboxField' | ||
import { NameField } from '~/components/form/fields/NameField' | ||
import { TextField } from '~/components/form/fields/TextField' | ||
import { SideModalForm } from '~/components/form/SideModalForm' | ||
import { fields, targetValueDescription } from '~/forms/vpc-router-route/shared' | ||
import { useForm, useVpcRouterSelector } from '~/hooks' | ||
import { addToast } from '~/stores/toast' | ||
import { pb } from '~/util/path-builder' | ||
|
||
const defaultValues: RouterRouteCreate = { | ||
name: '', | ||
description: '', | ||
destination: { type: 'ip', value: '' }, | ||
target: { type: 'ip', value: '' }, | ||
} | ||
|
||
export function CreateRouterRouteSideModalForm() { | ||
const queryClient = useApiQueryClient() | ||
const routerSelector = useVpcRouterSelector() | ||
const navigate = useNavigate() | ||
|
||
const onDismiss = () => { | ||
navigate(pb.vpcRouter(routerSelector)) | ||
} | ||
|
||
const createRouterRoute = useApiMutation('vpcRouterRouteCreate', { | ||
onSuccess() { | ||
queryClient.invalidateQueries('vpcRouterRouteList') | ||
addToast({ content: 'Your route has been created' }) | ||
onDismiss() | ||
}, | ||
}) | ||
|
||
const form = useForm({ defaultValues }) | ||
const targetType = form.watch('target.type') | ||
|
||
return ( | ||
<SideModalForm | ||
form={form} | ||
formType="create" | ||
resourceName="route" | ||
onDismiss={onDismiss} | ||
onSubmit={({ name, description, destination, target }) => | ||
createRouterRoute.mutate({ | ||
query: routerSelector, | ||
body: { | ||
name, | ||
description, | ||
destination, | ||
// drop has no value | ||
target: target.type === 'drop' ? { type: target.type } : target, | ||
}, | ||
}) | ||
} | ||
loading={createRouterRoute.isPending} | ||
submitError={createRouterRoute.error} | ||
> | ||
<NameField name="name" control={form.control} /> | ||
<DescriptionField name="description" control={form.control} /> | ||
<ListboxField {...fields.destType} control={form.control} /> | ||
<TextField {...fields.destValue} control={form.control} /> | ||
<ListboxField | ||
{...fields.targetType} | ||
control={form.control} | ||
onChange={(value) => { | ||
// 'outbound' is only valid option when targetType is 'internet_gateway' | ||
if (value === 'internet_gateway') { | ||
form.setValue('target.value', 'outbound') | ||
} | ||
if (value === 'drop') { | ||
form.setValue('target.value', '') | ||
} | ||
}} | ||
/> | ||
{targetType !== 'drop' && ( | ||
<TextField | ||
{...fields.targetValue} | ||
control={form.control} | ||
// when targetType is 'internet_gateway', we set it to `outbound` and make it non-editable | ||
disabled={targetType === 'internet_gateway'} | ||
description={targetValueDescription(targetType)} | ||
/> | ||
)} | ||
</SideModalForm> | ||
) | ||
} |
Oops, something went wrong.