Skip to content

Commit feff6b9

Browse files
davidchai717nusanam
andcommitted
Hierarchy tree resets when reloading
Co-authored-by: Ruth Anam <[email protected]> Co-authored-by: David Chai <[email protected]>
1 parent b42eea5 commit feff6b9

File tree

2 files changed

+35
-20
lines changed

2 files changed

+35
-20
lines changed

src/app/components/Chart.jsx

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,31 @@ class Chart extends Component {
1313
super(props);
1414
this.chartRef = React.createRef();
1515
this.maked3Tree = this.maked3Tree.bind(this);
16+
this.removed3Tree = this.removed3Tree.bind(this);
1617
}
1718
componentDidMount() {
1819
const { snapshot, hierarchy } = this.props;
1920
console.log('initial props', this.props)
20-
root = JSON.parse(JSON.stringify(snapshot));
21+
root = JSON.parse(JSON.stringify(hierarchy));
2122
this.maked3Tree();
2223
}
2324

2425
componentDidUpdate() {
2526
const { snapshot, hierarchy } = this.props;
2627
console.log('updated props', this.props)
27-
root = JSON.parse(JSON.stringify(snapshot));
28+
root = JSON.parse(JSON.stringify(hierarchy));
2829
this.maked3Tree();
2930
}
3031

31-
// removed3Tree() {
32-
// const { anchor } = this.refs;
33-
// while (anchor.hasChildNodes()) {
34-
// anchor.removeChild(anchor.lastChild);
35-
// }
36-
// }
32+
removed3Tree() {
33+
const { current } = this.chartRef;
34+
while (current.hasChildNodes()) {
35+
current.removeChild(current.lastChild);
36+
}
37+
}
3738

3839
maked3Tree() {
39-
40+
this.removed3Tree();
4041
let width = 900;
4142
let height = 1000;
4243
let chartContainer = d3.select(this.chartRef.current)

src/extension/background.js

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ function createTabObj(title) {
1111
title,
1212
// snapshots is an array of ALL state snapshots for the reactime tab working on a specific user application
1313
snapshots: [],
14+
index: 0,
1415
//* 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)
1516
currLocation: null,
1617
//* inserting a new property to build out our hierarchy dataset for d3
@@ -23,19 +24,20 @@ function createTabObj(title) {
2324
};
2425
}
2526

26-
const makeNewNode = () => {
27-
let num = 0;
2827

29-
return class Node {
30-
constructor(obj) {
31-
this.index = num += 1;
28+
// function resetIndex(num) {
29+
// return num = 0;
30+
// }
31+
32+
// let num = 0;
33+
34+
class Node {
35+
constructor(obj, tabObj) {
36+
this.index = tabObj.index += 1;
3237
this.stateSnapshot = obj;
3338
this.children = [];
3439
}
3540
};
36-
};
37-
38-
const Node = makeNewNode();
3941

4042
function sendToHierarchy (tabObj, newNode) {
4143
if (!tabObj.currLocation) {
@@ -72,7 +74,7 @@ chrome.runtime.onConnect.addListener(port => {
7274
if (Object.keys(tabsObj).length > 0) {
7375
port.postMessage({
7476
action: 'initialConnectSnapshots',
75-
payload: {...tabsObj, msg: 'connection to devgools made'},
77+
payload: { ...tabsObj, msg: 'connection to devgools made' },
7678
});
7779
}
7880

@@ -103,6 +105,12 @@ chrome.runtime.onConnect.addListener(port => {
103105
return;
104106
case 'emptySnap':
105107
tabsObj[tabId].snapshots.splice(1);
108+
// reset children in root node to reset graph
109+
tabsObj[tabId].hierarchy.children = [];
110+
// reassigning pointer to the appropriate node to branch off of
111+
tabsObj[tabId].currLocation = tabsObj[tabId].hierarchy;
112+
// reset index
113+
tabsObj[tabId].index = 1;
106114
return;
107115
case 'setLock':
108116
tabsObj[tabId].mode.locked = payload;
@@ -148,6 +156,12 @@ chrome.runtime.onMessage.addListener((request, sender) => {
148156
// dont remove snapshots if persisting
149157
if (!persist) {
150158
tabsObj[tabId].snapshots.splice(1);
159+
// reset children in root node to reset graph
160+
tabsObj[tabId].hierarchy.children = [];
161+
// reassigning pointer to the appropriate node to branch off of
162+
tabsObj[tabId].currLocation = tabsObj[tabId].hierarchy;
163+
// reset index
164+
tabsObj[tabId].index = 1;
151165

152166
// send a message to devtools
153167
portsArr.forEach(bg => bg.postMessage({
@@ -170,7 +184,7 @@ chrome.runtime.onMessage.addListener((request, sender) => {
170184
reloaded[tabId] = false;
171185

172186
tabsObj[tabId].snapshots.push(request.payload);
173-
sendToHierarchy(tabsObj[tabId], new Node(request.payload));
187+
sendToHierarchy(tabsObj[tabId], new Node(request.payload, tabsObj[tabId]));
174188
if (portsArr.length > 0) {
175189
portsArr.forEach(bg => bg.postMessage({
176190
action: 'initialConnectSnapshots',
@@ -186,7 +200,7 @@ chrome.runtime.onMessage.addListener((request, sender) => {
186200
} else {
187201
tabsObj[tabId].snapshots.push(request.payload);
188202
//! INVOKING buildHierarchy FIGURE OUT WHAT TO PASS IN!!!!
189-
sendToHierarchy(tabsObj[tabId], new Node(request.payload));
203+
sendToHierarchy(tabsObj[tabId], new Node(request.payload, tabsObj[tabId]));
190204
}
191205
// send message to devtools
192206
if (portsArr.length > 0) {

0 commit comments

Comments
 (0)