@@ -13,6 +13,8 @@ import AutoSizer from 'react-virtualized-auto-sizer';
13
13
import { FixedSizeList } from 'react-window' ;
14
14
import SnapshotCommitListItem from './SnapshotCommitListItem' ;
15
15
import { minBarWidth } from './constants' ;
16
+ import { formatDuration , formatTime } from './utils' ;
17
+ import Tooltip from './Tooltip' ;
16
18
17
19
import styles from './SnapshotCommitList.css' ;
18
20
@@ -24,6 +26,7 @@ export type ItemData = {|
24
26
selectedCommitIndex : number | null ,
25
27
selectedFilteredCommitIndex : number | null ,
26
28
selectCommitIndex : ( index : number ) => void ,
29
+ setHoveredCommitIndex : ( index : number ) => void ,
27
30
startCommitDrag : ( newDragState : DragState ) => void ,
28
31
| } ;
29
32
@@ -166,6 +169,10 @@ function List({
166
169
}
167
170
} , [ dragState ] ) ;
168
171
172
+ const [ hoveredCommitIndex , setHoveredCommitIndex ] = useState < number | null > (
173
+ null ,
174
+ ) ;
175
+
169
176
// Pass required contextual data down to the ListItem renderer.
170
177
const itemData = useMemo < ItemData > (
171
178
( ) => ( {
@@ -176,6 +183,7 @@ function List({
176
183
selectedCommitIndex,
177
184
selectedFilteredCommitIndex,
178
185
selectCommitIndex,
186
+ setHoveredCommitIndex,
179
187
startCommitDrag : setDragState ,
180
188
} ) ,
181
189
[
@@ -186,22 +194,37 @@ function List({
186
194
selectedCommitIndex ,
187
195
selectedFilteredCommitIndex ,
188
196
selectCommitIndex ,
197
+ setHoveredCommitIndex ,
189
198
] ,
190
199
) ;
191
200
201
+ let tooltipLabel = null ;
202
+ if ( hoveredCommitIndex !== null ) {
203
+ const commitDuration = commitDurations [ hoveredCommitIndex ] ;
204
+ const commitTime = commitTimes [ hoveredCommitIndex ] ;
205
+ tooltipLabel = `${ formatDuration ( commitDuration ) } ms at ${ formatTime (
206
+ commitTime ,
207
+ ) } s`;
208
+ }
209
+
192
210
return (
193
- < div ref = { divRef } style = { { height, width} } >
194
- < FixedSizeList
195
- className = { styles . List }
196
- layout = "horizontal"
197
- height = { height }
198
- itemCount = { filteredCommitIndices . length }
199
- itemData = { itemData }
200
- itemSize = { itemSize }
201
- ref = { ( listRef : any ) /* Flow bug? */ }
202
- width = { width } >
203
- { SnapshotCommitListItem }
204
- </ FixedSizeList >
205
- </ div >
211
+ < Tooltip label = { tooltipLabel } >
212
+ < div
213
+ ref = { divRef }
214
+ style = { { height, width} }
215
+ onMouseLeave = { ( ) => setHoveredCommitIndex ( null ) } >
216
+ < FixedSizeList
217
+ className = { styles . List }
218
+ layout = "horizontal"
219
+ height = { height }
220
+ itemCount = { filteredCommitIndices . length }
221
+ itemData = { itemData }
222
+ itemSize = { itemSize }
223
+ ref = { ( listRef : any ) /* Flow bug? */ }
224
+ width = { width } >
225
+ { SnapshotCommitListItem }
226
+ </ FixedSizeList >
227
+ </ div >
228
+ </ Tooltip >
206
229
) ;
207
230
}
0 commit comments