Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dropdown to instance breadcrumb #2392

Merged
merged 2 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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')

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes in this file are irrelevant to the fix, but I did this while debugging and I like it better.

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))
},
Copy link
Collaborator

@david-crespo david-crespo Aug 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a legit bug, and I know why this change turned it up. The failure was that the expected disappearance of you-fail from the instance list was not happening.

What happens in this delete from instance detail test is:

  1. go to the instance detail page for you-fail
  2. delete it
  3. let it automatically land us on the list view
  4. confirm the instance is gone

Before this PR, there was nothing on the instance detail page "observing" the instanceList query, so when we nav to instance list on delete success, that query will always be fetched fresh because it is "new" from RQ's point of view. But with this PR, there is now the breadcrumb that uses the list of instances, so the query is "active" on the instance detail page.

Here is the funny bit: when you do what the test does by hand, you inevitably sit on the you-fail page longer than the 2 seconds required for the query to become stale. That means it will automatically refetch when the loader fires for the instance list page on navigation. But the test is faster than you, so it lands on the instance detail and hits delete in under 2 seconds, so the query is not stale by the time we land on the instance list and therefore does not refetch. I confirmed this theory by adding a sleep to the test so it sits on the page for 2 seconds before clicking delete. That makes the test pass! But of course the real fix is to specifically invalidate the instance list in the delete success callback.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, wow. Good sleuthing on this.

})

const { data: instance } = usePrefetchedApiQuery(
Expand Down
Loading