Skip to content

Commit 1b0180d

Browse files
authored
Merge pull request #86 from oslabs-beta/staging
Staging
2 parents 725a553 + 54b4850 commit 1b0180d

File tree

16 files changed

+9893
-60
lines changed

16 files changed

+9893
-60
lines changed

.gitmodules

Whitespace-only changes.

src/app/components/PerfView.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ interface PerfViewProps {
3131

3232
const PerfView = (props:PerfViewProps) => {
3333
const { snapshots, viewIndex, width, height } = props
34+
let adjustedSize = Math.min(width, height);
3435
const svgRef = useRef(null);
3536

3637
// Figure out which snapshot index to use
@@ -41,19 +42,18 @@ const PerfView = (props:PerfViewProps) => {
4142
// Set up color scaling function
4243
const colorScale = d3.scaleLinear()
4344
.domain([0, 7])
44-
.range(['hsl(200,60%,60%)', 'hsl(255,30%,30%)'])
45-
// .range(['hsl(152,30%,80%)', 'hsl(228,30%,40%)'])
45+
.range(['hsl(200,60%,60%)', 'hsl(255,30%,60%)'])
4646
.interpolate(d3.interpolateHcl);
4747

4848
// Set up circle-packing layout function
4949
const packFunc = useCallback((data:object) => {
5050
return d3.pack()
51-
.size([width, height])
51+
.size([adjustedSize, adjustedSize])
5252
// .radius(d => { return d.r; })
5353
.padding(3)(d3.hierarchy(data)
5454
.sum((d:{componentData?:{actualDuration?:number}}) => { return d.componentData.actualDuration || 0; })
5555
.sort((a:{value:number}, b:{value:number}) => { return b.value - a.value; }));
56-
}, [width, height]);
56+
}, [adjustedSize]);
5757

5858
// If indexToDisplay changes, clear old tree nodes
5959
useEffect(() => {
@@ -79,8 +79,12 @@ const PerfView = (props:PerfViewProps) => {
7979
let view;
8080

8181
// Set up viewBox dimensions and onClick for parent svg
82+
83+
// console.log("PerfView -> height", height)
84+
// console.log("PerfView -> width", width)
85+
// console.log("PerfView -> adjustedSize", adjustedSize)
8286
const svg = d3.select(svgRef.current)
83-
.attr('viewBox', `-${width / 2} -${height / 2} ${width} ${height}`)
87+
.attr('viewBox', `-${adjustedSize / 2} -${adjustedSize / 2} ${width} ${height}`)
8488
.on('click', () => zoomToNode(packedRoot));
8589

8690
// Connect circles below root to data

src/app/components/StateRoute.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const StateRoute = (props:StateRouteProps) => {
4242
if (hierarchy) {
4343
return (
4444
<ErrorHandler>
45-
<PerfView viewIndex={viewIndex} snapshots={snapshots} width={600} height={600}/>
45+
<PerfView viewIndex={viewIndex} snapshots={snapshots} width={600} height={1000}/>
4646
</ErrorHandler>
4747
);
4848
}

src/app/components/Tree.tsx

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
11
import React from 'react';
22
import JSONTree from 'react-json-tree';
33

4-
54
const getItemString = (type, data:{state?:object|string, name:string, children:[]}) => {
6-
// check to make sure that we are on the tree node, not anything else
7-
if (
8-
Object.keys(data).length > 3
9-
&& typeof data.state === 'object'
10-
&& typeof data.name === 'string'
11-
&& Array.isArray(data.children)
12-
) {
5+
if (data && data.name) {
136
return <span>{data.name}</span>;
147
}
15-
return null;
8+
return <span />;
169
};
1710

1811
interface TreeProps {
@@ -22,6 +15,8 @@ interface TreeProps {
2215
const Tree = (props:TreeProps) => {
2316
const { snapshot } = props;
2417

18+
console.log('Tree -> snapshot', snapshot);
19+
2520
return (
2621
<>
2722
{snapshot && (
@@ -30,7 +25,9 @@ const Tree = (props:TreeProps) => {
3025
theme={{ tree: () => ({ className: 'json-tree' }) }}
3126
shouldExpandNode={() => true}
3227
getItemString={getItemString}
33-
labelRenderer={(raw:any[]) => (typeof raw[0] !== 'number' ? <span>{raw[0]}</span> : null)}
28+
labelRenderer={(raw:any[]) => {
29+
return (typeof raw[0] !== 'number' ? <span>{raw[0]}</span> : null)
30+
}}
3431
/>
3532
)}
3633
</>

src/app/containers/MainContainer.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,14 @@ function MainContainer(): any {
8484
// if viewIndex is -1, then use the sliderIndex instead
8585
const snapshotView = viewIndex === -1 ? snapshots[sliderIndex] : snapshots[viewIndex];
8686
// gabi :: cleannign hierarchy and snapshotView from stateless data
87-
const statelessCleanning = (obj:{name?:string; componentData?:object; state?:object|string;stateSnaphot?:object; children?:any[]}) => {
87+
const statelessCleanning = (
88+
obj:{
89+
name?:string;
90+
componentData?:object;
91+
state?:{hooksState?: any | {componentData?: any}[]} | string;
92+
stateSnaphot?:object;
93+
children?:any[];
94+
}) => {
8895
const newObj = { ...obj };
8996
if (newObj.name === 'nameless') {
9097
delete newObj.name;
@@ -95,6 +102,14 @@ function MainContainer(): any {
95102
if (newObj.state === 'stateless') {
96103
delete newObj.state;
97104
}
105+
if (newObj.state && newObj.state.hooksState) {
106+
if (Array.isArray(newObj.state.hooksState)) {
107+
newObj.state.hooksState.forEach(s => {
108+
delete s.componentData;
109+
});
110+
}
111+
}
112+
98113
if (newObj.stateSnaphot) {
99114
newObj.stateSnaphot = statelessCleanning(obj.stateSnaphot);
100115
}

src/app/reducers/mainReducer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default (state, action) => produce(state, draft => {
1818
// eslint-disable-next-line consistent-return
1919
const findName = (index, obj) => {
2020
// eslint-disable-next-line eqeqeq
21-
if (obj.index == index) {
21+
if (obj && obj.index == index) {
2222
return obj.name;
2323
}
2424

src/app/styles/components/d3graph.css

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,19 @@ div.tooltip {
5454
max-width: 250px;
5555
overflow-wrap: break-word;
5656
padding: 6px;
57-
color: #1a2229;
57+
color: #320a5c;
5858
font-size: 12px;
5959
font-family: "Overpass Mono", monospace;
60-
background: #6699C4;
60+
background: #9cf4df;
6161
border-radius: 8px;
6262
pointer-events: none;
6363
}
6464

6565
.d3-tip {
6666
line-height: 1;
6767
padding: 6px;
68-
background: #6699C4;
69-
color: #1a2229;
68+
background: #9cf4df;
69+
color: #320a5c;
7070
border-radius: 4px;
7171
font-size: 13px;
7272
max-width: 400px;
@@ -80,7 +80,7 @@ div.tooltip {
8080
display: inline;
8181
font-size: 15px;
8282
line-height: 1;
83-
color: #6699C4;
83+
color: #9cf4df;
8484
content: "\25BC";
8585
position: absolute;
8686
text-align: center;
@@ -102,9 +102,9 @@ div.tooltip {
102102
}
103103

104104
.perf-d3-container {
105-
display: flex;
106-
flex-direction: column;
107-
justify-content: space-between;
105+
/* display: flex; */
106+
/* flex-direction: column; */
107+
/* justify-content: space-between; */
108108
height: calc(100% - 70px);
109109
/* border: 2px solid red; */
110110
}
@@ -115,6 +115,7 @@ div.tooltip {
115115

116116
.perf-chart-labels {
117117
font: 1.3em sans-serif;
118+
font-weight: bold;
118119
/* font-size: calc(12px + .8vw); */
119120
/* color: white; */
120121
/* fill: rgb(231, 231, 231); */

src/backend/helpers.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ export const throttle = (f, t) => {
1717
if (isOnCooldown && isCallQueued) return;
1818
if (isOnCooldown) {
1919
isCallQueued = true;
20+
console.log('snapshot update already queued');
2021
return;
2122
}
23+
console.log('no queue, updating snapshot from trigger func');
2224
f();
2325
isOnCooldown = true;
2426
isCallQueued = false;
@@ -27,11 +29,14 @@ export const throttle = (f, t) => {
2729
if (isCallQueued) {
2830
isCallQueued = false;
2931
isOnCooldown = true; // not needed I think
32+
console.log('calling queued call');
33+
f();
3034
setTimeout(runAfterTimeout, t);
3135
return;
3236
}
3337
isOnCooldown = false;
3438
};
39+
console.log('queueing snapshot update');
3540
setTimeout(runAfterTimeout, t);
3641
};
3742
return throttledFunc;

src/backend/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function getRouteURL(node: SnapshotNode): string {
4040
window.addEventListener('message', ({ data: { action, payload } } : MsgData) => {
4141
switch (action) {
4242
case 'jumpToSnap':
43-
timeJump(payload); // * This sets state with given payload
43+
timeJump(payload, true); // * This sets state with given payload
4444
// Get the pathname from payload and add new entry to browser history
4545
// MORE: https://developer.mozilla.org/en-US/docs/Web/API/History/pushState
4646

src/backend/linkFiber.ts

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ export default (snap: Snapshot, mode: Mode): ()=>void => {
7878
// Carlos: these two are legacy comments, we should look into them later
7979
// prevents useEffect from crashing on load
8080
// if (memoizedState.next.queue === null) { // prevents double pushing snapshot updates
81-
// console.log('traverse hooks memoizedState', memoizedState);
82-
if (memoizedState.memoizedState) {
81+
if (memoizedState.memoizedState && memoizedState.queue.lastRenderedReducer && memoizedState.queue.lastRenderedReducer.name === 'basicStateReducer') {
8382
hooksStates.push({
8483
component: memoizedState.queue,
8584
state: memoizedState.memoizedState,
@@ -112,6 +111,10 @@ export default (snap: Snapshot, mode: Mode): ()=>void => {
112111
treeBaseDuration,
113112
} = currentFiber;
114113

114+
<<<<<<< HEAD
115+
let newState: any = {};
116+
let componentData: ComponentData = {};
117+
=======
115118
let newState: any;
116119
let componentData: ComponentData = {};
117120
/* = {
@@ -122,6 +125,7 @@ export default (snap: Snapshot, mode: Mode): ()=>void => {
122125
treeBaseDuration: 0,
123126
};
124127
*/
128+
>>>>>>> master
125129
let componentFound = false;
126130

127131
// Check if node is a stateful setState component
@@ -146,11 +150,15 @@ export default (snap: Snapshot, mode: Mode): ()=>void => {
146150
hooksStates.forEach((state, i) => {
147151
hooksIndex = componentActionsRecord.saveNew(state.state, state.component);
148152
if (newState && newState.hooksState) {
149-
newState.hooksState.push([{ [hooksNames[i]]: state.state }, hooksIndex]);
153+
newState.hooksState.push({ [hooksNames[i]]: state.state, componentData: { index: hooksIndex } });
154+
// newState.hooksState.push([{ [hooksNames[i]]: state.state }, hooksIndex]);
150155
} else if (newState) {
151-
newState.hooksState = [{ [hooksNames[i]]: state.state }, hooksIndex];
156+
newState.hooksState = [{ [hooksNames[i]]: state.state, componentData: { index: hooksIndex } }];
157+
// newState.hooksState = [{ [hooksNames[i]]: state.state }, hooksIndex];
152158
} else {
153-
newState = { hooksState: [{ [hooksNames[i]]: state.state }, hooksIndex] };
159+
// newState = { hooksState: [{ [hooksNames[i]]: state.state }, hooksIndex] };
160+
newState = { hooksState: [] };
161+
newState.hooksState.push({ [hooksNames[i]]: state.state, componentData: { index: hooksIndex } });
154162
}
155163
componentFound = true;
156164
});
@@ -174,7 +182,10 @@ export default (snap: Snapshot, mode: Mode): ()=>void => {
174182

175183
let newNode = null;
176184
// We want to add this fiber node to the snapshot
185+
<<<<<<< HEAD
186+
=======
177187
// const snapshotState = newState.state || newState.hooksState;
188+
>>>>>>> master
178189
if (componentFound || newState === 'stateless') {
179190
if (fromSibling) {
180191
newNode = tree.addSibling(newState,
@@ -185,6 +196,7 @@ export default (snap: Snapshot, mode: Mode): ()=>void => {
185196
elementType ? elementType.name : 'nameless',
186197
componentData);
187198
}
199+
if (newState !== 'stateless') console.log('state updated:', newState);
188200
} else {
189201
newNode = tree;
190202
}
@@ -217,7 +229,10 @@ export default (snap: Snapshot, mode: Mode): ()=>void => {
217229

218230
function onVisibilityChange(): void {
219231
doWork = !document.hidden;
232+
<<<<<<< HEAD
233+
=======
220234
// console.log('doWork is:', doWork);
235+
>>>>>>> master
221236
}
222237

223238
return () => {
@@ -244,7 +259,12 @@ export default (snap: Snapshot, mode: Mode): ()=>void => {
244259
return function (...args) {
245260
// eslint-disable-next-line prefer-destructuring
246261
fiberRoot = args[1];
247-
if (doWork) throttledUpdateSnapshot();
262+
console.log('in CFR committed fiber');
263+
if (doWork) {
264+
console.log('in CFR: updating snapshot');
265+
throttledUpdateSnapshot();
266+
}
267+
console.log('in CFR updated snapshot');
248268
return original(...args);
249269
};
250270
}(devTools.onCommitFiberRoot));

0 commit comments

Comments
 (0)