Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
2 changes: 2 additions & 0 deletions app/forms/instance-create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ export async function clientLoader({ params }: LoaderFunctionArgs) {
queryClient.prefetchQuery(
q(api.floatingIpList, { query: { project, limit: ALL_ISH } })
),
// Fetch VPCs for custom NIC form
queryClient.prefetchQuery(q(api.vpcList, { query: { project, limit: ALL_ISH } })),
])
return null
}
Expand Down
35 changes: 18 additions & 17 deletions app/forms/network-interface-create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
*
* Copyright Oxide Computer Company
*/
import { useQuery } from '@tanstack/react-query'
import { useMemo } from 'react'
import { useForm } from 'react-hook-form'
import type { SetNonNullable, SetRequired } from 'type-fest'

import { api, q, type ApiError, type InstanceNetworkInterfaceCreate } from '@oxide/api'
import {
api,
q,
usePrefetchedQuery,
type ApiError,
type InstanceNetworkInterfaceCreate,
} from '@oxide/api'

import { DescriptionField } from '~/components/form/fields/DescriptionField'
import { ListboxField } from '~/components/form/fields/ListboxField'
Expand All @@ -20,14 +23,7 @@ import { TextField } from '~/components/form/fields/TextField'
import { SideModalForm } from '~/components/form/SideModalForm'
import { useProjectSelector } from '~/hooks/use-params'
import { FormDivider } from '~/ui/lib/Divider'

const defaultValues: SetRequired<SetNonNullable<InstanceNetworkInterfaceCreate>, 'ip'> = {
name: '',
description: '',
ip: '',
subnetName: '',
vpcName: '',
}
import { ALL_ISH } from '~/util/consts'

type CreateNetworkInterfaceFormProps = {
onDismiss: () => void
Expand All @@ -47,12 +43,17 @@ export function CreateNetworkInterfaceForm({
submitError = null,
}: CreateNetworkInterfaceFormProps) {
const projectSelector = useProjectSelector()

const { data: vpcsData } = useQuery(q(api.vpcList, { query: projectSelector }))
const vpcs = useMemo(() => vpcsData?.items || [], [vpcsData])

const {
data: { items: vpcs },
} = usePrefetchedQuery(q(api.vpcList, { query: { ...projectSelector, limit: ALL_ISH } }))
const defaultValues = {
name: '',
description: '',
ip: '',
subnetName: '',
vpcName: vpcs.length > 0 ? vpcs[0].name : '',
}
const form = useForm({ defaultValues })

return (
<SideModalForm
form={form}
Expand Down
2 changes: 2 additions & 0 deletions app/pages/project/instances/NetworkingTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ export async function clientLoader({ params }: LoaderFunctionArgs) {
queryClient.setQueryData(queryKey, { type: 'success', data: pool })
}
}),
// Fetch VPCs for Add NIC form
queryClient.fetchQuery(q(api.vpcList, { query: { project, limit: ALL_ISH } })),
])
return null
}
Expand Down
Loading