1
+ /* eslint-disable no-param-reassign */
1
2
/* eslint-disable guard-for-in */
2
3
/* eslint-disable no-restricted-syntax */
3
- // @ts -nocheck
4
4
import React , { useState , useEffect } from 'react' ;
5
5
import {
6
6
MemoryRouter as Router ,
@@ -15,7 +15,7 @@ import BarGraphComparison from './BarGraphComparison';
15
15
import BarGraphComparisonActions from './BarGraphComparisonActions' ;
16
16
import { useStoreContext } from '../../../store' ;
17
17
import { setCurrentTabInApp } from '../../../actions/actions' ;
18
-
18
+ import { Bar } from '@visx/shape' ;
19
19
20
20
interface BarStackProps {
21
21
width : number ;
@@ -82,8 +82,10 @@ const collectNodes = (snaps, componentName) => {
82
82
return finalResults ;
83
83
} ;
84
84
85
+ type currNum = number
86
+
85
87
/* DATA HANDLING HELPER FUNCTIONS */
86
- const traverse = ( snapshot , data , snapshots , currTotalRender = 0 ) => {
88
+ const traverse = ( snapshot , data , snapshots , currTotalRender : currNum = 0 ) : void => {
87
89
if ( ! snapshot . children [ 0 ] ) return ;
88
90
89
91
// loop through snapshots
@@ -95,7 +97,7 @@ const traverse = (snapshot, data, snapshots, currTotalRender = 0) => {
95
97
Number . parseFloat ( child . componentData . actualDuration ) . toPrecision ( 5 ) ,
96
98
) ;
97
99
// sums render time for all children
98
- currTotalRender += renderTime ;
100
+ const childrenRenderTime = currTotalRender + renderTime ;
99
101
// components as keys and set the value to their rendering time
100
102
data . barStack [ data . barStack . length - 1 ] [ componentName ] = renderTime ;
101
103
@@ -120,11 +122,10 @@ const traverse = (snapshot, data, snapshots, currTotalRender = 0) => {
120
122
// Get rtid for the hovering feature
121
123
data . componentData [ componentName ] . rtid = child . rtid ;
122
124
data . componentData [ componentName ] . information = collectNodes ( snapshots , child . name ) ;
123
- traverse ( snapshot . children [ idx ] , data , snapshots , currTotalRender ) ;
125
+ traverse ( snapshot . children [ idx ] , data , snapshots , childrenRenderTime ) ;
124
126
} ) ;
125
127
// reassigns total render time to max render time
126
128
data . maxTotalRender = Math . max ( currTotalRender , data . maxTotalRender ) ;
127
- return data ;
128
129
} ;
129
130
130
131
// Retrieve snapshot series data from Chrome's local storage.
@@ -145,9 +146,17 @@ const getSnapshotIds = (obj, snapshotIds = []): string[] => {
145
146
return snapshotIds ;
146
147
} ;
147
148
149
+ type BarStackProp = Record < string , unknown >
150
+
151
+ interface PerfData {
152
+ barStack : BarStackProp [ ] ,
153
+ componentData ?: Record < string , unknown > ,
154
+ maxTotalRender : number ,
155
+ }
156
+
148
157
// Returns array of snapshot objs each with components and corresponding render times.
149
- const getPerfMetrics = ( snapshots , snapshotsIds ) : { } => {
150
- const perfData = {
158
+ const getPerfMetrics = ( snapshots , snapshotsIds ) : PerfData => {
159
+ const perfData : PerfData = {
151
160
barStack : [ ] ,
152
161
componentData : { } ,
153
162
maxTotalRender : 0 ,
@@ -160,12 +169,12 @@ const getPerfMetrics = (snapshots, snapshotsIds): {} => {
160
169
} ;
161
170
162
171
/* EXPORT COMPONENT */
163
- const PerformanceVisx = ( props : BarStackProps ) => {
172
+ const PerformanceVisx = ( props : BarStackProps ) : JSX . Element => {
164
173
// hook used to dispatch onhover action in rect
165
174
const {
166
175
width, height, snapshots, hierarchy,
167
176
} = props ;
168
- const [ { tabs , currentTab , currentTabInApp } , dispatch ] = useStoreContext ( ) ;
177
+ const [ { currentTabInApp } , dispatch ] = useStoreContext ( ) ;
169
178
const NO_STATE_MSG = 'No state change detected. Trigger an event to change state' ;
170
179
const data = getPerfMetrics ( snapshots , getSnapshotIds ( hierarchy ) ) ;
171
180
const [ series , setSeries ] = useState ( true ) ;
@@ -178,10 +187,22 @@ const PerformanceVisx = (props: BarStackProps) => {
178
187
dispatch ( setCurrentTabInApp ( 'performance' ) ) ;
179
188
} , [ dispatch ] ) ;
180
189
190
+ type Series = {
191
+ data : {
192
+ barStack : ActionObj [ ] ,
193
+ }
194
+ name : string
195
+ }
196
+
197
+ type ActionObj = {
198
+ name : unknown ,
199
+ seriesName : unknown ,
200
+ }
201
+
181
202
// Creates the actions array used to populate the compare actions dropdown
182
203
const getActions = ( ) => {
183
- let seriesArr = localStorage . getItem ( 'project' ) ;
184
- seriesArr = seriesArr === null ? [ ] : JSON . parse ( seriesArr ) ;
204
+ const project = localStorage . getItem ( 'project' ) ;
205
+ const seriesArr : Series [ ] = project === null ? [ ] : JSON . parse ( project ) ;
185
206
const actionsArr = [ ] ;
186
207
187
208
if ( seriesArr . length ) {
@@ -244,13 +265,12 @@ const PerformanceVisx = (props: BarStackProps) => {
244
265
data . barStack = filteredSnapshots ;
245
266
}
246
267
247
-
268
+ // maxheight is referring to the max height in render time to choose the scaling size for graph
269
+ let maxHeight = 0 ;
248
270
if ( snapshot !== 'All Snapshots' ) {
249
271
// filter barStack to make it equal to an array of length 1 with object matching snapshot ID to mirror the data.barStack object's shape
250
272
const checkData = [ data . barStack . find ( comp => comp . snapshotId === snapshot ) ] ;
251
273
const holdData = [ ] ;
252
- // maxheight is referring to the max height in render time to choose the scaling size for graph
253
- let maxHeight = 0 ;
254
274
// looping through checkData which is composed of a single snapshot while pushing key/values to a new object and setting maxHeight
255
275
for ( const key in checkData [ 0 ] ) {
256
276
if ( key !== 'route' && key !== 'snapshotId' ) {
0 commit comments