Skip to content

Commit 55a6e9e

Browse files
committed
Fixed breakage on save series & component details. Should pass tests now
1 parent da04dc6 commit 55a6e9e

File tree

2 files changed

+109
-27
lines changed

2 files changed

+109
-27
lines changed

src/app/components/PerformanceVisx.tsx

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
11
/* eslint-disable guard-for-in */
2-
//* eslint-disable no-restricted-syntax */
2+
/* eslint-disable no-restricted-syntax */
33
// @ts-nocheck
44
import React, { useState } from 'react';
5+
import FormControlLabel from '@material-ui/core/FormControlLabel';
6+
import { ParentSize } from '@visx/responsive';
57
import {
68
MemoryRouter as Router,
79
Route,
810
NavLink,
911
Switch,
1012
} from 'react-router-dom';
13+
import { Component } from 'react';
14+
import { render } from 'react-dom';
1115
import RenderingFrequency from './RenderingFrequency';
1216
// import Switch from '@material-ui/core/Switch';
1317
import BarGraph from './BarGraph';
1418
import BarGraphComparison from './BarGraphComparison';
1519
import { useStoreContext } from '../store';
1620
// import snapshots from './snapshots';
21+
import snapshots from './snapshots';
22+
1723
const exclude = ['childExpirationTime', 'staticContext', '_debugSource', 'actualDuration', 'actualStartTime', 'treeBaseDuration', '_debugID', '_debugIsCurrentlyTiming', 'selfBaseDuration', 'expirationTime', 'effectTag', 'alternate', '_owner', '_store', 'get key', 'ref', '_self', '_source', 'firstBaseUpdate', 'updateQueue', 'lastBaseUpdate', 'shared', 'responders', 'pending', 'lanes', 'childLanes', 'effects', 'memoizedState', 'pendingProps', 'lastEffect', 'firstEffect', 'tag', 'baseState', 'baseQueue', 'dependencies', 'Consumer', 'context', '_currentRenderer', '_currentRenderer2', 'mode', 'flags', 'nextEffect', 'sibling', 'create', 'deps', 'next', 'destroy', 'parentSub', 'child', 'key', 'return', 'children', '$$typeof', '_threadCount', '_calculateChangedBits', '_currentValue', '_currentValue2', 'Provider', '_context', 'stateNode', 'elementType', 'type'];
24+
1825
/* NOTES
1926
Issue - Not fully compatible with recoil apps. Reference the recoil-todo-test.
2027
Barstacks display inconsistently...however, almost always displays upon initial test app load or
@@ -23,14 +30,16 @@ However, cycling between updating state and then emptying sometimes fixes the st
2330
to note - all snapshots do render (check HTML doc) within the chrome extension but they do
2431
not display because height is not consistently passed to each bar. This side effect is only
2532
seen in recoil apps...
26-
*/
33+
*/
34+
2735
// typescript for PROPS from StateRoute.tsx
2836
interface BarStackProps {
2937
width: number;
3038
height: number;
3139
snapshots: [];
3240
hierarchy: any;
3341
}
42+
3443
const makePropsPretty = data => {
3544
const propsFormat = [];
3645
const nestedObj = [];
@@ -52,6 +61,7 @@ const makePropsPretty = data => {
5261
}
5362
return propsFormat;
5463
};
64+
5565
const collectNodes = (snaps, componentName) => {
5666
const componentsResult = [];
5767
const renderResult = [];
@@ -100,6 +110,7 @@ const collectNodes = (snaps, componentName) => {
100110
}
101111
}
102112
}
113+
103114
const finalResults = componentsResult.map((e, index) => {
104115
const name = Object.keys(e)[0];
105116
e[name].rendertime = renderResult[index];
@@ -112,12 +123,15 @@ const collectNodes = (snaps, componentName) => {
112123
}
113124
return finalResults;
114125
};
126+
115127
/* DATA HANDLING HELPER FUNCTIONS */
116128
const traverse = (snapshot, data, snapshots, currTotalRender = 0) => {
117129
if (!snapshot.children[0]) return;
130+
118131
// loop through snapshots
119132
snapshot.children.forEach((child, idx) => {
120133
const componentName = child.name + -[idx + 1];
134+
121135
// Get component Rendering Time
122136
const renderTime = Number(
123137
Number.parseFloat(child.componentData.actualDuration).toPrecision(5),
@@ -126,6 +140,7 @@ const traverse = (snapshot, data, snapshots, currTotalRender = 0) => {
126140
currTotalRender += renderTime;
127141
// components as keys and set the value to their rendering time
128142
data.barStack[data.barStack.length - 1][componentName] = renderTime;
143+
129144
// Get component stateType
130145
if (!data.componentData[componentName]) {
131146
data.componentData[componentName] = {
@@ -142,7 +157,9 @@ const traverse = (snapshot, data, snapshots, currTotalRender = 0) => {
142157
data.componentData[componentName].renderFrequency++;
143158
}
144159
// else {
160+
145161
// }
162+
146163
// add to total render time
147164
data.componentData[componentName].totalRenderTime += renderTime;
148165
// Get rtid for the hovering feature
@@ -154,17 +171,21 @@ const traverse = (snapshot, data, snapshots, currTotalRender = 0) => {
154171
data.maxTotalRender = Math.max(currTotalRender, data.maxTotalRender);
155172
return data;
156173
};
174+
157175
// Retrieve snapshot series data from Chrome's local storage.
158176
const allStorage = () => {
159177
const values = [];
160178
const keys = Object.keys(localStorage);
161179
let i = keys.length;
180+
181+
162182
while (i--) {
163183
const series = localStorage.getItem(keys[i]);
164184
values.push(JSON.parse(series));
165185
}
166186
return values;
167187
};
188+
168189
// Gets snapshot Ids for the regular bar graph view.
169190
const getSnapshotIds = (obj, snapshotIds = []): string[] => {
170191
snapshotIds.push(`${obj.name}.${obj.branch}`);
@@ -175,6 +196,7 @@ const getSnapshotIds = (obj, snapshotIds = []): string[] => {
175196
}
176197
return snapshotIds;
177198
};
199+
178200
// Returns array of snapshot objs each with components and corresponding render times.
179201
const getPerfMetrics = (snapshots, snapshotsIds): {} => {
180202
const perfData = {
@@ -188,6 +210,7 @@ const getPerfMetrics = (snapshots, snapshotsIds): {} => {
188210
});
189211
return perfData;
190212
};
213+
191214
/* EXPORT COMPONENT */
192215
const PerformanceVisx = (props: BarStackProps) => {
193216
// hook used to dispatch onhover action in rect
@@ -200,6 +223,7 @@ const PerformanceVisx = (props: BarStackProps) => {
200223
const [comparisonData, setComparisonData] = useState();
201224
const NO_STATE_MSG = 'No state change detected. Trigger an event to change state';
202225
const data = getPerfMetrics(snapshots, getSnapshotIds(hierarchy));
226+
203227
const renderComparisonBargraph = () => {
204228
if (hierarchy) {
205229
return (
@@ -212,17 +236,20 @@ const PerformanceVisx = (props: BarStackProps) => {
212236
);
213237
}
214238
};
239+
215240
const renderBargraph = () => {
216241
if (hierarchy) {
217242
return <BarGraph data={data} width={width} height={height} />;
218243
}
219244
};
245+
220246
const renderComponentDetailsView = () => {
221247
if (hierarchy) {
222248
return <RenderingFrequency data={data.componentData} />;
223249
}
224250
return <div className="noState">{NO_STATE_MSG}</div>;
225251
};
252+
226253
return (
227254
<Router>
228255
<div className="performance-nav-bar-container">
@@ -252,6 +279,7 @@ const PerformanceVisx = (props: BarStackProps) => {
252279
Component Details
253280
</NavLink>
254281
</div>
282+
255283
<Switch>
256284
<Route path="/comparison" render={renderComparisonBargraph} />
257285
<Route path="/componentdetails" render={renderComponentDetailsView} />
@@ -260,4 +288,5 @@ const PerformanceVisx = (props: BarStackProps) => {
260288
</Router>
261289
);
262290
};
263-
export default PerformanceVisx;
291+
292+
export default PerformanceVisx;
Lines changed: 77 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,112 @@
1-
import React from 'react';
1+
/* eslint-disable jsx-a11y/click-events-have-key-events */
2+
/* eslint-disable jsx-a11y/no-static-element-interactions */
3+
/* eslint-disable react/prop-types */
4+
import React, { useState } from 'react';
5+
import { render } from 'react-dom';
26
import { onHover, onHoverExit } from '../actions/actions';
37
import { useStoreContext } from '../store';
48

5-
const RenderingFrequency = (props) => {
9+
const RenderingFrequency = props => {
610
const perfData = props.data;
711
return (
812
<div>
9-
{Object.keys(perfData).map((componentName) => {
13+
{Object.keys(perfData).map(componentName => {
1014
const currentComponent = perfData[componentName];
1115
return (
1216
<ComponentCard
1317
componentName={componentName}
1418
stateType={currentComponent.stateType}
1519
averageRenderTime={(
16-
currentComponent.totalRenderTime /
17-
currentComponent.renderFrequency
20+
currentComponent.totalRenderTime
21+
/ currentComponent.renderFrequency
1822
).toFixed(3)}
1923
renderFrequency={currentComponent.renderFrequency}
2024
rtid={currentComponent.rtid}
25+
information={perfData[componentName].information}
2126
/>
2227
);
2328
})}
2429
</div>
2530
);
2631
};
27-
const ComponentCard = (props) => {
32+
33+
const ComponentCard = props => {
2834
const {
2935
componentName,
3036
stateType,
3137
averageRenderTime,
3238
renderFrequency,
3339
rtid,
40+
information,
3441
} = props;
3542
const [{ tabs, currentTab }, dispatch] = useStoreContext();
36-
const onMouseMove = () => {
37-
dispatch(onHover(rtid));
38-
};
39-
const onMouseLeave = () => {
40-
dispatch(onHoverExit(rtid));
41-
};
43+
const [expand, setExpand] = useState(false);
44+
45+
// render time for each component from each snapshot
46+
// differences in state change that happened prior;
47+
48+
const dataComponentArray = [];
49+
for (let i = 0; i < information.length; i++) {
50+
dataComponentArray.push(<DataComponent header={Object.keys(information[i])} paragraphs={Object.values(information[i])} />);
51+
}
52+
4253
return (
43-
<div
44-
onMouseLeave={onMouseLeave}
45-
onMouseMove={onMouseMove}
46-
className="StyledGridElement"
47-
>
48-
<div className="RenderLeft">
49-
<h3>{componentName} </h3>
50-
<h4>{stateType}</h4>
51-
<h4>average time: {averageRenderTime} ms</h4>
54+
<div className="borderStyling">
55+
<div
56+
className={expand ? 'ExpandStyledGridElement' : 'StyledGridElement'}
57+
>
58+
<div className="RenderLeft">
59+
<h3>
60+
{componentName}
61+
{' '}
62+
</h3>
63+
<h4>{stateType}</h4>
64+
<h4>
65+
average time:
66+
{' '}
67+
{averageRenderTime}
68+
{' '}
69+
ms
70+
</h4>
71+
</div>
72+
<div
73+
onClick={() => {
74+
if (expand === true) {
75+
setExpand(false);
76+
} else {
77+
setExpand(true);
78+
}
79+
}}
80+
className="RenderRight"
81+
>
82+
<p>{renderFrequency}</p>
83+
</div>
5284
</div>
53-
<div className="RenderRight">
54-
<p>{renderFrequency}</p>
85+
<div className={expand === true ? 'DataComponent' : null} >
86+
{expand === true ? dataComponentArray : null}
5587
</div>
5688
</div>
5789
);
5890
};
59-
export default RenderingFrequency;
91+
92+
const DataComponent = props => {
93+
const {
94+
header,
95+
paragraphs,
96+
} = props;
97+
98+
return (
99+
<div className="borderCheck">
100+
<h4>
101+
{' '}
102+
{header}
103+
</h4>
104+
<p>
105+
106+
{paragraphs}
107+
</p>
108+
</div>
109+
);
110+
};
111+
112+
export default RenderingFrequency;

0 commit comments

Comments
 (0)