55/* eslint-disable @typescript-eslint/no-var-requires */
66/* eslint-disable max-len */
77/* eslint-disable object-curly-newline */
8- import React , { useState } from " react" ;
8+ import React , { useState } from ' react' ;
99import {
1010 MemoryRouter as Router ,
1111 Route ,
1212 NavLink ,
1313 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' ;
2424
25- const History = require ( " ./History" ) . default ;
26- const ErrorHandler = require ( " ./ErrorHandler" ) . default ;
25+ const History = require ( ' ./History' ) . default ;
26+ const ErrorHandler = require ( ' ./ErrorHandler' ) . default ;
2727
2828const 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' ;
3030// eslint-disable-next-line react/prop-types
3131
3232export interface StateRouteProps {
@@ -69,7 +69,7 @@ const StateRoute = (props: StateRouteProps) => {
6969 </ ParentSize >
7070 ) ;
7171 }
72- return < div className = " noState" > { NO_STATE_MSG } </ div > ;
72+ return < div className = ' noState' > { NO_STATE_MSG } </ div > ;
7373 } ;
7474
7575 // the hierarchy gets set upon the first click on the page
@@ -88,7 +88,7 @@ const StateRoute = (props: StateRouteProps) => {
8888 />
8989 ) ;
9090 }
91- return < div className = " noState" > { NO_STATE_MSG } </ div > ;
91+ return < div className = ' noState' > { NO_STATE_MSG } </ div > ;
9292 } ;
9393
9494 const renderAtomsRelationship = ( ) => (
@@ -112,33 +112,63 @@ const StateRoute = (props: StateRouteProps) => {
112112 if ( hierarchy ) {
113113 return < Tree snapshot = { snapshot } /> ;
114114 }
115- return < div className = " noState" > { NO_STATE_MSG } </ div > ;
115+ return < div className = ' noState' > { NO_STATE_MSG } </ div > ;
116116 } ;
117117 const renderWebMetrics = ( ) => {
118118 let LCPColor , FIDColor , FCPColor , TTFBColor ;
119119
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 <= 900 ) 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' ;
131131
132132 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 = 'Measures loading performance. The benchmark is less than 2500 ms.'
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 = 'Measures interactivity. The benchmark is less than 100 ms.'
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 = 'Measures the time it takes the browser to render the first piece of DOM content. No benchmark.'
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 = 'Measures the time it takes for a browser to receive the first byte of page content. The benchmark is 600 ms.'
171+ />
142172 </ div >
143173 ) ;
144174 } ;
@@ -160,61 +190,61 @@ const StateRoute = (props: StateRouteProps) => {
160190 </ ParentSize >
161191 ) ;
162192 }
163- return < div className = " noState" > { NO_STATE_MSG } </ div > ;
193+ return < div className = ' noState' > { NO_STATE_MSG } </ div > ;
164194 } ;
165195
166196 return (
167197 < Router >
168- < div className = " navbar" >
198+ < div className = ' navbar' >
169199 < NavLink
170- className = " router-link"
171- activeClassName = " is-active"
200+ className = ' router-link'
201+ activeClassName = ' is-active'
172202 exact
173- to = "/"
203+ to = '/'
174204 >
175205 Map
176206 </ NavLink >
177207 < NavLink
178- className = " router-link"
179- activeClassName = " is-active"
180- to = " /performance"
208+ className = ' router-link'
209+ activeClassName = ' is-active'
210+ to = ' /performance'
181211 >
182212 Performance
183213 </ NavLink >
184214 < NavLink
185- className = " router-link"
186- activeClassName = " is-active"
187- to = " /history"
215+ className = ' router-link'
216+ activeClassName = ' is-active'
217+ to = ' /history'
188218 >
189219 History
190220 </ NavLink >
191221 < NavLink
192- className = " router-link"
193- activeClassName = " is-active"
194- to = " /webMetrics"
222+ className = ' router-link'
223+ activeClassName = ' is-active'
224+ to = ' /webMetrics'
195225 >
196226 Web Metrics
197227 </ NavLink >
198- < NavLink className = " router-link" activeClassName = " is-active" to = " /tree" >
228+ < NavLink className = ' router-link' activeClassName = ' is-active' to = ' /tree' >
199229 Tree
200230 </ NavLink >
201231 { isRecoil && (
202232 < NavLink
203- className = " router-link"
204- activeClassName = " is-active"
205- to = " /relationship"
233+ className = ' router-link'
234+ activeClassName = ' is-active'
235+ to = ' /relationship'
206236 >
207237 AtomsRecoil
208238 </ NavLink >
209239 ) }
210240 </ div >
211241 < 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 } />
218248 </ Switch >
219249 </ Router >
220250 ) ;
0 commit comments