Skip to content
Open
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
43 changes: 14 additions & 29 deletions packages/query-devtools/src/Devtools.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1853,64 +1853,49 @@ const QueryDetails = () => {
const [restoringLoading, setRestoringLoading] = createSignal(false)
const [dataMode, setDataMode] = createSignal<'view' | 'edit'>('view')
const [dataEditError, setDataEditError] = createSignal<boolean>(false)
const getSelectedQuery = (queryCache: Accessor<QueryCache>) => {
const queryHash = selectedQueryHash()
return queryHash ? queryCache().get(queryHash) : undefined
}

const errorTypes = createMemo(() => {
return useQueryDevtoolsContext().errorTypes || []
})

const activeQuery = createSubscribeToQueryCacheBatcher(
(queryCache) =>
queryCache()
.getAll()
.find((query) => query.queryHash === selectedQueryHash()),
(queryCache) => getSelectedQuery(queryCache),
false,
)

const activeQueryFresh = createSubscribeToQueryCacheBatcher((queryCache) => {
return queryCache()
.getAll()
.find((query) => query.queryHash === selectedQueryHash())
}, false)
const activeQueryFresh = createSubscribeToQueryCacheBatcher(
(queryCache) => getSelectedQuery(queryCache),
false,
)
Comment thread
coderabbitai[bot] marked this conversation as resolved.

const activeQueryState = createSubscribeToQueryCacheBatcher(
(queryCache) =>
queryCache()
.getAll()
.find((query) => query.queryHash === selectedQueryHash())?.state,
(queryCache) => getSelectedQuery(queryCache)?.state,
false,
)

const activeQueryStateData = createSubscribeToQueryCacheBatcher(
(queryCache) => {
return queryCache()
.getAll()
.find((query) => query.queryHash === selectedQueryHash())?.state.data
},
(queryCache) => getSelectedQuery(queryCache)?.state.data,
false,
)

const statusLabel = createSubscribeToQueryCacheBatcher((queryCache) => {
const query = queryCache()
.getAll()
.find((q) => q.queryHash === selectedQueryHash())
const query = getSelectedQuery(queryCache)
if (!query) return 'inactive'
return getQueryStatusLabel(query)
})

const queryStatus = createSubscribeToQueryCacheBatcher((queryCache) => {
const query = queryCache()
.getAll()
.find((q) => q.queryHash === selectedQueryHash())
const query = getSelectedQuery(queryCache)
if (!query) return 'pending'
return query.state.status
})

const observerCount = createSubscribeToQueryCacheBatcher(
(queryCache) =>
queryCache()
.getAll()
.find((query) => query.queryHash === selectedQueryHash())
?.getObserversCount() ?? 0,
(queryCache) => getSelectedQuery(queryCache)?.getObserversCount() ?? 0,
)

const color = createMemo(() => getQueryStatusColorByLabel(statusLabel()))
Expand Down
16 changes: 16 additions & 0 deletions packages/query-devtools/src/__tests__/Devtools.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,22 @@ describe('Devtools', () => {
rendered.getByLabelText(/Query key \["mutable-key",\{"page":1\}\]/),
).toBeInTheDocument()
})

it('should render query details for a custom query hash', () => {
const query = queryClient.getQueryCache().build(queryClient, {
queryKey: ['custom-query-hash'],
queryFn: () => 'x',
queryKeyHashFn: () => 'custom-query-hash-value',
})
query.setData('x')
const rendered = renderDevtools({ initialIsOpen: true })

fireEvent.click(
rendered.getByLabelText('Query key custom-query-hash-value'),
)

expect(rendered.getByText('Query Details')).toBeInTheDocument()
})
})

describe('picture-in-picture', () => {
Expand Down