Skip to content

Commit 8dcddce

Browse files
Add dropdown to instance breadcrumb (#2392)
* Add dropdown to instance breadcrumb * on instance delete success, invalidate instance list before navigating --------- Co-authored-by: David Crespo <[email protected]>
1 parent f53bb38 commit 8dcddce

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

app/components/TopBarPicker.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,14 +326,21 @@ export function ProjectPicker({ project }: { project?: Project }) {
326326
export function InstancePicker() {
327327
// picker only shows up when an instance is in scope
328328
const instanceSelector = useInstanceSelector()
329-
const { instance } = instanceSelector
330-
329+
const { project, instance } = instanceSelector
330+
const { data: instances } = useApiQuery('instanceList', {
331+
query: { project, limit: PAGE_SIZE },
332+
})
333+
const items = (instances?.items || []).map(({ name }) => ({
334+
label: name,
335+
to: pb.instance({ project, instance: name }),
336+
}))
331337
return (
332338
<TopBarPicker
333339
aria-label="Switch instance"
334340
category="Instance"
335341
current={instance}
336-
to={pb.instanceStorage(instanceSelector)}
342+
to={pb.instance({ project, instance })}
343+
items={items}
337344
noItemsText="No instances found"
338345
/>
339346
)

app/pages/project/instances/InstancesPage.tsx

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,7 @@ import { filesize } from 'filesize'
1010
import { useMemo } from 'react'
1111
import { useNavigate, type LoaderFunctionArgs } from 'react-router-dom'
1212

13-
import {
14-
apiQueryClient,
15-
useApiQueryClient,
16-
usePrefetchedApiQuery,
17-
type Instance,
18-
} from '@oxide/api'
13+
import { apiQueryClient, usePrefetchedApiQuery, type Instance } from '@oxide/api'
1914
import { Instances16Icon, Instances24Icon } from '@oxide/design-system/icons/react'
2015

2116
import { DocsPopover } from '~/components/DocsPopover'
@@ -55,12 +50,11 @@ InstancesPage.loader = async ({ params }: LoaderFunctionArgs) => {
5550
return null
5651
}
5752

53+
const refetchInstances = () => apiQueryClient.invalidateQueries('instanceList')
54+
5855
export function InstancesPage() {
5956
const { project } = useProjectSelector()
6057

61-
const queryClient = useApiQueryClient()
62-
const refetchInstances = () => queryClient.invalidateQueries('instanceList')
63-
6458
const makeActions = useMakeInstanceActions(
6559
{ project },
6660
{ onSuccess: refetchInstances, onDelete: refetchInstances }

app/pages/project/instances/instance/InstancePage.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,10 @@ export function InstancePage() {
9494
const makeActions = useMakeInstanceActions(instanceSelector, {
9595
onSuccess: refreshData,
9696
// go to project instances list since there's no more instance
97-
onDelete: () => navigate(pb.instances(instanceSelector)),
97+
onDelete: () => {
98+
apiQueryClient.invalidateQueries('instanceList')
99+
navigate(pb.instances(instanceSelector))
100+
},
98101
})
99102

100103
const { data: instance } = usePrefetchedApiQuery(

0 commit comments

Comments
 (0)