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 {
@@ -69,7 +69,7 @@ const StateRoute = (props: StateRouteProps) => {
69
69
</ ParentSize >
70
70
) ;
71
71
}
72
- return < div className = " noState" > { NO_STATE_MSG } </ div > ;
72
+ return < div className = ' noState' > { NO_STATE_MSG } </ div > ;
73
73
} ;
74
74
75
75
// the hierarchy gets set upon the first click on the page
@@ -88,7 +88,7 @@ const StateRoute = (props: StateRouteProps) => {
88
88
/>
89
89
) ;
90
90
}
91
- return < div className = " noState" > { NO_STATE_MSG } </ div > ;
91
+ return < div className = ' noState' > { NO_STATE_MSG } </ div > ;
92
92
} ;
93
93
94
94
const renderAtomsRelationship = ( ) => (
@@ -112,33 +112,63 @@ const StateRoute = (props: StateRouteProps) => {
112
112
if ( hierarchy ) {
113
113
return < Tree snapshot = { snapshot } /> ;
114
114
}
115
- return < div className = " noState" > { NO_STATE_MSG } </ div > ;
115
+ return < div className = ' noState' > { NO_STATE_MSG } </ div > ;
116
116
} ;
117
117
const renderWebMetrics = ( ) => {
118
118
let LCPColor , FIDColor , FCPColor , TTFBColor ;
119
119
120
- if ( webMetrics . LCP <= 2000 ) LCPColor = " #0bce6b" ;
121
- if ( webMetrics . LCP > 2000 && webMetrics . LCP < 4000 ) LCPColor = " #E56543" ;
122
- if ( webMetrics . LCP > 4000 ) LCPColor = " #fc2000" ;
123
- if ( webMetrics . FID <= 100 ) FIDColor = " #0bce6b" ;
124
- if ( webMetrics . FID > 100 && webMetrics . FID <= 300 ) FIDColor = " #fc5a03" ;
125
- if ( webMetrics . FID > 300 ) FIDColor = " #fc2000" ;
126
- if ( webMetrics . FCP <= 9000 ) FCPColor = " #0bce6b" ;
127
- if ( webMetrics . FCP > 900 && webMetrics . FCP <= 1100 ) FCPColor = " #fc5a03" ;
128
- if ( webMetrics . FCP > 1100 ) FCPColor = " #fc2000" ;
129
- if ( webMetrics . TTFB <= 600 ) TTFBColor = " #0bce6b" ;
130
- if ( webMetrics . TTFB > 600 ) TTFBColor = " #fc2000" ;
120
+ if ( webMetrics . LCP <= 2000 ) LCPColor = ' #0bce6b' ;
121
+ if ( webMetrics . LCP > 2000 && webMetrics . LCP < 4000 ) LCPColor = ' #E56543' ;
122
+ if ( webMetrics . LCP > 4000 ) LCPColor = ' #fc2000' ;
123
+ if ( webMetrics . FID <= 100 ) FIDColor = ' #0bce6b' ;
124
+ if ( webMetrics . FID > 100 && webMetrics . FID <= 300 ) FIDColor = ' #fc5a03' ;
125
+ if ( webMetrics . FID > 300 ) FIDColor = ' #fc2000' ;
126
+ if ( webMetrics . FCP <= 9000 ) FCPColor = ' #0bce6b' ;
127
+ if ( webMetrics . FCP > 900 && webMetrics . FCP <= 1100 ) FCPColor = ' #fc5a03' ;
128
+ if ( webMetrics . FCP > 1100 ) FCPColor = ' #fc2000' ;
129
+ if ( webMetrics . TTFB <= 600 ) TTFBColor = ' #0bce6b' ;
130
+ if ( webMetrics . TTFB > 600 ) TTFBColor = ' #fc2000' ;
131
131
132
132
return (
133
- < div className = "web-metrics-container" >
134
- < WebMetrics color = { LCPColor } series = { ( webMetrics . LCP / 2500 ) * 100 }
135
- formatted = { ( val ) => { return ( Number . isNaN ( val ) ) ? '- ms' : ( ( ( val / 100 ) * 2500 ) . toFixed ( 2 ) + ' ms' ) } }
136
- label = "LCP" />
137
- < WebMetrics color = { FIDColor } series = { ( webMetrics . FID ) * 25 }
138
- formatted = { ( val ) => { return ( Number . isNaN ( val ) ) ? '- ms' : ( ( val / 25 ) . toFixed ( 2 ) + ' ms' ) } }
139
- label = "FID" />
140
- < WebMetrics color = { FCPColor } series = { ( webMetrics . FCP / 1000 ) * 100 } formatted = { ( val ) => ( ( val / 100 ) * 1000 ) . toFixed ( 2 ) + ' ms' } label = "FCP" />
141
- < WebMetrics color = { TTFBColor } series = { ( webMetrics . TTFB / 10 ) * 100 } formatted = { ( val ) => ( ( val / 100 ) * 10 ) . toFixed ( 2 ) + ' ms' } label = "TTFB" />
133
+ < div className = 'web-metrics-container' >
134
+ < WebMetrics
135
+ color = { LCPColor }
136
+ series = { ( webMetrics . LCP / 2500 ) * 100 }
137
+ formatted = { ( val ) => {
138
+ return Number . isNaN ( val )
139
+ ? '- ms'
140
+ : ( ( val / 100 ) * 2500 ) . toFixed ( 2 ) + ' ms' ;
141
+ } }
142
+ label = 'LCP'
143
+ name = 'Largest Contentful Paint'
144
+ description = 'Time website loads largest content on screen'
145
+ />
146
+ < WebMetrics
147
+ color = { FIDColor }
148
+ series = { webMetrics . FID * 25 }
149
+ formatted = { ( val ) => {
150
+ return Number . isNaN ( val ) ? '- ms' : ( val / 25 ) . toFixed ( 2 ) + ' ms' ;
151
+ } }
152
+ label = 'FID'
153
+ name = 'First Input Delay'
154
+ description = 'Time from when a user first interacts with your site'
155
+ />
156
+ < WebMetrics
157
+ color = { FCPColor }
158
+ series = { ( webMetrics . FCP / 1000 ) * 100 }
159
+ formatted = { ( val ) => ( ( val / 100 ) * 1000 ) . toFixed ( 2 ) + ' ms' }
160
+ label = 'FCP'
161
+ name = 'First Contentful Paint'
162
+ description = 'How long it takes browser to render first piece of DOM content'
163
+ />
164
+ < WebMetrics
165
+ color = { TTFBColor }
166
+ series = { ( webMetrics . TTFB / 10 ) * 100 }
167
+ formatted = { ( val ) => ( ( val / 100 ) * 10 ) . toFixed ( 2 ) + ' ms' }
168
+ label = 'TTFB'
169
+ name = 'Time to First Byte'
170
+ description = 'Time at which your server sends a response'
171
+ />
142
172
</ div >
143
173
) ;
144
174
} ;
@@ -160,61 +190,61 @@ const StateRoute = (props: StateRouteProps) => {
160
190
</ ParentSize >
161
191
) ;
162
192
}
163
- return < div className = " noState" > { NO_STATE_MSG } </ div > ;
193
+ return < div className = ' noState' > { NO_STATE_MSG } </ div > ;
164
194
} ;
165
195
166
196
return (
167
197
< Router >
168
- < div className = " navbar" >
198
+ < div className = ' navbar' >
169
199
< NavLink
170
- className = " router-link"
171
- activeClassName = " is-active"
200
+ className = ' router-link'
201
+ activeClassName = ' is-active'
172
202
exact
173
- to = "/"
203
+ to = '/'
174
204
>
175
205
Map
176
206
</ NavLink >
177
207
< NavLink
178
- className = " router-link"
179
- activeClassName = " is-active"
180
- to = " /performance"
208
+ className = ' router-link'
209
+ activeClassName = ' is-active'
210
+ to = ' /performance'
181
211
>
182
212
Performance
183
213
</ NavLink >
184
214
< NavLink
185
- className = " router-link"
186
- activeClassName = " is-active"
187
- to = " /history"
215
+ className = ' router-link'
216
+ activeClassName = ' is-active'
217
+ to = ' /history'
188
218
>
189
219
History
190
220
</ NavLink >
191
221
< NavLink
192
- className = " router-link"
193
- activeClassName = " is-active"
194
- to = " /webMetrics"
222
+ className = ' router-link'
223
+ activeClassName = ' is-active'
224
+ to = ' /webMetrics'
195
225
>
196
226
Web Metrics
197
227
</ NavLink >
198
- < NavLink className = " router-link" activeClassName = " is-active" to = " /tree" >
228
+ < NavLink className = ' router-link' activeClassName = ' is-active' to = ' /tree' >
199
229
Tree
200
230
</ NavLink >
201
231
{ isRecoil && (
202
232
< NavLink
203
- className = " router-link"
204
- activeClassName = " is-active"
205
- to = " /relationship"
233
+ className = ' router-link'
234
+ activeClassName = ' is-active'
235
+ to = ' /relationship'
206
236
>
207
237
AtomsRecoil
208
238
</ NavLink >
209
239
) }
210
240
</ div >
211
241
< Switch >
212
- < Route path = " /performance" render = { renderPerfView } />
213
- < Route path = " /history" render = { renderHistory } />
214
- < Route path = " /relationship" render = { renderAtomsRelationship } />
215
- < Route path = " /webMetrics" render = { renderWebMetrics } />
216
- < Route path = " /tree" render = { renderTree } />
217
- < Route path = "/" render = { renderComponentMap } />
242
+ < Route path = ' /performance' render = { renderPerfView } />
243
+ < Route path = ' /history' render = { renderHistory } />
244
+ < Route path = ' /relationship' render = { renderAtomsRelationship } />
245
+ < Route path = ' /webMetrics' render = { renderWebMetrics } />
246
+ < Route path = ' /tree' render = { renderTree } />
247
+ < Route path = '/' render = { renderComponentMap } />
218
248
</ Switch >
219
249
</ Router >
220
250
) ;
0 commit comments