Skip to content

Commit 4b546cc

Browse files
committed
Merge branch 'ali-feature' of https://github.com/C-STYR/reactime into cole_feature
2 parents ab3d8b9 + dc9299c commit 4b546cc

File tree

8 files changed

+200
-8
lines changed

8 files changed

+200
-8
lines changed

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
"jest-diff": "^26.1.0",
100100
"jest-puppeteer": "^4.4.0",
101101
"jest-runner-eslint": "^0.7.7",
102+
"jscharting-react": "^1.2.1",
102103
"puppeteer": "^5.1.0",
103104
"sass": "^1.26.10",
104105
"sass-loader": "^7.3.1",
@@ -138,25 +139,29 @@
138139
"@visx/zoom": "^1.0.0",
139140
"acorn": "^7.3.1",
140141
"acorn-jsx": "^5.2.0",
142+
"apexcharts": "^3.23.1",
141143
"cookie": "^0.4.1",
142144
"d3": "^5.16.0",
143145
"d3-scale-chromatic": "^2.0.0",
144146
"d3-shape": "^2.0.0",
145147
"d3-zoom": "^1.8.3",
146148
"immer": "^3.3.0",
147149
"jest-runner": "^26.1.0",
150+
"jscharting": "^3.0.2",
148151
"jsondiffpatch": "^0.3.11",
149152
"mixpanel": "^0.11.0",
150153
"mixpanel-browser": "^2.39.0",
151154
"prop-types": "^15.7.2",
152155
"rc-slider": "^8.7.1",
153156
"rc-tooltip": "^3.7.3",
154157
"react": "^16.13.1",
158+
"react-apexcharts": "^1.3.7",
155159
"react-dom": "^16.13.1",
156160
"react-html-parser": "^2.0.2",
157161
"react-json-tree": "^0.11.2",
158162
"react-router-dom": "^5.2.0",
159163
"react-select": "^3.1.0",
160-
"recoil": "0.0.10"
164+
"recoil": "0.0.10",
165+
"web-vitals": "^1.1.0"
161166
}
162167
}

src/app/components/StateRoute.tsx

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import { useStoreContext } from '../store';
2020
import PerformanceVisx from './PerformanceVisx';
2121
import Legend from './AtomsRelationshipLegend';
2222
import AtomsRelationship from './AtomsRelationship';
23+
import WebMetrics from './WebMetrics';
24+
2325

2426
const History = require('./History').default;
2527
const ErrorHandler = require('./ErrorHandler').default;
@@ -37,14 +39,16 @@ export interface StateRouteProps {
3739
children?: any[];
3840
atomsComponents?: any;
3941
atomSelectors?: any;
42+
4043
};
4144
hierarchy: any;
4245
snapshots: [];
4346
viewIndex: number;
47+
webMetrics: object;
4448
}
4549

4650
const StateRoute = (props: StateRouteProps) => {
47-
const { snapshot, hierarchy, snapshots, viewIndex } = props;
51+
const { snapshot, hierarchy, snapshots, viewIndex, webMetrics } = props;
4852
const [{ tabs, currentTab }, dispatch] = useStoreContext();
4953
const { hierarchy, sliderIndex, viewIndex } = tabs[currentTab];
5054
const isRecoil = snapshot.atomsComponents ? true : false;
@@ -111,6 +115,16 @@ const StateRoute = (props: StateRouteProps) => {
111115
return <Tree snapshot={snapshot} />;
112116
}
113117
return <div className="noState">{NO_STATE_MSG}</div>;
118+
119+
};
120+
const renderWebMetrics = () => {
121+
return (
122+
<div>
123+
<WebMetrics webMetrics={webMetrics}/>
124+
<WebMetrics webMetrics={webMetrics}/>
125+
<WebMetrics webMetrics={webMetrics}/>
126+
</div>
127+
)
114128
};
115129

116130
const renderPerfView = () => {
@@ -155,6 +169,13 @@ const StateRoute = (props: StateRouteProps) => {
155169
>
156170
History
157171
</NavLink>
172+
<NavLink
173+
className="router-link"
174+
activeClassName="is-active"
175+
to="/webMetrics"
176+
>
177+
Web Metrics
178+
</NavLink>
158179
<NavLink
159180
className="router-link"
160181
activeClassName="is-active"
@@ -176,6 +197,7 @@ const StateRoute = (props: StateRouteProps) => {
176197
<Route path="/performance" render={renderPerfView} />
177198
<Route path="/history" render={renderHistory} />
178199
<Route path="/relationship" render={renderAtomsRelationship} />
200+
<Route path="/webMetrics" render={renderWebMetrics} />
179201
<Route path="/tree" render={renderTree} />
180202
<Route path="/" render={renderComponentMap} />
181203
</Switch>

src/app/components/WebMetrics.tsx

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import React, { useState } from 'react';
2+
import Charts from 'react-apexcharts'
3+
4+
const radialGraph = ({webMetrics}) => {
5+
const state = {
6+
7+
series: [(webMetrics.FCP / 1000) * 100],
8+
options: {
9+
chart: {
10+
height: 350,
11+
type: 'radialBar',
12+
toolbar: {
13+
show: true
14+
}
15+
},
16+
plotOptions: {
17+
radialBar: {
18+
startAngle: -135,
19+
endAngle: 225,
20+
hollow: {
21+
margin: 0,
22+
size: '90%',
23+
background: '#242529',
24+
image: undefined,
25+
imageOffsetX: 0,
26+
imageOffsetY: 0,
27+
position: 'front',
28+
dropShadow: {
29+
enabled: true,
30+
top: 3,
31+
left: 0,
32+
blur: 4,
33+
opacity: 0.24
34+
}
35+
},
36+
track: {
37+
background: '#fff',
38+
strokeWidth: '10%',
39+
margin: 0, // margin is in pixels
40+
dropShadow: {
41+
enabled: true,
42+
top: -3,
43+
left: 0,
44+
blur: 4,
45+
opacity: 0.35
46+
}
47+
},
48+
49+
dataLabels: {
50+
show: true,
51+
name: {
52+
offsetY: -10,
53+
show: true,
54+
color: '#fff',
55+
fontSize: '17px'
56+
},
57+
value: {
58+
formatter: function(val) {
59+
return parseInt(webMetrics.FCP);
60+
},
61+
color: '#fff',
62+
fontSize: '25px',
63+
show: true,
64+
}
65+
}
66+
}
67+
},
68+
fill: {
69+
type: 'gradient',
70+
gradient: {
71+
shade: 'dark',
72+
type: 'horizontal',
73+
shadeIntensity: 0.5,
74+
gradientToColors: ['#ABE5A1'],
75+
inverseColors: true,
76+
opacityFrom: 1,
77+
opacityTo: 1,
78+
stops: [0, 100]
79+
}
80+
},
81+
stroke: {
82+
lineCap: 'round'
83+
},
84+
labels: ['FCP'],
85+
},
86+
87+
88+
};
89+
90+
91+
return (
92+
93+
94+
<div id="card">
95+
<div id="chart">
96+
<Charts options={state.options} series={state.series} type="radialBar" height={350} />
97+
</div>
98+
</div>
99+
100+
)
101+
}
102+
103+
export default radialGraph;

src/app/containers/ActionContainer.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,13 @@ function ActionContainer(props) {
115115
);
116116

117117
if (!timeTravel) {
118-
console.log("should be false:", timeTravel)
119118
return (
120119
//returns an empty div when timeTravel is false
121120

122121
<div></div>
123122
)
124123
}
125124
else {
126-
console.log("Should be true:", timeTravel);
127125
// this is not logging; the prop is not being udpdated or the component is not being re-rendered.
128126
return (
129127
<div className="action-container">

src/app/containers/MainContainer.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,11 @@ function MainContainer(): any {
151151
</div>
152152
);
153153
}
154-
const { viewIndex, sliderIndex, snapshots, hierarchy } = tabs[currentTab];
154+
const { viewIndex, sliderIndex, snapshots, hierarchy, webMetrics } = tabs[currentTab];
155155
// if viewIndex is -1, then use the sliderIndex instead
156+
console.log('webMetrics in MainContainer >>>', webMetrics);
157+
158+
156159
const snapshotView =
157160
viewIndex === -1 ? snapshots[sliderIndex] : snapshots[viewIndex];
158161
// cleaning hierarchy and snapshotView from stateless data
@@ -222,6 +225,7 @@ function MainContainer(): any {
222225
{snapshots.length ? (
223226
<StateContainer
224227
toggleActionContainer={toggleActionContainer}
228+
webMetrics={webMetrics}
225229
viewIndex={viewIndex}
226230
snapshot={snapshotDisplay}
227231
hierarchy={hierarchyDisplay}

src/app/containers/StateContainer.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ interface StateContainerProps {
2424
}
2525
>;
2626
toggleActionContainer?: any;
27+
webMetrics: object;
2728
AtomsRelationship?: any[];
2829
hierarchy: Record<string, unknown>;
2930
snapshots: [];
@@ -33,7 +34,7 @@ interface StateContainerProps {
3334

3435
// eslint-disable-next-line react/prop-types
3536
const StateContainer = (props: StateContainerProps): JSX.Element => {
36-
const { snapshot, hierarchy, snapshots, viewIndex, toggleActionContainer } = props;
37+
const { snapshot, hierarchy, snapshots, viewIndex, toggleActionContainer, webMetrics } = props;
3738
const [Text, setText] = useState('State');
3839

3940
return (
@@ -74,6 +75,7 @@ const StateContainer = (props: StateContainerProps): JSX.Element => {
7475
setText('State');
7576
return (
7677
<StateRoute
78+
webMetrics={webMetrics}
7779
viewIndex={viewIndex}
7880
snapshot={snapshot}
7981
hierarchy={hierarchy}

src/extension/background.js

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ const firstSnapshotReceived = {};
77
// there will be the same number of objects in here as there are reactime tabs open for each user application being worked on
88
const tabsObj = {};
99

10+
let metrics = {}; //for Performance Metrics 8.0
11+
1012
function createTabObj(title) {
1113
// update tabsObj
1214
return {
@@ -32,6 +34,8 @@ function createTabObj(title) {
3234
paused: false,
3335
empty: false,
3436
},
37+
38+
webMetrics: {},
3539
};
3640
}
3741

@@ -175,16 +179,25 @@ chrome.runtime.onConnect.addListener((port) => {
175179
});
176180

177181
// background.js listening for a message from contentScript.js
178-
chrome.runtime.onMessage.addListener((request, sender) => {
182+
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
179183
// IGNORE THE AUTOMATIC MESSAGE SENT BY CHROME WHEN CONTENT SCRIPT IS FIRST LOADED
180184
if (request.type === 'SIGN_CONNECT') {
181185
return true;
182186
}
187+
188+
189+
console.log('Request in Listener >>>', request)
190+
console.log('Sender in Listener >>>', sender)
183191
const tabTitle = sender.tab.title;
184192
const tabId = sender.tab.id;
185-
const { action, index, name } = request;
193+
const { action, index, name, value } = request;
186194
let isReactTimeTravel = false;
187195

196+
if (name) {
197+
metrics[name] = value;
198+
};
199+
200+
console.log('metrics outside', metrics);
188201

189202
// Filter out tabs that don't have reactime, tabs that dont use react?
190203
if (
@@ -203,6 +216,8 @@ chrome.runtime.onMessage.addListener((request, sender) => {
203216
tabsObj[tabId] = createTabObj(tabTitle);
204217
}
205218

219+
//Performance Metrics 8.0
220+
206221
const { persist, empty } = tabsObj[tabId].mode;
207222

208223
switch (action) {
@@ -236,7 +251,10 @@ chrome.runtime.onMessage.addListener((request, sender) => {
236251
tabsObj[tabId].snapshots = tabsObj[tabId].initialSnapshot;
237252
// resets hierarchy to page initial state recorded when emptied
238253
tabsObj[tabId].hierarchy = tabsObj[tabId].initialHierarchy;
254+
255+
239256
} else {
257+
240258
// triggered with new tab opened
241259
// resets snapshots to page initial state
242260
tabsObj[tabId].snapshots.splice(1);
@@ -273,11 +291,24 @@ chrome.runtime.onMessage.addListener((request, sender) => {
273291
case 'recordSnap': {
274292
const sourceTab = tabId;
275293
// first snapshot received from tab
294+
console.log('metrics in recordSnap case', metrics);
295+
tabsObj[tabId].webMetrics = metrics;
296+
297+
// metrics check
298+
console.log('tabsObj >>>', tabsObj);
299+
300+
276301
if (!firstSnapshotReceived[tabId]) {
277302
firstSnapshotReceived[tabId] = true;
278303
reloaded[tabId] = false;
304+
305+
console.log('metrics in recordSnap case', metrics);
306+
tabsObj[tabId].webMetrics = metrics;
279307

280308
tabsObj[tabId].snapshots.push(request.payload);
309+
310+
// metrics check
311+
console.log('tabsObj >>>', tabsObj);
281312

282313
sendToHierarchy(
283314
tabsObj[tabId],

src/extension/contentScript.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { getTTFB, getLCP, getFID, getFCP, getCLS } from "web-vitals";
2+
13

24
let firstMessage = true;
35

@@ -35,4 +37,29 @@ chrome.runtime.onMessage.addListener(request => {
3537
return true; // attempt to fix port closing console error
3638
});
3739

40+
//Performance Metrics 8.0
41+
42+
const metrics = {};
43+
const gatherMetrics = ({ name, value }) => {
44+
metrics[name] = value;
45+
46+
47+
chrome.runtime.sendMessage({
48+
type: "performance:metric",
49+
name,
50+
value
51+
});
52+
53+
54+
55+
}
56+
57+
getTTFB(gatherMetrics);
58+
getLCP(gatherMetrics);
59+
getFID(gatherMetrics);
60+
getFCP(gatherMetrics);
61+
getCLS(gatherMetrics);
62+
63+
64+
3865
chrome.runtime.sendMessage({ action: 'injectScript' });

0 commit comments

Comments
 (0)