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

Commit

Permalink
feat: show fresh/stale colors for inactive queries
Browse files Browse the repository at this point in the history
  • Loading branch information
tannerlinsley committed Jun 25, 2020
1 parent 552808d commit cc6d808
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
20 changes: 15 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ import {
Select,
} from './styledComponents'
import { ThemeProvider } from './theme'
import { getQueryStatusLabel, getQueryStatusColor } from './utils'
import {
getQueryStatusLabel,
getQueryStatusColor,
getQueryOpacity,
} from './utils'
import Explorer from './Explorer'
import Logo from './Logo'

Expand Down Expand Up @@ -171,8 +175,7 @@ const sortFns = {

export const ReactQueryDevtoolsPanel = React.forwardRef(
function ReactQueryDevtoolsPanel(props, ref) {

const queryCache = useQueryCache ? useQueryCache() : cache;
const queryCache = useQueryCache ? useQueryCache() : cache

const [sort, setSort] = useLocalStorage(
'reactQueryDevtoolsSortFn',
Expand Down Expand Up @@ -217,7 +220,13 @@ export const ReactQueryDevtoolsPanel = React.forwardRef(

return [
activeQuery,
activeQuery ? JSON.parse(JSON.stringify(activeQuery, (key, value) => key === 'cache' ? undefined : value)) : null,
activeQuery
? JSON.parse(
JSON.stringify(activeQuery, (key, value) =>
key === 'cache' ? undefined : value
)
)
: null,
]
}, [activeQueryHash, queries])

Expand All @@ -236,7 +245,7 @@ export const ReactQueryDevtoolsPanel = React.forwardRef(
return queryCache.subscribe(queryCache => {
setUnsortedQueries(Object.values(queryCache.queries))
})
}, [sort, sortFn, sortDesc])
}, [sort, sortFn, sortDesc, queryCache])

React.useEffect(() => {
if (activeQueryHash && !activeQuery) {
Expand Down Expand Up @@ -399,6 +408,7 @@ export const ReactQueryDevtoolsPanel = React.forwardRef(
width: '2rem',
height: '2rem',
background: getQueryStatusColor(query, theme),
opacity: getQueryOpacity(query),
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
Expand Down
6 changes: 4 additions & 2 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import useMediaQuery from './useMediaQuery'
export function getQueryStatusColor(query, theme) {
return query.state.isFetching
? theme.active
: !query.instances.length
? theme.gray
: query.state.isStale
? theme.warning
: theme.success
}

export function getQueryOpacity(query) {
return !query.instances.length ? 0.3 : 1
}

export function getQueryStatusLabel(query) {
return query.state.isFetching
? 'fetching'
Expand Down

0 comments on commit cc6d808

Please sign in to comment.