Skip to content

Commit 6cd25c9

Browse files
authored
Add minitable to Floating IP side modal (#2630)
1 parent a629300 commit 6cd25c9

File tree

2 files changed

+52
-10
lines changed

2 files changed

+52
-10
lines changed

app/forms/floating-ip-edit.tsx

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,41 @@
66
* Copyright Oxide Computer Company
77
*/
88
import { 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

1319
import { DescriptionField } from '~/components/form/fields/DescriptionField'
1420
import { NameField } from '~/components/form/fields/NameField'
1521
import { SideModalForm } from '~/components/form/SideModalForm'
1622
import { HL } from '~/components/HL'
1723
import { getFloatingIpSelector, useFloatingIpSelector } from '~/hooks/use-params'
1824
import { 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'
1930
import type * as PP from '~/util/path-params'
2031
import { pb } from 'app/util/path-builder'
2132

2233
const 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

2538
EditFloatingIpSideModalForm.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>

app/pages/project/floating-ips/FloatingIpsPage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ const instanceList = (project: string) =>
6161
FloatingIpsPage.loader = async ({ params }: LoaderFunctionArgs) => {
6262
const { project } = getProjectSelector(params)
6363
await Promise.all([
64-
queryClient.prefetchQuery(fipList(project).optionsFn()),
65-
queryClient.prefetchQuery(instanceList(project).optionsFn()),
64+
queryClient.fetchQuery(fipList(project).optionsFn()),
65+
queryClient.fetchQuery(instanceList(project).optionsFn()),
6666
// fetch IP Pools and preload into RQ cache so fetches by ID in
6767
// IpPoolCell can be mostly instant yet gracefully fall back to
6868
// fetching individually if we don't fetch them all here

0 commit comments

Comments
 (0)