Skip to content

Commit

Permalink
Update how form handles drop target
Browse files Browse the repository at this point in the history
  • Loading branch information
charliepark committed Aug 14, 2024
1 parent dcd1d7f commit 80f94bb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
15 changes: 12 additions & 3 deletions app/forms/vpc-router-route-create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ export function CreateRouterRouteSideModalForm() {
const targetType = form.watch('target.type')

useEffect(() => {
// Clear target value when targetType changes to 'drop'
targetType === 'drop' && form.setValue('target.value', '')

This comment has been minimized.

Copy link
@david-crespo

david-crespo Aug 14, 2024

Collaborator

I think it's still good to clear it because otherwise the old value is still there when you go to another type and back

// 'outbound' is only valid option when targetType is 'internet_gateway'
targetType === 'internet_gateway' && form.setValue('target.value', 'outbound')
}, [targetType, form])
Expand All @@ -60,7 +58,18 @@ export function CreateRouterRouteSideModalForm() {
formType="create"
resourceName="route"
onDismiss={onDismiss}
onSubmit={(body) => createRouterRoute.mutate({ query: routerSelector, body })}
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}
>
Expand Down
12 changes: 8 additions & 4 deletions app/forms/vpc-router-route-edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ export function EditRouterRouteSideModalForm() {
const targetType = form.watch('target.type')

useEffect(() => {
// Clear target value when targetType changes to 'drop'
targetType === 'drop' && form.setValue('target.value', '')
// 'outbound' is only valid option when targetType is 'internet_gateway'
targetType === 'internet_gateway' && form.setValue('target.value', 'outbound')
}, [targetType, form])
Expand All @@ -95,11 +93,17 @@ export function EditRouterRouteSideModalForm() {
formType="edit"
resourceName="route"
onDismiss={onDismiss}
onSubmit={(body) =>
onSubmit={({ name, description, destination, target }) =>
updateRouterRoute.mutate({
query: { project, vpc, router: routerName },
path: { route: routeName },
body,
body: {
name,
description,
destination,
// drop has no value
target: target.type === 'drop' ? { type: target.type } : target,
},
})
}
loading={updateRouterRoute.isPending}
Expand Down
2 changes: 1 addition & 1 deletion app/forms/vpc-router-route/shared.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const routeFormMessage = {
// https://github.com/oxidecomputer/omicron/blob/914f5fd7d51f9b060dcc0382a30b607e25df49b2/nexus/src/app/vpc_router.rs#L201-L204
noNewRoutesOnSystemRouter: 'User-provided routes cannot be added to a system router',
// https://github.com/oxidecomputer/omicron/blob/914f5fd7d51f9b060dcc0382a30b607e25df49b2/nexus/src/app/vpc_router.rs#L300-L304
noDeletingRoutesOnSystemRouter: 'DELETE not allowed on system routes',
noDeletingRoutesOnSystemRouter: 'System routes can not be deleted',
}

export const targetValueDescription = (targetType: RouteTarget['type']) =>
Expand Down

0 comments on commit 80f94bb

Please sign in to comment.