@@ -20,6 +20,7 @@ import { useStoreContext } from '../store';
20
20
import PerformanceVisx from './PerformanceVisx' ;
21
21
import Legend from './AtomsRelationshipLegend' ;
22
22
import AtomsRelationship from './AtomsRelationship' ;
23
+ import WebMetrics from './WebMetrics' ;
23
24
24
25
const History = require ( './History' ) . default ;
25
26
const ErrorHandler = require ( './ErrorHandler' ) . default ;
@@ -41,21 +42,23 @@ export interface StateRouteProps {
41
42
hierarchy : any ;
42
43
snapshots : [ ] ;
43
44
viewIndex : number ;
45
+ webMetrics : object ;
44
46
}
45
47
46
48
const StateRoute = ( props : StateRouteProps ) => {
47
- const { snapshot, hierarchy, snapshots, viewIndex } = props ;
49
+ const { snapshot, hierarchy, snapshots, viewIndex, webMetrics } = props ;
48
50
const [ { tabs, currentTab } , dispatch ] = useStoreContext ( ) ;
49
51
const { hierarchy, sliderIndex, viewIndex } = tabs [ currentTab ] ;
50
52
const isRecoil = snapshot . atomsComponents ? true : false ;
53
+
51
54
const [ noRenderData , setNoRenderData ] = useState ( false ) ;
52
55
// component map zoom state
53
56
const [ { x, y, k } , setZoomState ] : any = useState ( {
54
57
x : 150 ,
55
58
y : 250 ,
56
59
k : 1 ,
57
60
} ) ;
58
-
61
+ console . log ( 'webMetrics in StateRoute Props >>>>' , webMetrics ) ;
59
62
// Map
60
63
const renderComponentMap = ( ) => {
61
64
if ( hierarchy ) {
@@ -67,7 +70,7 @@ const StateRoute = (props: StateRouteProps) => {
67
70
</ ParentSize >
68
71
) ;
69
72
}
70
- return < div className = " noState" > { NO_STATE_MSG } </ div > ;
73
+ return < div className = ' noState' > { NO_STATE_MSG } </ div > ;
71
74
} ;
72
75
73
76
// the hierarchy gets set upon the first click on the page
@@ -86,7 +89,7 @@ const StateRoute = (props: StateRouteProps) => {
86
89
/>
87
90
) ;
88
91
}
89
- return < div className = " noState" > { NO_STATE_MSG } </ div > ;
92
+ return < div className = ' noState' > { NO_STATE_MSG } </ div > ;
90
93
} ;
91
94
92
95
const renderAtomsRelationship = ( ) => (
@@ -110,7 +113,37 @@ const StateRoute = (props: StateRouteProps) => {
110
113
if ( hierarchy ) {
111
114
return < Tree snapshot = { snapshot } /> ;
112
115
}
113
- return < div className = "noState" > { NO_STATE_MSG } </ div > ;
116
+ return < div className = 'noState' > { NO_STATE_MSG } </ div > ;
117
+ } ;
118
+ const renderWebMetrics = ( ) => {
119
+ let LCPColor , FIDColor , CLSColor , FCPColor , TTFBColor ;
120
+
121
+ if ( webMetrics . LCP <= 2000 ) LCPColor = "#0bce6b" ;
122
+ if ( webMetrics . LCP > 2000 && webMetrics . LCP < 4000 ) LCPColor = "#E56543" ;
123
+ if ( webMetrics . LCP > 4000 ) LCPColor = "#fc2000" ;
124
+ if ( webMetrics . FID <= 100 ) FIDColor = "#0bce6b" ;
125
+ if ( webMetrics . FID > 100 && webMetrics . FID <= 300 ) FIDColor = "#fc5a03" ;
126
+ if ( webMetrics . FID > 300 ) FIDColor = "#fc2000" ;
127
+ if ( webMetrics . CLS <= 0.1 ) FIDColor = "#0bce6b" ;
128
+ if ( webMetrics . CLS > 0.1 && webMetrics . CLS <= 0.25 ) CLSColor = "#fc5a03" ;
129
+ if ( webMetrics . CLS > 0.25 ) CLSColor = "#fc2000" ;
130
+ if ( webMetrics . FCP <= 9000 ) FCPColor = "#0bce6b" ;
131
+ if ( webMetrics . FCP > 900 && webMetrics . FCP <= 1100 ) FCPColor = "#fc5a03" ;
132
+ if ( webMetrics . FCP > 1100 ) FCPColor = "#fc2000" ;
133
+ if ( webMetrics . TTFB <= 600 ) TTFBColor = "#0bce6b" ;
134
+ if ( webMetrics . TTFB > 600 ) TTFBColor = "#fc2000" ;
135
+
136
+
137
+
138
+ return (
139
+ < div className = "web-metrics-container" >
140
+ < WebMetrics color = { LCPColor } series = { ( webMetrics . LCP / 2500 ) * 100 } formatted = { ( val ) => ( ( val / 100 ) * 2500 ) . toFixed ( 2 ) + ' ms' } label = "LCP" />
141
+ < WebMetrics color = { FIDColor } series = { ( webMetrics . FID ) * 25 } formatted = { ( val ) => ( ( val / 25 ) ) . toFixed ( 2 ) + ' ms' } label = "FID" />
142
+ { /* <WebMetrics color={CLSColor} series={(webMetrics.CLS * 50) * 100} formatted={(val) => ((val / 100) / 50).toFixed(2)} label="CLS"/> */ }
143
+ < WebMetrics color = { FCPColor } series = { ( webMetrics . FCP / 1000 ) * 100 } formatted = { ( val ) => ( ( val / 100 ) * 1000 ) . toFixed ( 2 ) + ' ms' } label = "FCP" />
144
+ < WebMetrics color = { TTFBColor } series = { ( webMetrics . TTFB / 10 ) * 100 } formatted = { ( val ) => ( ( val / 100 ) * 10 ) . toFixed ( 2 ) + ' ms' } label = "TTFB" />
145
+ </ div >
146
+ ) ;
114
147
} ;
115
148
116
149
const renderPerfView = ( ) => {
@@ -130,54 +163,61 @@ const StateRoute = (props: StateRouteProps) => {
130
163
</ ParentSize >
131
164
) ;
132
165
}
133
- return < div className = " noState" > { NO_STATE_MSG } </ div > ;
166
+ return < div className = ' noState' > { NO_STATE_MSG } </ div > ;
134
167
} ;
135
168
136
169
return (
137
170
< Router >
138
- < div className = "navbar" >
139
- < NavLink className = "router-link"
140
- activeClassName = "is-active"
141
- exact to = "/" >
171
+ < div className = 'navbar' >
172
+ < NavLink
173
+ className = 'router-link'
174
+ activeClassName = 'is-active'
175
+ exact
176
+ to = '/'
177
+ >
142
178
Map
143
179
</ NavLink >
144
180
< NavLink
145
- className = " router-link"
146
- activeClassName = " is-active"
147
- to = " /performance"
181
+ className = ' router-link'
182
+ activeClassName = ' is-active'
183
+ to = ' /performance'
148
184
>
149
185
Performance
150
186
</ NavLink >
151
187
< NavLink
152
- className = " router-link"
153
- activeClassName = " is-active"
154
- to = " /history"
188
+ className = ' router-link'
189
+ activeClassName = ' is-active'
190
+ to = ' /history'
155
191
>
156
192
History
157
193
</ NavLink >
158
194
< NavLink
159
- className = " router-link"
160
- activeClassName = " is-active"
161
- to = "/tree"
195
+ className = ' router-link'
196
+ activeClassName = ' is-active'
197
+ to = '/webMetrics'
162
198
>
199
+ Web Metrics
200
+ </ NavLink >
201
+ < NavLink className = 'router-link' activeClassName = 'is-active' to = '/tree' >
163
202
Tree
164
203
</ NavLink >
165
204
{ isRecoil && (
166
205
< NavLink
167
- className = " router-link"
168
- activeClassName = " is-active"
169
- to = " /relationship"
206
+ className = ' router-link'
207
+ activeClassName = ' is-active'
208
+ to = ' /relationship'
170
209
>
171
210
AtomsRecoil
172
211
</ NavLink >
173
212
) }
174
213
</ div >
175
214
< Switch >
176
- < Route path = "/performance" render = { renderPerfView } />
177
- < Route path = "/history" render = { renderHistory } />
178
- < Route path = "/relationship" render = { renderAtomsRelationship } />
179
- < Route path = "/tree" render = { renderTree } />
180
- < Route path = "/" render = { renderComponentMap } />
215
+ < Route path = '/performance' render = { renderPerfView } />
216
+ < Route path = '/history' render = { renderHistory } />
217
+ < Route path = '/relationship' render = { renderAtomsRelationship } />
218
+ < Route path = '/webMetrics' render = { renderWebMetrics } />
219
+ < Route path = '/tree' render = { renderTree } />
220
+ < Route path = '/' render = { renderComponentMap } />
181
221
</ Switch >
182
222
</ Router >
183
223
) ;
0 commit comments