5
5
/* eslint-disable @typescript-eslint/no-var-requires */
6
6
/* eslint-disable max-len */
7
7
/* eslint-disable object-curly-newline */
8
- import React , { useState } from ' react' ;
8
+ import React , { useState } from " react" ;
9
9
import {
10
10
MemoryRouter as Router ,
11
11
Route ,
12
12
NavLink ,
13
13
Switch ,
14
- } from ' react-router-dom' ;
15
- import { ParentSize } from ' @visx/responsive' ;
16
- import Tree from ' ./Tree' ;
17
- import ComponentMap from ' ./ComponentMap' ;
18
- import { changeView , changeSlider } from ' ../actions/actions' ;
19
- import { useStoreContext } from ' ../store' ;
20
- import PerformanceVisx from ' ./PerformanceVisx' ;
21
- import Legend from ' ./AtomsRelationshipLegend' ;
22
- import AtomsRelationship from ' ./AtomsRelationship' ;
23
- import WebMetrics from ' ./WebMetrics' ;
14
+ } from " react-router-dom" ;
15
+ import { ParentSize } from " @visx/responsive" ;
16
+ import Tree from " ./Tree" ;
17
+ import ComponentMap from " ./ComponentMap" ;
18
+ import { changeView , changeSlider } from " ../actions/actions" ;
19
+ import { useStoreContext } from " ../store" ;
20
+ import PerformanceVisx from " ./PerformanceVisx" ;
21
+ import Legend from " ./AtomsRelationshipLegend" ;
22
+ import AtomsRelationship from " ./AtomsRelationship" ;
23
+ import WebMetrics from " ./WebMetrics" ;
24
24
25
- const History = require ( ' ./History' ) . default ;
26
- const ErrorHandler = require ( ' ./ErrorHandler' ) . default ;
25
+ const History = require ( " ./History" ) . default ;
26
+ const ErrorHandler = require ( " ./ErrorHandler" ) . default ;
27
27
28
28
const NO_STATE_MSG =
29
- ' No state change detected. Trigger an event to change state' ;
29
+ " No state change detected. Trigger an event to change state" ;
30
30
// eslint-disable-next-line react/prop-types
31
31
32
32
export interface StateRouteProps {
@@ -50,15 +50,15 @@ const StateRoute = (props: StateRouteProps) => {
50
50
const [ { tabs, currentTab } , dispatch ] = useStoreContext ( ) ;
51
51
const { hierarchy, sliderIndex, viewIndex } = tabs [ currentTab ] ;
52
52
const isRecoil = snapshot . atomsComponents ? true : false ;
53
-
53
+
54
54
const [ noRenderData , setNoRenderData ] = useState ( false ) ;
55
55
// component map zoom state
56
56
const [ { x, y, k } , setZoomState ] : any = useState ( {
57
57
x : 150 ,
58
58
y : 250 ,
59
59
k : 1 ,
60
60
} ) ;
61
- console . log ( ' webMetrics in StateRoute Props >>>>' , webMetrics ) ;
61
+ console . log ( " webMetrics in StateRoute Props >>>>" , webMetrics ) ;
62
62
// Map
63
63
const renderComponentMap = ( ) => {
64
64
if ( hierarchy ) {
@@ -70,7 +70,7 @@ const StateRoute = (props: StateRouteProps) => {
70
70
</ ParentSize >
71
71
) ;
72
72
}
73
- return < div className = ' noState' > { NO_STATE_MSG } </ div > ;
73
+ return < div className = " noState" > { NO_STATE_MSG } </ div > ;
74
74
} ;
75
75
76
76
// the hierarchy gets set upon the first click on the page
@@ -89,7 +89,7 @@ const StateRoute = (props: StateRouteProps) => {
89
89
/>
90
90
) ;
91
91
}
92
- return < div className = ' noState' > { NO_STATE_MSG } </ div > ;
92
+ return < div className = " noState" > { NO_STATE_MSG } </ div > ;
93
93
} ;
94
94
95
95
const renderAtomsRelationship = ( ) => (
@@ -113,34 +113,52 @@ const StateRoute = (props: StateRouteProps) => {
113
113
if ( hierarchy ) {
114
114
return < Tree snapshot = { snapshot } /> ;
115
115
}
116
- return < div className = ' noState' > { NO_STATE_MSG } </ div > ;
116
+ return < div className = " noState" > { NO_STATE_MSG } </ div > ;
117
117
} ;
118
118
const renderWebMetrics = ( ) => {
119
119
let LCPColor , FIDColor , CLSColor , FCPColor , TTFBColor ;
120
120
121
121
if ( webMetrics . LCP <= 2000 ) LCPColor = "#0bce6b" ;
122
122
if ( webMetrics . LCP > 2000 && webMetrics . LCP < 4000 ) LCPColor = "#E56543" ;
123
- if ( webMetrics . LCP > 4000 ) LCPColor = "#fc2000" ;
123
+ if ( webMetrics . LCP > 4000 ) LCPColor = "#fc2000" ;
124
124
if ( webMetrics . FID <= 100 ) FIDColor = "#0bce6b" ;
125
- if ( webMetrics . FID > 100 && webMetrics . FID <= 300 ) FIDColor = "#fc5a03" ;
126
- if ( webMetrics . FID > 300 ) FIDColor = "#fc2000" ;
125
+ if ( webMetrics . FID > 100 && webMetrics . FID <= 300 ) FIDColor = "#fc5a03" ;
126
+ if ( webMetrics . FID > 300 ) FIDColor = "#fc2000" ;
127
127
if ( webMetrics . FCP <= 9000 ) FCPColor = "#0bce6b" ;
128
- if ( webMetrics . FCP > 900 && webMetrics . FCP <= 1100 ) FCPColor = "#fc5a03" ;
129
- if ( webMetrics . FCP > 1100 ) FCPColor = "#fc2000" ;
128
+ if ( webMetrics . FCP > 900 && webMetrics . FCP <= 1100 ) FCPColor = "#fc5a03" ;
129
+ if ( webMetrics . FCP > 1100 ) FCPColor = "#fc2000" ;
130
130
if ( webMetrics . TTFB <= 600 ) TTFBColor = "#0bce6b" ;
131
- if ( webMetrics . TTFB > 600 ) TTFBColor = "#fc2000" ;
132
-
131
+ if ( webMetrics . TTFB > 600 ) TTFBColor = "#fc2000" ;
133
132
134
-
135
133
return (
136
134
< div className = "web-metrics-container" >
137
- < WebMetrics color = { LCPColor } series = { ( webMetrics . LCP / 2500 ) * 100 } formatted = { ( val ) => ( ( val / 100 ) * 2500 ) . toFixed ( 2 ) + ' ms' } label = "LCP" />
138
- < WebMetrics color = { FIDColor } series = { ( webMetrics . FID ) * 25 } formatted = { ( val ) => ( ( val / 25 ) ) . toFixed ( 2 ) + ' ms' } label = "FID" />
139
- < WebMetrics color = { FCPColor } series = { ( webMetrics . FCP / 1000 ) * 100 } formatted = { ( val ) => ( ( val / 100 ) * 1000 ) . toFixed ( 2 ) + ' ms' } label = "FCP" />
140
- < WebMetrics color = { TTFBColor } series = { ( webMetrics . TTFB / 10 ) * 100 } formatted = { ( val ) => ( ( val / 100 ) * 10 ) . toFixed ( 2 ) + ' ms' } label = "TTFB" />
141
- < div id = 'hoverText' > Testing</ div >
135
+ < WebMetrics
136
+ color = { LCPColor }
137
+ series = { ( webMetrics . LCP / 2500 ) * 100 }
138
+ formatted = { ( val ) => ( ( val / 100 ) * 2500 ) . toFixed ( 2 ) + " ms" }
139
+ label = "LCP"
140
+ />
141
+ < WebMetrics
142
+ color = { FIDColor }
143
+ series = { webMetrics . FID * 25 }
144
+ formatted = { ( val ) => ( val / 25 ) . toFixed ( 2 ) + " ms" }
145
+ label = "FID"
146
+ />
147
+ < WebMetrics
148
+ color = { FCPColor }
149
+ series = { ( webMetrics . FCP / 1000 ) * 100 }
150
+ formatted = { ( val ) => ( ( val / 100 ) * 1000 ) . toFixed ( 2 ) + " ms" }
151
+ label = "FCP"
152
+ />
153
+ < WebMetrics
154
+ color = { TTFBColor }
155
+ series = { ( webMetrics . TTFB / 10 ) * 100 }
156
+ formatted = { ( val ) => ( ( val / 100 ) * 10 ) . toFixed ( 2 ) + " ms" }
157
+ label = "TTFB"
158
+ />
142
159
</ div >
143
- ) } ;
160
+ ) ;
161
+ } ;
144
162
145
163
const renderPerfView = ( ) => {
146
164
if ( hierarchy ) {
@@ -159,61 +177,61 @@ const StateRoute = (props: StateRouteProps) => {
159
177
</ ParentSize >
160
178
) ;
161
179
}
162
- return < div className = ' noState' > { NO_STATE_MSG } </ div > ;
180
+ return < div className = " noState" > { NO_STATE_MSG } </ div > ;
163
181
} ;
164
182
165
183
return (
166
184
< Router >
167
- < div className = ' navbar' >
185
+ < div className = " navbar" >
168
186
< NavLink
169
- className = ' router-link'
170
- activeClassName = ' is-active'
187
+ className = " router-link"
188
+ activeClassName = " is-active"
171
189
exact
172
- to = '/'
190
+ to = "/"
173
191
>
174
192
Map
175
193
</ NavLink >
176
194
< NavLink
177
- className = ' router-link'
178
- activeClassName = ' is-active'
179
- to = ' /performance'
195
+ className = " router-link"
196
+ activeClassName = " is-active"
197
+ to = " /performance"
180
198
>
181
199
Performance
182
200
</ NavLink >
183
201
< NavLink
184
- className = ' router-link'
185
- activeClassName = ' is-active'
186
- to = ' /history'
202
+ className = " router-link"
203
+ activeClassName = " is-active"
204
+ to = " /history"
187
205
>
188
206
History
189
207
</ NavLink >
190
208
< NavLink
191
- className = ' router-link'
192
- activeClassName = ' is-active'
193
- to = ' /webMetrics'
209
+ className = " router-link"
210
+ activeClassName = " is-active"
211
+ to = " /webMetrics"
194
212
>
195
213
Web Metrics
196
214
</ NavLink >
197
- < NavLink className = ' router-link' activeClassName = ' is-active' to = ' /tree' >
215
+ < NavLink className = " router-link" activeClassName = " is-active" to = " /tree" >
198
216
Tree
199
217
</ NavLink >
200
218
{ isRecoil && (
201
219
< NavLink
202
- className = ' router-link'
203
- activeClassName = ' is-active'
204
- to = ' /relationship'
220
+ className = " router-link"
221
+ activeClassName = " is-active"
222
+ to = " /relationship"
205
223
>
206
224
AtomsRecoil
207
225
</ NavLink >
208
226
) }
209
227
</ div >
210
228
< Switch >
211
- < Route path = ' /performance' render = { renderPerfView } />
212
- < Route path = ' /history' render = { renderHistory } />
213
- < Route path = ' /relationship' render = { renderAtomsRelationship } />
214
- < Route path = ' /webMetrics' render = { renderWebMetrics } />
215
- < Route path = ' /tree' render = { renderTree } />
216
- < Route path = '/' render = { renderComponentMap } />
229
+ < Route path = " /performance" render = { renderPerfView } />
230
+ < Route path = " /history" render = { renderHistory } />
231
+ < Route path = " /relationship" render = { renderAtomsRelationship } />
232
+ < Route path = " /webMetrics" render = { renderWebMetrics } />
233
+ < Route path = " /tree" render = { renderTree } />
234
+ < Route path = "/" render = { renderComponentMap } />
217
235
</ Switch >
218
236
</ Router >
219
237
) ;
0 commit comments