Skip to content
This repository was archived by the owner on Jan 2, 2021. It is now read-only.

Commit cc6d808

Browse files
committed
feat: show fresh/stale colors for inactive queries
1 parent 552808d commit cc6d808

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

src/index.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ import {
1616
Select,
1717
} from './styledComponents'
1818
import { ThemeProvider } from './theme'
19-
import { getQueryStatusLabel, getQueryStatusColor } from './utils'
19+
import {
20+
getQueryStatusLabel,
21+
getQueryStatusColor,
22+
getQueryOpacity,
23+
} from './utils'
2024
import Explorer from './Explorer'
2125
import Logo from './Logo'
2226

@@ -171,8 +175,7 @@ const sortFns = {
171175

172176
export const ReactQueryDevtoolsPanel = React.forwardRef(
173177
function ReactQueryDevtoolsPanel(props, ref) {
174-
175-
const queryCache = useQueryCache ? useQueryCache() : cache;
178+
const queryCache = useQueryCache ? useQueryCache() : cache
176179

177180
const [sort, setSort] = useLocalStorage(
178181
'reactQueryDevtoolsSortFn',
@@ -217,7 +220,13 @@ export const ReactQueryDevtoolsPanel = React.forwardRef(
217220

218221
return [
219222
activeQuery,
220-
activeQuery ? JSON.parse(JSON.stringify(activeQuery, (key, value) => key === 'cache' ? undefined : value)) : null,
223+
activeQuery
224+
? JSON.parse(
225+
JSON.stringify(activeQuery, (key, value) =>
226+
key === 'cache' ? undefined : value
227+
)
228+
)
229+
: null,
221230
]
222231
}, [activeQueryHash, queries])
223232

@@ -236,7 +245,7 @@ export const ReactQueryDevtoolsPanel = React.forwardRef(
236245
return queryCache.subscribe(queryCache => {
237246
setUnsortedQueries(Object.values(queryCache.queries))
238247
})
239-
}, [sort, sortFn, sortDesc])
248+
}, [sort, sortFn, sortDesc, queryCache])
240249

241250
React.useEffect(() => {
242251
if (activeQueryHash && !activeQuery) {
@@ -399,6 +408,7 @@ export const ReactQueryDevtoolsPanel = React.forwardRef(
399408
width: '2rem',
400409
height: '2rem',
401410
background: getQueryStatusColor(query, theme),
411+
opacity: getQueryOpacity(query),
402412
display: 'flex',
403413
alignItems: 'center',
404414
justifyContent: 'center',

src/utils.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ import useMediaQuery from './useMediaQuery'
66
export function getQueryStatusColor(query, theme) {
77
return query.state.isFetching
88
? theme.active
9-
: !query.instances.length
10-
? theme.gray
119
: query.state.isStale
1210
? theme.warning
1311
: theme.success
1412
}
1513

14+
export function getQueryOpacity(query) {
15+
return !query.instances.length ? 0.3 : 1
16+
}
17+
1618
export function getQueryStatusLabel(query) {
1719
return query.state.isFetching
1820
? 'fetching'

0 commit comments

Comments
 (0)