Skip to content

Commit 243c55d

Browse files
authored
refactor: create path params types module, rename current path params to "selectors" (#2606)
* shuffle around API selector types and separate path params * use the new PP type in a few places
1 parent deb5e18 commit 243c55d

File tree

14 files changed

+158
-149
lines changed

14 files changed

+158
-149
lines changed

app/api/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ export * from './__generated__/Api'
1919

2020
export type { ApiTypes }
2121

22-
export * as PathParams from './path-params'
23-
2422
export { ensurePrefetched, PAGE_SIZE, type PaginatedQuery, type ResultsPage } from './hooks'
2523
export type { ApiError } from './errors'
2624
export { navToLogin } from './nav-to-login'

app/api/path-params.ts

Lines changed: 0 additions & 30 deletions
This file was deleted.

app/api/selectors.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this
4+
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
5+
*
6+
* Copyright Oxide Computer Company
7+
*/
8+
import type { Merge } from 'type-fest'
9+
10+
export type Project = Readonly<{ project?: string }>
11+
export type Instance = Readonly<Merge<Project, { instance?: string }>>
12+
export type Disk = Readonly<Merge<Project, { disk?: string }>>
13+
export type Image = Readonly<Merge<Project, { image?: string }>>
14+
export type SiloImage = Readonly<{ image?: string }>
15+
export type NetworkInterface = Readonly<Merge<Instance, { interface?: string }>>
16+
export type Snapshot = Readonly<Merge<Project, { snapshot?: string }>>
17+
export type Vpc = Readonly<Merge<Project, { vpc?: string }>>
18+
export type VpcRouter = Readonly<Merge<Vpc, { router?: string }>>
19+
export type VpcRouterRoute = Readonly<Merge<VpcRouter, { route?: string }>>
20+
export type VpcSubnet = Readonly<Merge<Vpc, { subnet?: string }>>
21+
export type FirewallRule = Readonly<Merge<Vpc, { rule?: string }>>
22+
export type Silo = Readonly<{ silo?: string }>
23+
export type IdentityProvider = Readonly<Merge<Silo, { provider: string }>>
24+
export type SystemUpdate = Readonly<{ version: string }>
25+
export type SshKey = Readonly<{ sshKey: string }>
26+
export type Sled = Readonly<{ sledId?: string }>
27+
export type IpPool = Readonly<{ pool?: string }>
28+
export type FloatingIp = Readonly<Merge<Project, { floatingIp?: string }>>
29+
30+
export type Id = Readonly<{ id: string }>

app/components/ExternalIps.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ import { useApiQuery } from '@oxide/api'
1111
import { EmptyCell, SkeletonCell } from '~/table/cells/EmptyCell'
1212
import { CopyableIp } from '~/ui/lib/CopyableIp'
1313
import { intersperse } from '~/util/array'
14+
import type * as PP from '~/util/path-params'
1415

15-
type InstanceSelector = { project: string; instance: string }
16-
17-
export function ExternalIps({ project, instance }: InstanceSelector) {
16+
export function ExternalIps({ project, instance }: PP.Instance) {
1817
const { data, isPending } = useApiQuery('instanceExternalIpList', {
1918
path: { instance },
2019
query: { project },

app/forms/snapshot-create.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
useApiMutation,
1515
useApiQuery,
1616
useApiQueryClient,
17-
type PathParams as PP,
1817
type SnapshotCreate,
1918
} from '@oxide/api'
2019

@@ -28,10 +27,11 @@ import { addToast } from '~/stores/toast'
2827
import { toComboboxItems } from '~/ui/lib/Combobox'
2928
import { ALL_ISH } from '~/util/consts'
3029
import { pb } from '~/util/path-builder'
30+
import type * as PP from '~/util/path-params'
3131

32-
const useSnapshotDiskItems = (projectSelector: PP.Project) => {
32+
const useSnapshotDiskItems = ({ project }: PP.Project) => {
3333
const { data: disks } = useApiQuery('diskList', {
34-
query: { ...projectSelector, limit: ALL_ISH },
34+
query: { project, limit: ALL_ISH },
3535
})
3636
return disks?.items.filter(diskCan.snapshot)
3737
}

app/pages/project/disks/DisksPage.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import { PageHeader, PageTitle } from '~/ui/lib/PageHeader'
3737
import { TableActions } from '~/ui/lib/Table'
3838
import { docLinks } from '~/util/links'
3939
import { pb } from '~/util/path-builder'
40+
import type * as PP from '~/util/path-params'
4041

4142
import { fancifyStates } from '../instances/instance/tabs/common'
4243

@@ -50,12 +51,12 @@ const EmptyState = () => (
5051
/>
5152
)
5253

53-
const diskList = (project: string) => getListQFn('diskList', { query: { project } })
54+
const diskList = (query: PP.Project) => getListQFn('diskList', { query })
5455

5556
DisksPage.loader = async ({ params }: LoaderFunctionArgs) => {
5657
const { project } = getProjectSelector(params)
5758
await Promise.all([
58-
queryClient.prefetchQuery(diskList(project).optionsFn()),
59+
queryClient.prefetchQuery(diskList({ project }).optionsFn()),
5960

6061
// fetch instances and preload into RQ cache so fetches by ID in
6162
// InstanceLinkCell can be mostly instant yet gracefully fall back to
@@ -162,7 +163,7 @@ export function DisksPage() {
162163

163164
const columns = useColsWithActions(staticCols, makeActions)
164165
const { table } = useQueryTable({
165-
query: diskList(project),
166+
query: diskList({ project }),
166167
columns,
167168
emptyState: <EmptyState />,
168169
})

app/pages/project/images/ImagesPage.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import { PageHeader, PageTitle } from '~/ui/lib/PageHeader'
3636
import { TableActions } from '~/ui/lib/Table'
3737
import { docLinks } from '~/util/links'
3838
import { pb } from '~/util/path-builder'
39+
import type * as PP from '~/util/path-params'
3940

4041
const EmptyState = () => (
4142
<EmptyMessage
@@ -49,11 +50,11 @@ const EmptyState = () => (
4950

5051
const colHelper = createColumnHelper<Image>()
5152

52-
const imageList = (project: string) => getListQFn('imageList', { query: { project } })
53+
const imageList = (query: PP.Project) => getListQFn('imageList', { query })
5354

5455
ImagesPage.loader = async ({ params }: LoaderFunctionArgs) => {
5556
const { project } = getProjectSelector(params)
56-
await queryClient.prefetchQuery(imageList(project).optionsFn())
57+
await queryClient.prefetchQuery(imageList({ project }).optionsFn())
5758
return null
5859
}
5960

@@ -103,7 +104,7 @@ export function ImagesPage() {
103104
}, [project, makeActions])
104105

105106
const { table } = useQueryTable({
106-
query: imageList(project),
107+
query: imageList({ project }),
107108
columns,
108109
emptyState: <EmptyState />,
109110
})

app/pages/project/vpcs/RouterPage.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,12 @@ import { PropertiesTable } from '~/ui/lib/PropertiesTable'
4343
import { TableControls, TableTitle } from '~/ui/lib/Table'
4444
import { docLinks } from '~/util/links'
4545
import { pb } from '~/util/path-builder'
46+
import type * as PP from '~/util/path-params'
4647

47-
type RouterParams = { project: string; vpc: string; router: string }
48-
49-
const routerView = ({ project, vpc, router }: RouterParams) =>
48+
const routerView = ({ project, vpc, router }: PP.VpcRouter) =>
5049
apiq('vpcRouterView', { path: { router }, query: { vpc, project } })
5150

52-
const routeList = (query: RouterParams) => getListQFn('vpcRouterRouteList', { query })
51+
const routeList = (query: PP.VpcRouter) => getListQFn('vpcRouterRouteList', { query })
5352

5453
export async function loader({ params }: LoaderFunctionArgs) {
5554
const routerSelector = getVpcRouterSelector(params)

app/pages/project/vpcs/VpcPage/tabs/VpcRoutersTab.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ import { useQueryTable } from '~/table/QueryTable'
2929
import { CreateLink } from '~/ui/lib/CreateButton'
3030
import { EmptyMessage } from '~/ui/lib/EmptyMessage'
3131
import { pb } from '~/util/path-builder'
32+
import type * as PP from '~/util/path-params'
3233

3334
const colHelper = createColumnHelper<VpcRouter>()
3435

35-
const vpcRouterList = (params: { project: string; vpc: string }) =>
36-
getListQFn('vpcRouterList', { query: params })
36+
const vpcRouterList = (query: PP.Vpc) => getListQFn('vpcRouterList', { query })
3737

3838
export async function loader({ params }: LoaderFunctionArgs) {
3939
const { project, vpc } = getVpcSelector(params)

app/pages/project/vpcs/VpcPage/tabs/VpcSubnetsTab.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ import { useQueryTable } from '~/table/QueryTable'
2929
import { CreateLink } from '~/ui/lib/CreateButton'
3030
import { EmptyMessage } from '~/ui/lib/EmptyMessage'
3131
import { pb } from '~/util/path-builder'
32+
import type * as PP from '~/util/path-params'
3233

3334
const colHelper = createColumnHelper<VpcSubnet>()
3435

35-
const subnetList = (params: { project: string; vpc: string }) =>
36-
getListQFn('vpcSubnetList', { query: params })
36+
const subnetList = (params: PP.Vpc) => getListQFn('vpcSubnetList', { query: params })
3737

3838
export async function loader({ params }: LoaderFunctionArgs) {
3939
const { project, vpc } = getVpcSelector(params)

0 commit comments

Comments
 (0)