Skip to content

Commit

Permalink
Add dropdown to instance breadcrumb (#2392)
Browse files Browse the repository at this point in the history
* Add dropdown to instance breadcrumb

* on instance delete success, invalidate instance list before navigating

---------

Co-authored-by: David Crespo <[email protected]>
  • Loading branch information
charliepark and david-crespo authored Aug 20, 2024
1 parent f53bb38 commit 8dcddce
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
13 changes: 10 additions & 3 deletions app/components/TopBarPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -326,14 +326,21 @@ export function ProjectPicker({ project }: { project?: Project }) {
export function InstancePicker() {
// picker only shows up when an instance is in scope
const instanceSelector = useInstanceSelector()
const { instance } = instanceSelector

const { project, instance } = instanceSelector
const { data: instances } = useApiQuery('instanceList', {
query: { project, limit: PAGE_SIZE },
})
const items = (instances?.items || []).map(({ name }) => ({
label: name,
to: pb.instance({ project, instance: name }),
}))
return (
<TopBarPicker
aria-label="Switch instance"
category="Instance"
current={instance}
to={pb.instanceStorage(instanceSelector)}
to={pb.instance({ project, instance })}
items={items}
noItemsText="No instances found"
/>
)
Expand Down
12 changes: 3 additions & 9 deletions app/pages/project/instances/InstancesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@ import { filesize } from 'filesize'
import { useMemo } from 'react'
import { useNavigate, type LoaderFunctionArgs } from 'react-router-dom'

import {
apiQueryClient,
useApiQueryClient,
usePrefetchedApiQuery,
type Instance,
} from '@oxide/api'
import { apiQueryClient, usePrefetchedApiQuery, type Instance } from '@oxide/api'
import { Instances16Icon, Instances24Icon } from '@oxide/design-system/icons/react'

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

const refetchInstances = () => apiQueryClient.invalidateQueries('instanceList')

export function InstancesPage() {
const { project } = useProjectSelector()

const queryClient = useApiQueryClient()
const refetchInstances = () => queryClient.invalidateQueries('instanceList')

const makeActions = useMakeInstanceActions(
{ project },
{ onSuccess: refetchInstances, onDelete: refetchInstances }
Expand Down
5 changes: 4 additions & 1 deletion app/pages/project/instances/instance/InstancePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ export function InstancePage() {
const makeActions = useMakeInstanceActions(instanceSelector, {
onSuccess: refreshData,
// go to project instances list since there's no more instance
onDelete: () => navigate(pb.instances(instanceSelector)),
onDelete: () => {
apiQueryClient.invalidateQueries('instanceList')
navigate(pb.instances(instanceSelector))
},
})

const { data: instance } = usePrefetchedApiQuery(
Expand Down

0 comments on commit 8dcddce

Please sign in to comment.