File tree Expand file tree Collapse file tree 6 files changed +51
-21
lines changed
packages/react-query-devtools/src/timeline Expand file tree Collapse file tree 6 files changed +51
-21
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ import useTimelineEvents from './useTimelineEvents'
9
9
import { SVGQueryTimeline , TooltipOptions } from './timelineComponents'
10
10
import { useTheme } from '../theme'
11
11
import TimelineOptions from './timelineOptions'
12
+ import ReactDOM from 'react-dom'
12
13
13
14
function clampValue ( value : number , min : number , max : number ) {
14
15
return Math . min ( Math . max ( value , min ) , max )
@@ -129,18 +130,24 @@ export function TimelinePanel(props: TimelinePanelProps) {
129
130
130
131
return (
131
132
< >
132
- { tooltip && (
133
- < div
134
- style = { {
135
- position : 'absolute' ,
136
- top : tooltip . y ,
137
- left : tooltip . x ,
138
- backgroundColor : theme . background ,
139
- } }
140
- >
141
- { tooltip . content }
142
- </ div >
143
- ) }
133
+ { tooltip &&
134
+ ReactDOM . createPortal (
135
+ < div
136
+ style = { {
137
+ position : 'absolute' ,
138
+ top : tooltip . y + 10 ,
139
+ left : tooltip . x + 10 ,
140
+ backgroundColor : theme . gray ,
141
+ fontFamily : 'sans-serif' ,
142
+ zIndex : 100000 ,
143
+ color : 'white' ,
144
+ padding : '.5em' ,
145
+ } }
146
+ >
147
+ { tooltip . content }
148
+ </ div > ,
149
+ document . body ,
150
+ ) }
144
151
< PanelMain isOpen = { isOpen } >
145
152
< PanelHead { ...headProps } >
146
153
< TimelineOptions
Original file line number Diff line number Diff line change @@ -5,7 +5,11 @@ import {
5
5
ReactQueryQueryEvent ,
6
6
} from './useTimelineEvents'
7
7
8
- import { computeObserverCountBoxes , computeQueryBoxes } from './utils'
8
+ import {
9
+ computeObserverCountBoxes ,
10
+ computeQueryBoxes ,
11
+ formatMillisecondsDuration ,
12
+ } from './utils'
9
13
10
14
export type TooltipOptions = {
11
15
x : number
@@ -98,6 +102,7 @@ export const SVGQueryTimeline = React.forwardRef<
98
102
{ boxes . map ( ( item ) => {
99
103
const counts = computeObserverCountBoxes ( item )
100
104
105
+ const cacheTime = formatMillisecondsDuration ( item . cacheTime )
101
106
return (
102
107
< g key = { item . startAt . getTime ( ) } >
103
108
< rect
@@ -106,7 +111,7 @@ export const SVGQueryTimeline = React.forwardRef<
106
111
width = { scaleX ( item . endAt ) - scaleX ( item . startAt ) }
107
112
height = "22"
108
113
fill = "#8798bf42"
109
- { ...getTooltipProps ( `Cache time: ${ item . cacheTime } ms ` ) }
114
+ { ...getTooltipProps ( `Cache time: ${ cacheTime } ` ) }
110
115
/>
111
116
{ counts . map ( ( count ) => (
112
117
< React . Fragment key = { count . start . getTime ( ) } >
Original file line number Diff line number Diff line change 1
- import React from 'react'
1
+ import * as React from 'react'
2
2
import { Input } from '../styledComponents'
3
3
import useTimelineEvents from './useTimelineEvents'
4
4
@@ -33,13 +33,9 @@ export default function TimelineOptions({
33
33
alignSelf : 'flex-end' ,
34
34
} }
35
35
>
36
- < button onClick = { ( ) => setZoom ( ( zoom ) => clampZoom ( zoom * 1.5 ) ) } >
37
- -
38
- </ button >
36
+ < button onClick = { ( ) => setZoom ( ( z ) => clampZoom ( z * 1.5 ) ) } > -</ button >
39
37
{ Math . floor ( ( zoomBasis / zoom ) * 100 ) } %
40
- < button onClick = { ( ) => setZoom ( ( zoom ) => clampZoom ( zoom / 1.5 ) ) } >
41
- +
42
- </ button >
38
+ < button onClick = { ( ) => setZoom ( ( z ) => clampZoom ( z / 1.5 ) ) } > +</ button >
43
39
</ div >
44
40
< div
45
41
style = { {
Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ describe('computeQueryBoxes', () => {
28
28
expect . objectContaining ( {
29
29
startAt : new Date ( '2022-07-20T13:19:15.000Z' ) ,
30
30
endAt : new Date ( '2022-07-20T13:19:59.999Z' ) ,
31
+ cacheTime : 300000 ,
31
32
} ) ,
32
33
)
33
34
} )
Original file line number Diff line number Diff line change @@ -38,6 +38,7 @@ export function computeQueryBoxes(
38
38
sortedEvents . forEach ( ( event ) => {
39
39
if ( event . eventType === 'added' ) {
40
40
partial . startAt = event . receivedAt
41
+ partial . cacheTime = event . cacheTime
41
42
} else if ( event . eventType === 'removed' ) {
42
43
items . push ( {
43
44
...createBox ( partial ) ,
@@ -102,3 +103,22 @@ export function computeObserverCountBoxes(query: Box) {
102
103
103
104
return counts . filter ( ( c ) => c . count !== 0 )
104
105
}
106
+
107
+ export function formatMillisecondsDuration ( ms : number | undefined ) {
108
+ if ( ! ms ) return null
109
+
110
+ const minutes = Math . floor ( ms / 60000 )
111
+ const seconds = Math . floor ( ( ms % 60000 ) / 1000 )
112
+ const milliseconds = Math . floor ( ( ms % 60000 ) % 1000 )
113
+
114
+ const zipped : [ number , string ] [ ] = [
115
+ [ minutes , 'min' ] ,
116
+ [ seconds , 's' ] ,
117
+ [ milliseconds , 'ms' ] ,
118
+ ]
119
+
120
+ return zipped
121
+ . filter ( ( [ count , _ ] ) => count > 0 )
122
+ . map ( ( [ count , unit ] ) => `${ count } ${ unit } ` )
123
+ . join ( ' ' )
124
+ }
Original file line number Diff line number Diff line change @@ -83,6 +83,7 @@ export default function rollup(options: RollupOptions): RollupOptions[] {
83
83
entryFile : 'src/index.ts' ,
84
84
globals : {
85
85
react : 'React' ,
86
+ 'react-dom' : 'ReactDOM' ,
86
87
'@tanstack/react-query' : 'ReactQuery' ,
87
88
} ,
88
89
} ) ,
You can’t perform that action at this time.
0 commit comments