Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
24 changes: 23 additions & 1 deletion app/components/AttachFloatingIpModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,16 @@
* Copyright Oxide Computer Company
*/

import { useQuery } from '@tanstack/react-query'
import { useForm } from 'react-hook-form'

import { useApiMutation, useApiQueryClient, type FloatingIp, type Instance } from '~/api'
import {
apiqErrorsAllowed,
useApiMutation,
useApiQueryClient,
type FloatingIp,
type Instance,
} from '~/api'
import { ListboxField } from '~/components/form/fields/ListboxField'
import { HL } from '~/components/HL'
import { addToast } from '~/stores/toast'
Expand All @@ -17,12 +24,27 @@ import { Slash } from '~/ui/lib/Slash'

import { ModalForm } from './form/ModalForm'

function IpPoolName({ ipPoolId }: { ipPoolId: string }) {
const { data: result } = useQuery(
apiqErrorsAllowed('projectIpPoolView', { path: { pool: ipPoolId } })
)
// As with IpPoolCell, this should never happen, but to be safe …
if (!result || result.type === 'error') return null
return (
<>
<Slash />
<span>{result.data.name}</span>
</>
)
}

function FloatingIpLabel({ fip }: { fip: FloatingIp }) {
return (
<div className="text-secondary selected:text-accent-secondary">
<div>{fip.name}</div>
<div className="flex gap-0.5">
<div>{fip.ip}</div>
<IpPoolName ipPoolId={fip.ipPoolId} />
{fip.description && (
<>
<Slash />
Expand Down
18 changes: 16 additions & 2 deletions app/pages/project/instances/NetworkingTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import { type LoaderFunctionArgs } from 'react-router'
import { match } from 'ts-pattern'

import {
apiqErrorsAllowed,
apiQueryClient,
instanceCan,
queryClient,
useApiMutation,
useApiQuery,
useApiQueryClient,
Expand Down Expand Up @@ -118,8 +120,20 @@ export async function clientLoader({ params }: LoaderFunctionArgs) {
path: { instance },
query: { project },
}),
// This is used in AttachEphemeralIpModal
apiQueryClient.fetchQuery('projectIpPoolList', { query: { limit: ALL_ISH } }),
// Fetch IP Pools and preload into RQ cache so fetches by ID in
// IpPoolCell and AttachFloatingIpModal can be mostly instant
apiQueryClient
.fetchQuery('projectIpPoolList', { query: { limit: ALL_ISH } })
.then((pools) => {
for (const pool of pools.items) {
// both IpPoolCell and the fetch in the model use errors-allowed
// versions to avoid blowing up in the unlikely event of an error
const { queryKey } = apiqErrorsAllowed('projectIpPoolView', {
path: { pool: pool.id },
})
queryClient.setQueryData(queryKey, { type: 'success', data: pool })
}
}),
])
return null
}
Expand Down
Loading