@tanstack/react-query-devtools 4.10.0 → 4.10.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/lib/devtools.esm.js +10 -16
- package/build/lib/devtools.esm.js.map +1 -1
- package/build/lib/devtools.js +9 -15
- package/build/lib/devtools.js.map +1 -1
- package/build/lib/devtools.mjs +10 -16
- package/build/lib/devtools.mjs.map +1 -1
- package/build/lib/index.prod.esm.js +26 -24
- package/build/lib/index.prod.esm.js.map +1 -1
- package/build/lib/index.prod.js +25 -23
- package/build/lib/index.prod.js.map +1 -1
- package/build/lib/index.prod.mjs +26 -24
- package/build/lib/index.prod.mjs.map +1 -1
- package/build/lib/utils.d.ts +2 -1
- package/build/lib/utils.esm.js +16 -8
- package/build/lib/utils.esm.js.map +1 -1
- package/build/lib/utils.js +16 -8
- package/build/lib/utils.js.map +1 -1
- package/build/lib/utils.mjs +16 -8
- package/build/lib/utils.mjs.map +1 -1
- package/build/umd/index.development.js +25 -34
- package/build/umd/index.development.js.map +1 -1
- package/package.json +4 -4
- package/src/__tests__/devtools.test.tsx +2 -2
- package/src/devtools.tsx +18 -21
- package/src/utils.ts +20 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/react-query-devtools",
|
|
3
|
-
"version": "4.10.
|
|
3
|
+
"version": "4.10.2",
|
|
4
4
|
"description": "TODO",
|
|
5
5
|
"author": "tannerlinsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -40,17 +40,17 @@
|
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@types/use-sync-external-store": "^0.0.3",
|
|
42
42
|
"react-error-boundary": "^3.1.4",
|
|
43
|
-
"@tanstack/react-query": "4.10.
|
|
44
|
-
"superjson": "^1.10.0"
|
|
43
|
+
"@tanstack/react-query": "4.10.1"
|
|
45
44
|
},
|
|
46
45
|
"dependencies": {
|
|
47
46
|
"@tanstack/match-sorter-utils": "^8.1.1",
|
|
47
|
+
"superjson": "^1.10.0",
|
|
48
48
|
"use-sync-external-store": "^1.2.0"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
51
|
"react": "^16.8.0 || ^17.0.0 || ^18.0.0",
|
|
52
52
|
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0",
|
|
53
|
-
"@tanstack/react-query": "4.10.
|
|
53
|
+
"@tanstack/react-query": "4.10.1"
|
|
54
54
|
},
|
|
55
55
|
"scripts": {
|
|
56
56
|
"clean": "rm -rf ./build",
|
|
@@ -555,7 +555,7 @@ describe('ReactQueryDevtools', () => {
|
|
|
555
555
|
})
|
|
556
556
|
|
|
557
557
|
it('should initialize filtering and sorting values with defaults when they are not stored in localstorage', () => {
|
|
558
|
-
localStorage.removeItem('
|
|
558
|
+
localStorage.removeItem('reactQueryDevtoolsBaseSort')
|
|
559
559
|
localStorage.removeItem('reactQueryDevtoolsSortFn')
|
|
560
560
|
localStorage.removeItem('reactQueryDevtoolsFilter')
|
|
561
561
|
|
|
@@ -593,7 +593,7 @@ describe('ReactQueryDevtools', () => {
|
|
|
593
593
|
})
|
|
594
594
|
|
|
595
595
|
it('should initialize sorting values with ones stored in localstorage', async () => {
|
|
596
|
-
localStorage.setItem('
|
|
596
|
+
localStorage.setItem('reactQueryDevtoolsBaseSort', 'true')
|
|
597
597
|
localStorage.setItem(
|
|
598
598
|
'reactQueryDevtoolsSortFn',
|
|
599
599
|
JSON.stringify(Object.keys(sortFns)[1]),
|
package/src/devtools.tsx
CHANGED
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
onlineManager,
|
|
12
12
|
notifyManager,
|
|
13
13
|
} from '@tanstack/react-query'
|
|
14
|
-
import { rankItem
|
|
14
|
+
import { rankItem } from '@tanstack/match-sorter-utils'
|
|
15
15
|
import useLocalStorage from './useLocalStorage'
|
|
16
16
|
import { sortFns, useIsMounted } from './utils'
|
|
17
17
|
import ScreenReader from './screenreader'
|
|
@@ -418,9 +418,9 @@ export const ReactQueryDevtoolsPanel = React.forwardRef<
|
|
|
418
418
|
|
|
419
419
|
const [filter, setFilter] = useLocalStorage('reactQueryDevtoolsFilter', '')
|
|
420
420
|
|
|
421
|
-
const [
|
|
422
|
-
'
|
|
423
|
-
|
|
421
|
+
const [baseSort, setBaseSort] = useLocalStorage(
|
|
422
|
+
'reactQueryDevtoolsBaseSort',
|
|
423
|
+
1,
|
|
424
424
|
)
|
|
425
425
|
|
|
426
426
|
const sortFn = React.useMemo(() => sortFns[sort as string], [sort])
|
|
@@ -438,26 +438,23 @@ export const ReactQueryDevtoolsPanel = React.forwardRef<
|
|
|
438
438
|
|
|
439
439
|
const queries = React.useMemo(() => {
|
|
440
440
|
const unsortedQueries = queryCache.getAll()
|
|
441
|
-
const sorted = queriesCount > 0 ? [...unsortedQueries].sort(sortFn) : []
|
|
442
441
|
|
|
443
|
-
if (
|
|
444
|
-
|
|
442
|
+
if (queriesCount === 0) {
|
|
443
|
+
return []
|
|
445
444
|
}
|
|
446
445
|
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
(item) => [item, rankItem(item.queryHash, filter)] as const,
|
|
453
|
-
)
|
|
454
|
-
|
|
455
|
-
ranked = ranked.filter((d) => d[1].passed)
|
|
446
|
+
const filtered = filter
|
|
447
|
+
? unsortedQueries.filter(
|
|
448
|
+
(item) => rankItem(item.queryHash, filter).passed,
|
|
449
|
+
)
|
|
450
|
+
: [...unsortedQueries]
|
|
456
451
|
|
|
457
|
-
|
|
452
|
+
const sorted = sortFn
|
|
453
|
+
? filtered.sort((a, b) => sortFn(a, b) * (baseSort as number))
|
|
454
|
+
: filtered
|
|
458
455
|
|
|
459
|
-
return
|
|
460
|
-
}, [
|
|
456
|
+
return sorted
|
|
457
|
+
}, [baseSort, sortFn, filter, queriesCount, queryCache])
|
|
461
458
|
|
|
462
459
|
const [isMockOffline, setMockOffline] = React.useState(false)
|
|
463
460
|
|
|
@@ -596,13 +593,13 @@ export const ReactQueryDevtoolsPanel = React.forwardRef<
|
|
|
596
593
|
</Select>
|
|
597
594
|
<Button
|
|
598
595
|
type="button"
|
|
599
|
-
onClick={() =>
|
|
596
|
+
onClick={() => setBaseSort((old) => old * -1)}
|
|
600
597
|
style={{
|
|
601
598
|
padding: '.3em .4em',
|
|
602
599
|
marginRight: '.5em',
|
|
603
600
|
}}
|
|
604
601
|
>
|
|
605
|
-
{
|
|
602
|
+
{baseSort === 1 ? '⬆ Asc' : '⬇ Desc'}
|
|
606
603
|
</Button>
|
|
607
604
|
<Button
|
|
608
605
|
type="button"
|
package/src/utils.ts
CHANGED
|
@@ -124,6 +124,9 @@ export const displayValue = (value: unknown) => {
|
|
|
124
124
|
return JSON.stringify(json)
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
+
// Sorting functions
|
|
128
|
+
type SortFn = (a: Query, b: Query) => number
|
|
129
|
+
|
|
127
130
|
const getStatusRank = (q: Query) =>
|
|
128
131
|
q.state.fetchStatus !== 'idle'
|
|
129
132
|
? 0
|
|
@@ -133,14 +136,21 @@ const getStatusRank = (q: Query) =>
|
|
|
133
136
|
? 2
|
|
134
137
|
: 1
|
|
135
138
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
139
|
+
const queryHashSort: SortFn = (a, b) => a.queryHash.localeCompare(b.queryHash)
|
|
140
|
+
|
|
141
|
+
const dateSort: SortFn = (a, b) =>
|
|
142
|
+
a.state.dataUpdatedAt < b.state.dataUpdatedAt ? 1 : -1
|
|
143
|
+
|
|
144
|
+
const statusAndDateSort: SortFn = (a, b) => {
|
|
145
|
+
if (getStatusRank(a) === getStatusRank(b)) {
|
|
146
|
+
return dateSort(a, b)
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return getStatusRank(a) > getStatusRank(b) ? 1 : -1
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export const sortFns: Record<string, SortFn> = {
|
|
153
|
+
'Status > Last Updated': statusAndDateSort,
|
|
154
|
+
'Query Hash': queryHashSort,
|
|
155
|
+
'Last Updated': dateSort,
|
|
146
156
|
}
|