Skip to content

Commit 887a2ca

Browse files
Add IP pool name to Attach Floating IP dropdown (#2870)
Co-authored-by: David Crespo <[email protected]>
1 parent 76ca8cf commit 887a2ca

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

app/components/AttachFloatingIpModal.tsx

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,16 @@
66
* Copyright Oxide Computer Company
77
*/
88

9+
import { useQuery } from '@tanstack/react-query'
910
import { useForm } from 'react-hook-form'
1011

11-
import { useApiMutation, useApiQueryClient, type FloatingIp, type Instance } from '~/api'
12+
import {
13+
apiqErrorsAllowed,
14+
useApiMutation,
15+
useApiQueryClient,
16+
type FloatingIp,
17+
type Instance,
18+
} from '~/api'
1219
import { ListboxField } from '~/components/form/fields/ListboxField'
1320
import { HL } from '~/components/HL'
1421
import { addToast } from '~/stores/toast'
@@ -17,12 +24,27 @@ import { Slash } from '~/ui/lib/Slash'
1724

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

27+
function IpPoolName({ ipPoolId }: { ipPoolId: string }) {
28+
const { data: result } = useQuery(
29+
apiqErrorsAllowed('projectIpPoolView', { path: { pool: ipPoolId } })
30+
)
31+
// As with IpPoolCell, this should never happen, but to be safe …
32+
if (!result || result.type === 'error') return null
33+
return (
34+
<>
35+
<Slash />
36+
<span>{result.data.name}</span>
37+
</>
38+
)
39+
}
40+
2041
function FloatingIpLabel({ fip }: { fip: FloatingIp }) {
2142
return (
2243
<div className="text-secondary selected:text-accent-secondary">
2344
<div>{fip.name}</div>
2445
<div className="flex gap-0.5">
2546
<div>{fip.ip}</div>
47+
<IpPoolName ipPoolId={fip.ipPoolId} />
2648
{fip.description && (
2749
<>
2850
<Slash />

app/pages/project/instances/NetworkingTab.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ import { type LoaderFunctionArgs } from 'react-router'
1111
import { match } from 'ts-pattern'
1212

1313
import {
14+
apiqErrorsAllowed,
1415
apiQueryClient,
1516
instanceCan,
17+
queryClient,
1618
useApiMutation,
1719
useApiQuery,
1820
useApiQueryClient,
@@ -118,8 +120,20 @@ export async function clientLoader({ params }: LoaderFunctionArgs) {
118120
path: { instance },
119121
query: { project },
120122
}),
121-
// This is used in AttachEphemeralIpModal
122-
apiQueryClient.fetchQuery('projectIpPoolList', { query: { limit: ALL_ISH } }),
123+
// Fetch IP Pools and preload into RQ cache so fetches by ID in
124+
// IpPoolCell and AttachFloatingIpModal can be mostly instant
125+
apiQueryClient
126+
.fetchQuery('projectIpPoolList', { query: { limit: ALL_ISH } })
127+
.then((pools) => {
128+
for (const pool of pools.items) {
129+
// both IpPoolCell and the fetch in the model use errors-allowed
130+
// versions to avoid blowing up in the unlikely event of an error
131+
const { queryKey } = apiqErrorsAllowed('projectIpPoolView', {
132+
path: { pool: pool.id },
133+
})
134+
queryClient.setQueryData(queryKey, { type: 'success', data: pool })
135+
}
136+
}),
123137
])
124138
return null
125139
}

0 commit comments

Comments
 (0)