Skip to content

Commit 40079aa

Browse files
davidchai717nusanam
andcommitted
Fixes and further debugging
Co-authored-by: Ruth Anam <[email protected]> Co-authored-by: David Chai <[email protected]>
1 parent b59b22f commit 40079aa

File tree

7 files changed

+60
-60
lines changed

7 files changed

+60
-60
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"Bryan Lee",
2626
"David Chai",
2727
"Josh Kim",
28-
"Ruthba Anam",
28+
"Ruth Anam",
2929
"Ryan Dang",
3030
"Sierra Swaby",
3131
"Yujin Kang"

src/app/components/Chart.jsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,21 @@ let root = {};
1010
let duration = 750;
1111

1212
class Chart extends Component {
13-
constructor() {
14-
super();
13+
constructor(props) {
14+
super(props);
1515
this.chartRef = React.createRef();
1616
this.maked3Tree = this.maked3Tree.bind(this);
1717
}
1818
componentDidMount() {
19-
const { snapshot } = this.props;
19+
const { snapshot, hierarchy } = this.props;
20+
console.log('initial props', this.props)
2021
root = JSON.parse(JSON.stringify(snapshot));
2122
this.maked3Tree();
2223
}
2324

2425
componentDidUpdate() {
25-
const { snapshot } = this.props;
26+
const { snapshot, hierarchy } = this.props;
27+
console.log('updated props', this.props)
2628
root = JSON.parse(JSON.stringify(snapshot));
2729
this.maked3Tree();
2830
}
@@ -140,8 +142,6 @@ class Chart extends Component {
140142

141143
let root = tree(hierarchy);
142144

143-
console.log('children', root.descendants());
144-
145145
g.selectAll('.link')
146146
// root.links() gets an array of all the links, where each element is an object containing a source property, which represents the link's source node, and a target property, which represents the link's target node.
147147
.data(root.links())

src/app/components/StateRoute.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
import Chart from './Chart';
88
import Tree from './Tree';
99

10-
const StateRoute = ({ snapshot }) => (
10+
const StateRoute = ({ snapshot, hierarchy }) => (
1111
<Router>
1212
<div className="navbar">
1313
<NavLink className="router-link" activeClassName="is-active" exact to="/">
@@ -18,7 +18,7 @@ const StateRoute = ({ snapshot }) => (
1818
</NavLink>
1919
</div>
2020
<Switch>
21-
<Route path="/chart" render={() => <Chart snapshot={snapshot} />} />
21+
<Route path="/chart" render={() => <Chart snapshot={snapshot} hierarchy={hierarchy} />} />
2222
<Route path="/" render={() => <Tree snapshot={snapshot} />} />
2323
</Switch>
2424
</Router>

src/app/containers/MainContainer.jsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ function MainContainer() {
2424
// listen for a message containing snapshots from the background script
2525
port.onMessage.addListener(message => {
2626
const { action, payload, sourceTab } = message;
27+
console.log('action message', action);
28+
console.log('payload message', message)
2729
switch (action) {
2830
case 'deleteTab': {
2931
dispatch(deleteTab(payload));
@@ -65,7 +67,8 @@ function MainContainer() {
6567
</div>
6668
);
6769
}
68-
const { viewIndex, sliderIndex, snapshots } = tabs[currentTab];
70+
const { viewIndex, sliderIndex, snapshots, hierarchy } = tabs[currentTab];
71+
console.log('main container', tabs[currentTab]);
6972

7073
// if viewIndex is -1, then use the sliderIndex instead
7174
const snapshotView = viewIndex === -1 ? snapshots[sliderIndex] : snapshots[viewIndex];
@@ -74,7 +77,7 @@ function MainContainer() {
7477
<HeadContainer />
7578
<div className="body-container">
7679
<ActionContainer />
77-
{snapshots.length ? <StateContainer snapshot={snapshotView} /> : null}
80+
{snapshots.length ? <StateContainer snapshot={snapshotView} hierarchy={hierarchy} /> : null}
7881
<TravelContainer snapshotsLength={snapshots.length} />
7982
<ButtonsContainer />
8083
</div>

src/app/containers/StateContainer.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import StateRoute from '../components/StateRoute';
77
import DiffRoute from '../components/DiffRoute';
88

99

10-
const StateContainer = ({ snapshot }) => {
10+
const StateContainer = ({ snapshot, hierarchy }) => {
11+
console.log('passing?', hierarchy);
1112
const [Text, setText] = useState('State');
1213
return (
1314
<Router>
@@ -27,7 +28,7 @@ const StateContainer = ({ snapshot }) => {
2728
</div>
2829
<Switch>
2930
<Route path="/diff" render={() => { setText('Diff'); return <DiffRoute snapshot={snapshot} />; }} />
30-
<Route path="/" render={() => { setText('State'); return <StateRoute snapshot={snapshot} />; }} />
31+
<Route path="/" render={() => { setText('State'); return <StateRoute snapshot={snapshot} hierarchy={hierarchy} />; }} />
3132
</Switch>
3233
</div>
3334
</Router>

src/extension/background.js

Lines changed: 42 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function createTabObj(title) {
1212
// snapshots is an array of ALL state snapshots for the reactime tab working on a specific user application
1313
snapshots: [],
1414
//* this is our pointer so we know what the current state the user is checking (this accounts for time travel aka when user clicks jump on the UI)
15-
currentStatePointer: null,
15+
currLocation: null,
1616
//* inserting a new property to build out our hierarchy dataset for d3
1717
hierarchy: null,
1818
mode: {
@@ -22,48 +22,46 @@ function createTabObj(title) {
2222
},
2323
};
2424
}
25-
// once state is modified (when user does something with app), a step appears in actionContainer.jsx column. That current state snapshot is added to our hierarchy object. That is what the buildHierarchy function is for. It takes in the entire tabObj, which has a hierarcy object as a property within it. Then we build this hierarchy object so that d3 can render graphs in our extension
26-
function buildHierarchy(obj, newNode) {
27-
// whenever we receive a snapshot from contentScript.js via message, we execute this function
28-
//* if empty on extension UI is clicked hierarchy needs to be reset to an object
29-
let num = 1;
30-
class d3Node {
31-
constructor(num, obj) {
32-
this.name = num++;
25+
26+
const makeNewNode = () => {
27+
let num = 0;
28+
29+
return class Node {
30+
constructor(obj) {
31+
this.index = num += 1;
3332
this.stateSnapshot = obj;
3433
this.children = [];
3534
}
36-
}
37-
38-
obj.hierarchy
39-
/* properties inside this object absolutely requires:
40-
name: string (the first state snapshot has to be a root)
41-
stateSnapshot: object
42-
currentStateSnapshot: boolean
43-
*/
44-
45-
// each time a statesnapshot is added, this gets incremented otherwise it will be decremented
46-
// we need to find a way to traverse through the object to know which node the user is on so we can add a new state snapshot in the right location
47-
// could we potentially have a variable in timejump function (timeJump.js in the package) that our function can work with --> contentScript.js has access to it --> we can access that variable message;
48-
stateCount = 1;
49-
50-
class stateNode {
51-
52-
constructor() {
53-
this.name = `state${stateCount}`;
54-
this.stateSnapshot = {};
55-
this.children = [];
56-
}
57-
}
35+
};
36+
};
5837

38+
const Node = makeNewNode();
5939

60-
// create a helper function that groups all the snapshots underneath each other
61-
// current state snapshot
62-
// needs to be supplied by the UI
63-
// also need to figure out how we would traverse through the big ass object to find the current state
64-
// Create a new object with name,
40+
function sendToHierarchy (tabObj, newNode) {
41+
if (!tabObj.currLocation) {
42+
tabObj.currLocation = newNode;
43+
tabObj.hierarchy = newNode;
44+
} else {
45+
tabObj.currLocation.children.push(newNode);
46+
tabObj.currLocation = newNode;
47+
}
48+
}
49+
function changeCurrLocation (tabObj, rootNode, index) {
50+
// check if current node has the index wanted
51+
if (rootNode.index === index) {
52+
tabObj.currLocation = rootNode;
53+
return;
54+
}
55+
// base case if no children
56+
if (!rootNode.children.length) {
57+
return;
58+
} else {
59+
// if not, recurse on each one of the children
60+
hierarchy.children.forEach(child => {
61+
changeCurrLocation(tabObj, child, index);
62+
});
63+
}
6564
}
66-
6765

6866
// establishing connection with devtools
6967
chrome.runtime.onConnect.addListener(port => {
@@ -74,7 +72,7 @@ chrome.runtime.onConnect.addListener(port => {
7472
if (Object.keys(tabsObj).length > 0) {
7573
port.postMessage({
7674
action: 'initialConnectSnapshots',
77-
payload: tabsObj,
75+
payload: {...tabsObj, msg: 'connection to devgools made'},
7876
});
7977
}
8078

@@ -150,15 +148,16 @@ chrome.runtime.onMessage.addListener((request, sender) => {
150148
// dont remove snapshots if persisting
151149
if (!persist) {
152150
tabsObj[tabId].snapshots.splice(1);
153-
151+
154152
// send a message to devtools
155153
portsArr.forEach(bg => bg.postMessage({
156154
action: 'initialConnectSnapshots',
157-
payload: tabsObj,
155+
payload: { ...tabsObj, msg: 'reload' },
158156
}));
159157
}
160158

161159
reloaded[tabId] = true;
160+
162161

163162
break;
164163
}
@@ -171,14 +170,11 @@ chrome.runtime.onMessage.addListener((request, sender) => {
171170
reloaded[tabId] = false;
172171

173172
tabsObj[tabId].snapshots.push(request.payload);
174-
//! INVOKING buildHierarchy FIGURE OUT WHAT TO PASS IN!!!!
175-
let currentStateObject = tabsObj[tabId]
176-
buildHierarchy(tabsObj[tabId], request.payloadTurnedIntoNODE );
177-
console.log(tabsObj[tabId].snapshots);
173+
sendToHierarchy(tabsObj[tabId], new Node(request.payload));
178174
if (portsArr.length > 0) {
179175
portsArr.forEach(bg => bg.postMessage({
180176
action: 'initialConnectSnapshots',
181-
payload: tabsObj,
177+
payload: {...tabsObj, msg: 'firstsnapshotreceived'},
182178
}));
183179
}
184180
break;
@@ -190,7 +186,7 @@ chrome.runtime.onMessage.addListener((request, sender) => {
190186
} else {
191187
tabsObj[tabId].snapshots.push(request.payload);
192188
//! INVOKING buildHierarchy FIGURE OUT WHAT TO PASS IN!!!!
193-
buildHierarchy();
189+
sendToHierarchy(tabsObj[tabId], new Node(request.payload));
194190
}
195191
// send message to devtools
196192
if (portsArr.length > 0) {

src/extension/contentScript.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ window.addEventListener('message', msg => {
1111
firstMessage = false;
1212
}
1313

14-
// post initial Message to npm package
14+
// post initial Message to background.js
1515
const { action } = msg.data;
1616
if (action === 'recordSnap') chrome.runtime.sendMessage(msg.data);
1717
});

0 commit comments

Comments
 (0)