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

Commit 87ccbb8

Browse files
committed
fix: use new observers instead of instances, better styles, display updated timestamp
1 parent 1bda05b commit 87ccbb8

File tree

4 files changed

+84
-53
lines changed

4 files changed

+84
-53
lines changed

src/Explorer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ export default function Explorer({
112112
defaultExpanded,
113113
renderer = DefaultRenderer,
114114
pageSize = 100,
115+
depth = 0,
115116
...rest
116117
}) {
117118
const [expanded, setExpanded] = React.useState(defaultExpanded)
@@ -121,7 +122,6 @@ export default function Explorer({
121122
}
122123

123124
const path = []
124-
const depth = 0
125125

126126
let type = typeof value
127127
let subEntries

src/index.js

Lines changed: 61 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
Input,
1515
Select,
1616
QueryCountStyles,
17+
ActiveQueryPanel,
1718
} from './styledComponents'
1819
import { ThemeProvider } from './theme'
1920
import {
@@ -207,7 +208,7 @@ export function ReactQueryDevtools({
207208
}
208209

209210
const getStatusRank = q =>
210-
q.state.isFetching ? 0 : !q.instances.length ? 3 : q.state.isStale ? 2 : 1
211+
q.state.isFetching ? 0 : !q.observers.length ? 3 : q.state.isStale ? 2 : 1
211212

212213
const sortFns = {
213214
'Status > Last Updated': (a, b) =>
@@ -282,7 +283,10 @@ export const ReactQueryDevtoolsPanel = React.forwardRef(
282283
Object.values(queryCache.queries)
283284
)
284285

285-
const [activeQueryHash, setActiveQueryHash] = React.useState(null)
286+
const [activeQueryHash, setActiveQueryHash] = useLocalStorage(
287+
'reactQueryDevtoolsActiveQueryHash',
288+
''
289+
)
286290

287291
const queries = React.useMemo(() => {
288292
const sorted = [...unsortedQueries].sort(sortFn)
@@ -296,17 +300,8 @@ export const ReactQueryDevtoolsPanel = React.forwardRef(
296300
)
297301
}, [sortDesc, sortFn, unsortedQueries, filter])
298302

299-
const [activeQuery, activeQueryJson] = React.useMemo(() => {
300-
const activeQuery = queries.find(
301-
query => query.queryHash === activeQueryHash
302-
)
303-
304-
return [
305-
activeQuery,
306-
activeQuery
307-
? JSON.parse(JSON.stringify(activeQuery, getCircularReplacer()))
308-
: null,
309-
]
303+
const activeQuery = React.useMemo(() => {
304+
return queries.find(query => query.queryHash === activeQueryHash)
310305
}, [activeQueryHash, queries])
311306

312307
const hasFresh = queries.filter(q => getQueryStatusLabel(q) === 'fresh')
@@ -326,12 +321,6 @@ export const ReactQueryDevtoolsPanel = React.forwardRef(
326321
})
327322
}, [sort, sortFn, sortDesc, queryCache])
328323

329-
React.useEffect(() => {
330-
if (activeQueryHash && !activeQuery) {
331-
setActiveQueryHash(null)
332-
}
333-
}, [activeQuery, activeQueryHash])
334-
335324
return (
336325
<ThemeProvider theme={theme}>
337326
<Panel ref={ref} className="ReactQueryDevtoolsPanel" {...panelProps}>
@@ -508,7 +497,7 @@ export const ReactQueryDevtoolsPanel = React.forwardRef(
508497
: 'white',
509498
}}
510499
>
511-
{query.instances.length}
500+
{query.observers.length}
512501
</div>
513502
<Code
514503
style={{
@@ -522,55 +511,72 @@ export const ReactQueryDevtoolsPanel = React.forwardRef(
522511
</div>
523512
</div>
524513
{activeQuery ? (
525-
<div
526-
style={{
527-
flex: '1 1 500px',
528-
display: 'flex',
529-
flexDirection: 'column',
530-
overflow: 'auto',
531-
height: '100%',
532-
}}
533-
>
514+
<ActiveQueryPanel>
534515
<div
535516
style={{
536517
padding: '.5rem',
537518
background: theme.backgroundAlt,
519+
position: 'sticky',
520+
top: 0,
521+
zIndex: 1,
538522
}}
539523
>
540524
Query Details
541525
</div>
542526
<div
543527
style={{
544-
padding: '1rem',
545-
display: 'flex',
546-
alignItems: 'center',
547-
justifyContent: 'space-between',
528+
padding: '.5rem 0',
548529
}}
549530
>
550-
<Code
531+
<div
551532
style={{
552-
lineHeight: '1.8rem',
533+
padding: '.5rem 1rem',
534+
display: 'flex',
535+
alignItems: 'center',
536+
justifyContent: 'space-between',
553537
}}
554538
>
555-
{activeQuery.queryHash}
556-
</Code>
557-
<span
539+
<Code
540+
style={{
541+
lineHeight: '1.8rem',
542+
}}
543+
>
544+
{activeQuery.queryHash}
545+
</Code>
546+
<span
547+
style={{
548+
padding: '0.3rem .6rem',
549+
borderRadius: '0.4rem',
550+
fontWeight: 'bold',
551+
textShadow: '0 2px 10px black',
552+
background: getQueryStatusColor(activeQuery, theme),
553+
flexShrink: 0,
554+
}}
555+
>
556+
{getQueryStatusLabel(activeQuery)}
557+
</span>
558+
</div>
559+
<div
558560
style={{
559-
padding: '0.3rem .6rem',
560-
borderRadius: '0.4rem',
561-
fontWeight: 'bold',
562-
textShadow: '0 2px 10px black',
563-
background: getQueryStatusColor(activeQuery, theme),
564-
flexShrink: 0,
561+
padding: '.5rem 1rem',
562+
display: 'flex',
563+
alignItems: 'center',
564+
justifyContent: 'space-between',
565565
}}
566566
>
567-
{getQueryStatusLabel(activeQuery)}
568-
</span>
567+
Last Updated:{' '}
568+
<Code>
569+
{new Date(activeQuery.state.updatedAt).toLocaleTimeString()}
570+
</Code>
571+
</div>
569572
</div>
570573
<div
571574
style={{
572575
background: theme.backgroundAlt,
573576
padding: '.5rem',
577+
position: 'sticky',
578+
top: 0,
579+
zIndex: 1,
574580
}}
575581
>
576582
Actions
@@ -604,6 +610,9 @@ export const ReactQueryDevtoolsPanel = React.forwardRef(
604610
style={{
605611
background: theme.backgroundAlt,
606612
padding: '.5rem',
613+
position: 'sticky',
614+
top: 0,
615+
zIndex: 1,
607616
}}
608617
>
609618
Data Explorer
@@ -615,14 +624,17 @@ export const ReactQueryDevtoolsPanel = React.forwardRef(
615624
>
616625
<Explorer
617626
label="Data"
618-
value={activeQueryJson.state.data}
627+
value={activeQuery?.state?.data}
619628
defaultExpanded={{}}
620629
/>
621630
</div>
622631
<div
623632
style={{
624633
background: theme.backgroundAlt,
625634
padding: '.5rem',
635+
position: 'sticky',
636+
top: 0,
637+
zIndex: 1,
626638
}}
627639
>
628640
Query Explorer
@@ -634,13 +646,13 @@ export const ReactQueryDevtoolsPanel = React.forwardRef(
634646
>
635647
<Explorer
636648
label="Query"
637-
value={activeQueryJson}
649+
value={activeQuery}
638650
defaultExpanded={{
639651
queryKey: true,
640652
}}
641653
/>
642654
</div>
643-
</div>
655+
</ActiveQueryPanel>
644656
) : null}
645657
</Panel>
646658
</ThemeProvider>

src/styledComponents.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,38 @@ export const Panel = styled(
44
'div',
55
(props, theme) => ({
66
fontSize: 'clamp(12px, 1.5vw, 14px)',
7+
fontFamily: `sans-serif`,
78
display: 'flex',
8-
flexWrap: 'wrap',
99
backgroundColor: theme.background,
1010
color: theme.foreground,
1111
}),
1212
{
13+
'(max-width: 700px)': {
14+
flexDirection: 'column',
15+
},
1316
'(max-width: 600px)': {
1417
fontSize: '.9rem',
1518
// flexDirection: 'column',
1619
},
1720
}
1821
)
1922

23+
export const ActiveQueryPanel = styled(
24+
'div',
25+
(props, theme) => ({
26+
flex: '1 1 500px',
27+
display: 'flex',
28+
flexDirection: 'column',
29+
overflow: 'auto',
30+
height: '100%',
31+
}),
32+
{
33+
'(max-width: 700px)': (props, theme) => ({
34+
borderTop: `2px solid ${theme.gray}`,
35+
}),
36+
}
37+
)
38+
2039
export const Button = styled('button', (props, theme) => ({
2140
appearance: 'none',
2241
fontSize: '.9em',

src/utils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ export function getQueryStatusColor(query, theme) {
1212
}
1313

1414
export function getQueryOpacity(query) {
15-
return !query.instances.length ? 0.3 : 1
15+
return !query.observers.length ? 0.3 : 1
1616
}
1717

1818
export function getQueryStatusLabel(query) {
1919
return query.state.isFetching
2020
? 'fetching'
21-
: !query.instances.length
21+
: !query.observers.length
2222
? 'inactive'
2323
: query.state.isStale
2424
? 'stale'

0 commit comments

Comments
 (0)