66 * Copyright Oxide Computer Company
77 */
88import { useForm } from 'react-hook-form'
9- import { useNavigate , type LoaderFunctionArgs } from 'react-router'
9+ import { Link , useNavigate , type LoaderFunctionArgs } from 'react-router'
1010
11- import { apiq , queryClient , useApiMutation , usePrefetchedApiQuery } from '@oxide/api'
11+ import {
12+ apiq ,
13+ getListQFn ,
14+ queryClient ,
15+ useApiMutation ,
16+ usePrefetchedQuery ,
17+ } from '@oxide/api'
1218
1319import { DescriptionField } from '~/components/form/fields/DescriptionField'
1420import { NameField } from '~/components/form/fields/NameField'
1521import { SideModalForm } from '~/components/form/SideModalForm'
1622import { HL } from '~/components/HL'
1723import { getFloatingIpSelector , useFloatingIpSelector } from '~/hooks/use-params'
1824import { addToast } from '~/stores/toast'
25+ import { EmptyCell } from '~/table/cells/EmptyCell'
26+ import { IpPoolCell } from '~/table/cells/IpPoolCell'
27+ import { CopyableIp } from '~/ui/lib/CopyableIp'
28+ import { PropertiesTable } from '~/ui/lib/PropertiesTable'
29+ import { ALL_ISH } from '~/util/consts'
1930import type * as PP from '~/util/path-params'
2031import { pb } from 'app/util/path-builder'
2132
2233const floatingIpView = ( { project, floatingIp } : PP . FloatingIp ) =>
2334 apiq ( 'floatingIpView' , { path : { floatingIp } , query : { project } } )
35+ const instanceList = ( project : string ) =>
36+ getListQFn ( 'instanceList' , { query : { project, limit : ALL_ISH } } )
2437
2538EditFloatingIpSideModalForm . loader = async ( { params } : LoaderFunctionArgs ) => {
2639 const selector = getFloatingIpSelector ( params )
27- await queryClient . prefetchQuery ( floatingIpView ( selector ) )
40+ await Promise . all ( [
41+ queryClient . fetchQuery ( floatingIpView ( selector ) ) ,
42+ queryClient . fetchQuery ( instanceList ( selector . project ) . optionsFn ( ) ) ,
43+ ] )
2844 return null
2945}
3046
@@ -35,10 +51,11 @@ export function EditFloatingIpSideModalForm() {
3551
3652 const onDismiss = ( ) => navigate ( pb . floatingIps ( { project : floatingIpSelector . project } ) )
3753
38- const { data : floatingIp } = usePrefetchedApiQuery ( 'floatingIpView' , {
39- path : { floatingIp : floatingIpSelector . floatingIp } ,
40- query : { project : floatingIpSelector . project } ,
41- } )
54+ const { data : floatingIp } = usePrefetchedQuery ( floatingIpView ( floatingIpSelector ) )
55+ const { data : instances } = usePrefetchedQuery (
56+ instanceList ( floatingIpSelector . project ) . optionsFn ( )
57+ )
58+ const instanceName = instances . items . find ( ( i ) => i . id === floatingIp . instanceId ) ?. name
4259
4360 const editFloatingIp = useApiMutation ( 'floatingIpUpdate' , {
4461 onSuccess ( _floatingIp ) {
@@ -49,7 +66,6 @@ export function EditFloatingIpSideModalForm() {
4966 } )
5067
5168 const form = useForm ( { defaultValues : floatingIp } )
52-
5369 return (
5470 < SideModalForm
5571 form = { form }
@@ -66,6 +82,32 @@ export function EditFloatingIpSideModalForm() {
6682 loading = { editFloatingIp . isPending }
6783 submitError = { editFloatingIp . error }
6884 >
85+ < PropertiesTable >
86+ < PropertiesTable . IdRow id = { floatingIp . id } />
87+ < PropertiesTable . DateRow label = "Created" date = { floatingIp . timeCreated } />
88+ < PropertiesTable . DateRow label = "Updated" date = { floatingIp . timeModified } />
89+ < PropertiesTable . Row label = "IP Address" >
90+ < CopyableIp ip = { floatingIp . ip } isLinked = { false } />
91+ </ PropertiesTable . Row >
92+ < PropertiesTable . Row label = "IP Pool" >
93+ < IpPoolCell ipPoolId = { floatingIp . ipPoolId } />
94+ </ PropertiesTable . Row >
95+ < PropertiesTable . Row label = "Instance" >
96+ { instanceName ? (
97+ < Link
98+ to = { pb . instanceNetworking ( {
99+ project : floatingIpSelector . project ,
100+ instance : instanceName ,
101+ } ) }
102+ className = "link-with-underline group text-sans-md"
103+ >
104+ { instanceName }
105+ </ Link >
106+ ) : (
107+ < EmptyCell />
108+ ) }
109+ </ PropertiesTable . Row >
110+ </ PropertiesTable >
69111 < NameField name = "name" control = { form . control } />
70112 < DescriptionField name = "description" control = { form . control } />
71113 </ SideModalForm >
0 commit comments