Skip to content
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

Add router tab and routes pages #2359

Merged
merged 55 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
373d70e
first stub of Routers and RouterRoutes pages
charliepark Jul 26, 2024
6422957
continuing stub of router routes pages
charliepark Jul 30, 2024
ddb2a53
Merge main; resolve conflicts
charliepark Jul 30, 2024
a7e6f44
Add more info to Router Route page
charliepark Jul 31, 2024
588cffd
adjustments; TypeValueCell
charliepark Aug 1, 2024
0507f0a
deleting a route works
charliepark Aug 2, 2024
d74f0c5
Updating strings in target / destination type-value rendering
charliepark Aug 2, 2024
95b184f
Update based on feedback in oxide-product-eng
charliepark Aug 2, 2024
007a961
remove underscores in badge
charliepark Aug 2, 2024
d224f1d
add limit to route list prefetch to match QueryTable fetch
david-crespo Aug 3, 2024
0a1c5ac
Progress on side modals to create router and route
charliepark Aug 5, 2024
50187a8
Router create works
charliepark Aug 5, 2024
266c923
Route create working
charliepark Aug 6, 2024
a6114e6
Router and route creation / editing working, mostly
charliepark Aug 6, 2024
4384645
Move Router edit side modal to Routers overview page
charliepark Aug 6, 2024
ad203e8
Add TopBar pickers for VPC and Router
charliepark Aug 7, 2024
226814a
vpcRouterDelete implemented
charliepark Aug 7, 2024
131c7f5
Updating a router route now works
charliepark Aug 7, 2024
ef29208
Update tests
charliepark Aug 7, 2024
240524f
Update to routes, path-builder spec
charliepark Aug 8, 2024
ff12b75
alphabetize routes
charliepark Aug 8, 2024
6afd415
add in a missing route to the spec
charliepark Aug 8, 2024
7440f84
Update test to match new error text in console
charliepark Aug 8, 2024
136b129
Update app/forms/vpc-router-create.tsx
charliepark Aug 8, 2024
ccfb037
Slight refactor on onDismiss
charliepark Aug 8, 2024
8bfaf3b
Clean up some duplicated code
charliepark Aug 8, 2024
f6f03e5
Removed old stubbed code
charliepark Aug 8, 2024
50c5b72
Simpler table construction; add link to VPC in TopBar
charliepark Aug 9, 2024
a2e3a83
refactoring
charliepark Aug 9, 2024
2f67e0d
Optimize route fields
charliepark Aug 9, 2024
ac75b10
Adjust mock db values
charliepark Aug 9, 2024
d52df65
Refactor
charliepark Aug 9, 2024
3a16b0b
Paginate routes
charliepark Aug 9, 2024
572a136
Adding some error handling for issues unearthed when using this bran…
charliepark Aug 9, 2024
9c876be
VPCs can not be used as destinations or targets in cusom routes
charliepark Aug 12, 2024
027e275
additional validations in forms; better comments
charliepark Aug 12, 2024
4ff67ed
small test improvement
charliepark Aug 12, 2024
812e010
Additional restrictions on routes / routers
charliepark Aug 12, 2024
442fa07
Update tests
charliepark Aug 13, 2024
75ba267
switch to expectRowVisible
charliepark Aug 13, 2024
7e62450
use clickRowAction
charliepark Aug 13, 2024
0673c21
Refactoring post-review
charliepark Aug 13, 2024
fe2df7d
More refactoring
charliepark Aug 13, 2024
f4975c7
Rename to RouterPage
charliepark Aug 13, 2024
7d88539
git add womp womp
charliepark Aug 13, 2024
014fb89
badge and IP Net updates
charliepark Aug 13, 2024
7a81ef0
Add disabled link for 'New route' on system router page
charliepark Aug 14, 2024
8c139fc
Add DescriptionCell file and update imports
charliepark Aug 14, 2024
dcd1d7f
update msw handler for name/description for VPC Route
charliepark Aug 14, 2024
80f94bb
Update how form handles drop target
charliepark Aug 14, 2024
8cc4744
Move from useEffect to onChange for TargetType
charliepark Aug 14, 2024
dbb47f1
Merge branch 'main' into routers-pages
charliepark Aug 14, 2024
8ac44d0
refactor; pull onChange inline
charliepark Aug 14, 2024
20423b0
Update handlers to error if route or router name already exists
charliepark Aug 14, 2024
e0813a1
Use VPC ID for testing Router uniqueness on update
charliepark Aug 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion app/api/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,14 @@ export const getUsePrefetchedApiQuery =
})
invariant(
result.data,
`Expected query to be prefetched. Key: ${JSON.stringify(queryKey)}`
`Expected query to be prefetched.
Key: ${JSON.stringify(queryKey)}
Ensure the following:
• loader is running
• query matches in both the loader and the component
• request isn't erroring-out server-side (check the Networking tab)
• mock API endpoint is implemented in handlers.ts
`
)
// TS infers non-nullable on a freestanding variable, but doesn't like to do
// it on a property. So we give it a hint
Expand Down
2 changes: 2 additions & 0 deletions app/api/path-params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export type SiloImage = { image?: string }
export type NetworkInterface = Merge<Instance, { interface?: string }>
export type Snapshot = Merge<Project, { snapshot?: string }>
export type Vpc = Merge<Project, { vpc?: string }>
export type VpcRouter = Merge<Vpc, { router?: string }>
export type VpcRouterRoute = Merge<VpcRouter, { route?: string }>
export type VpcSubnet = Merge<Vpc, { subnet?: string }>
export type FirewallRule = Merge<Vpc, { rule?: string }>
export type Silo = { silo?: string }
Expand Down
55 changes: 53 additions & 2 deletions app/components/TopBarPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ import {
Success12Icon,
} from '@oxide/design-system/icons/react'

import { useInstanceSelector, useIpPoolSelector, useSiloSelector } from '~/hooks'
import {
useInstanceSelector,
useIpPoolSelector,
useSiloSelector,
useVpcRouterSelector,
useVpcSelector,
} from '~/hooks'
import { useCurrentUser } from '~/layouts/AuthenticatedLayout'
import { PAGE_SIZE } from '~/table/QueryTable'
import { Button } from '~/ui/lib/Button'
Expand Down Expand Up @@ -229,7 +235,7 @@ export function SiloPicker() {
export function IpPoolPicker() {
// picker only shows up when a pool is in scope
const { pool: poolName } = useIpPoolSelector()
const { data } = useApiQuery('ipPoolList', { query: { limit: 10 } })
const { data } = useApiQuery('ipPoolList', { query: { limit: PAGE_SIZE } })
const items = (data?.items || []).map((pool) => ({
label: pool.name,
to: pb.ipPool({ pool: pool.name }),
Expand All @@ -246,6 +252,51 @@ export function IpPoolPicker() {
)
}

/** Used when drilling down into a VPC from the Silo view. */
export function VpcPicker() {
// picker only shows up when a VPC is in scope
const { project, vpc } = useVpcSelector()
const { data } = useApiQuery('vpcList', { query: { project, limit: PAGE_SIZE } })
charliepark marked this conversation as resolved.
Show resolved Hide resolved
const items = (data?.items || []).map((v) => ({
label: v.name,
to: pb.vpc({ project, vpc: v.name }),
}))

return (
<TopBarPicker
aria-label="Switch VPC"
category="VPC"
current={vpc}
items={items}
noItemsText="No VPCs found"
to={pb.vpc({ project, vpc })}
/>
)
}

/** Used when drilling down into a VPC Router from the Silo view. */
export function VpcRouterPicker() {
// picker only shows up when a router is in scope
const { project, vpc, router } = useVpcRouterSelector()
const { data } = useApiQuery('vpcRouterList', {
query: { project, vpc, limit: PAGE_SIZE },
})
const items = (data?.items || []).map((r) => ({
label: r.name,
to: pb.vpcRouter({ vpc, project, router: r.name }),
}))

return (
<TopBarPicker
aria-label="Switch router"
category="router"
current={router}
items={items}
noItemsText="No routers found"
/>
)
}

const NoProjectLogo = () => (
<div className="flex h-[34px] w-[34px] items-center justify-center rounded text-secondary bg-secondary">
<Folder16Icon />
Expand Down
2 changes: 1 addition & 1 deletion app/forms/subnet-edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export function EditSubnetForm() {
},
})

const defaultValues = R.pick(subnet, ['name', 'description']) satisfies VpcSubnetUpdate
const defaultValues: VpcSubnetUpdate = R.pick(subnet, ['name', 'description'])

const form = useForm({ defaultValues })

Expand Down
55 changes: 55 additions & 0 deletions app/forms/vpc-router-create.tsx
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>
)
}
87 changes: 87 additions & 0 deletions app/forms/vpc-router-edit.tsx
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>
)
}
98 changes: 98 additions & 0 deletions app/forms/vpc-router-route-create.tsx
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>
)
}
Loading
Loading