3
3
// Use of this software is governed by the CockroachDB Software License
4
4
// included in the /LICENSE file.
5
5
6
+ import { createHash } from "crypto" ;
7
+
6
8
import {
7
9
Loading ,
8
10
Text ,
9
11
Anchor ,
10
12
util ,
11
13
TimezoneContext ,
14
+ SortSetting ,
15
+ ISortedTablePagination ,
12
16
} from "@cockroachlabs/cluster-ui" ;
13
17
import classNames from "classnames/bind" ;
14
- import React , { useRef , useMemo , useEffect , useContext } from "react" ;
18
+ import React , { useRef , useMemo , useEffect , useContext , useState } from "react" ;
15
19
import { Helmet } from "react-helmet" ;
16
20
import { useDispatch , useSelector } from "react-redux" ;
17
21
18
22
import { cockroach } from "src/js/protos" ;
23
+ import { analytics } from "src/redux/analytics" ;
19
24
import {
20
25
refreshHotRanges ,
21
26
clearHotRanges ,
@@ -63,6 +68,8 @@ const HotRangesPage = () => {
63
68
const timezone = useContext ( TimezoneContext ) ;
64
69
65
70
const { filters, applyFilters } = useFilters ( ) ;
71
+ const [ sortSetting , setSortSetting ] = useState < SortSetting > ( null ) ;
72
+ const [ pagination , setPagination ] = useState < ISortedTablePagination > ( null ) ;
66
73
67
74
// dispatch hot ranges call whenever the filters change and are not empty
68
75
useEffect ( ( ) => {
@@ -77,6 +84,28 @@ const HotRangesPage = () => {
77
84
}
78
85
} , [ filters . nodeIds , dispatch ] ) ;
79
86
87
+ // track analytics on filters, pagination and sort.
88
+ const analyticsKey = createHash ( "md5" )
89
+ . update ( JSON . stringify ( [ filters , sortSetting , pagination ] ) )
90
+ . digest ( "hex" ) ;
91
+ useEffect ( ( ) => {
92
+ if ( ! filters . nodeIds . length || ! pagination || ! sortSetting ) {
93
+ return ;
94
+ }
95
+ analytics . track ( {
96
+ event : "Hot Ranges Page Load" ,
97
+ properties : {
98
+ filters,
99
+ pagination,
100
+ sortSetting,
101
+ } ,
102
+ } ) ;
103
+ // this is keyed on a hash of the contents for filters, pagination and sortSetting
104
+ // as opposed to the references themselves, as we don't want to re-run this effect
105
+ // when the contents haven't changed, but the references have.
106
+ // eslint-disable-next-line react-hooks/exhaustive-deps
107
+ } , [ analyticsKey ] ) ;
108
+
80
109
// load the databases if possible.
81
110
useEffect ( ( ) => {
82
111
dispatch ( refreshDatabases ( ) ) ;
@@ -129,6 +158,16 @@ const HotRangesPage = () => {
129
158
nodeIdToLocalityMap = { nodeIdToLocalityMap }
130
159
clearFilterContainer = { < span ref = { clearButtonRef } /> }
131
160
emptyMessage = { emptyMessage }
161
+ onViewPropertiesChange = { ( {
162
+ sortSetting,
163
+ pagination,
164
+ } : {
165
+ sortSetting : SortSetting ;
166
+ pagination : ISortedTablePagination ;
167
+ } ) => {
168
+ setSortSetting ( sortSetting ) ;
169
+ setPagination ( pagination ) ;
170
+ } }
132
171
/>
133
172
) }
134
173
page = { undefined }
0 commit comments