Open History to see the last commit
1import React from 'react'
2import type { QueryCache } from '@tanstack/react-query'
3β
4import { Code, QueryKey, QueryKeys } from '../../styledComponents'
5import { getQueryStatusLabel } from '../../utils'
6import useSubscribeToQueryCache from '../../useSubscribeToQueryCache'
7import { defaultTheme as theme } from '../../theme'
8β
9/**
10 * Displays the number of queries for each status
11 */
12export default function QueryStatusCount({
13 queryCache,
14}: {
15 queryCache: QueryCache
16}) {
17 const hasFresh = useSubscribeToQueryCache(
18 queryCache,
19 () =>
20 queryCache.getAll().filter((q) => getQueryStatusLabel(q) === 'fresh')
21 .length,
22 )
23 const hasFetching = useSubscribeToQueryCache(
24 queryCache,
25 () =>
26 queryCache.getAll().filter((q) => getQueryStatusLabel(q) === 'fetching')
27 .length,
28 )
29 const hasPaused = useSubscribeToQueryCache(
30 queryCache,
31 () =>
32 queryCache.getAll().filter((q) => getQueryStatusLabel(q) === 'paused')
33 .length,
34 )
35 const hasStale = useSubscribeToQueryCache(
36 queryCache,
37 () =>
38 queryCache.getAll().filter((q) => getQueryStatusLabel(q) === 'stale')
39 .length,
40 )
41 const hasInactive = useSubscribeToQueryCache(
42 queryCache,
43 () =>
44 queryCache.getAll().filter((q) => getQueryStatusLabel(q) === 'inactive')
45 .length,
46 )
47 return (
48 <QueryKeys>
49 <QueryKey
50 style={{
51 background: theme.success,
52 opacity: hasFresh ? 1 : 0.3,
53 }}
54 >
55 fresh <Code>({hasFresh})</Code>
56 </QueryKey>{' '}
57 <QueryKey
58 style={{
59 background: theme.active,
60 opacity: hasFetching ? 1 : 0.3,
61 }}
62 >
63 fetching <Code>({hasFetching})</Code>
64 </QueryKey>{' '}
65 <QueryKey
66 style={{
67 background: theme.paused,
68 opacity: hasPaused ? 1 : 0.3,
69 }}
70 >
71 paused <Code>({hasPaused})</Code>
72 </QueryKey>{' '}
73 <QueryKey
74 style={{
75 background: theme.warning,
76 color: 'black',
77 textShadow: '0',
78 opacity: hasStale ? 1 : 0.3,
79 }}
80 >
81 stale <Code>({hasStale})</Code>
82 </QueryKey>{' '}
83 <QueryKey
84 style={{
85 background: theme.gray,
86 opacity: hasInactive ? 1 : 0.3,
87 }}
88 >
89 inactive <Code>({hasInactive})</Code>
90 </QueryKey>
91 </QueryKeys>
92 )
93}