Skip to content

Commit 5a7b54d

Browse files
committed
adding refresh and debugging empty functionality
1 parent 09a8299 commit 5a7b54d

File tree

5 files changed

+105
-55
lines changed

5 files changed

+105
-55
lines changed

src/app/components/Diff.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function Diff({ snapshot, show }) {
2525
else formatters.html.hideUnchanged();
2626

2727
if (previous === undefined || delta === undefined) {
28-
return <div> No state change detected. Trigger an event to change state </div>;
28+
return <div className='noState'> No state change detected. Trigger an event to change state </div>;
2929
}
3030
return <div>{ReactHtmlParser(html)}</div>;
3131
}

src/app/components/StateRoute.jsx

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,29 @@ import Chart from './Chart';
88
import Tree from './Tree';
99

1010
// eslint-disable-next-line react/prop-types
11-
const StateRoute = ({ snapshot, hierarchy }) => (
11+
12+
const StateRoute = ({ snapshot, hierarchy }) => {
13+
// gabi :: the hierarchy get set on the first click in the page, when page in refreshed we don't have a hierarchy so we need to check if hierarchy was inicialize involk render chart
14+
const renderChart = () =>{
15+
if (hierarchy){
16+
return <Chart hierarchy={hierarchy} />
17+
}
18+
else{
19+
return <div className='noState'> No state change detected. Trigger an event to change state </div>;
20+
}
21+
}
22+
23+
// gabi :: the snapshot get set on the first click in the page, when page in refreshed we don't have a hierarchy so we need to check if snapshot was inicialize involk render chart
24+
const renderTree = () => {
25+
if (hierarchy){
26+
return <Tree snapshot={snapshot} />
27+
}
28+
else{
29+
return <div className='noState'> No state change detected. Trigger an event to change state </div>;
30+
}
31+
}
32+
33+
return (
1234
<Router>
1335
<div className="navbar">
1436
<NavLink className="router-link" activeClassName="is-active" exact to="/">
@@ -19,11 +41,11 @@ const StateRoute = ({ snapshot, hierarchy }) => (
1941
</NavLink>
2042
</div>
2143
<Switch>
22-
<Route path="/chart" render={() => <Chart hierarchy={hierarchy} />} />
23-
<Route path="/" render={() => <Tree snapshot={snapshot} />} />
44+
<Route path="/chart" render={renderChart} />
45+
<Route path="/" render={renderTree} />
2446
</Switch>
2547
</Router>
26-
);
48+
)};
2749

2850
StateRoute.propTypes = {
2951
snapshot: PropTypes.shape({

src/app/containers/ActionContainer.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ function ActionContainer() {
3434
displayArray(element)
3535
})
3636
}
37-
}
38-
displayArray(hierarchy)
37+
}
38+
// gabi :: the hierarchy get set on the first click in the page, when page in refreshed we don't have a hierarchy so we need to check if hierarchy was inicialize involk displayArray to display the hierarchy
39+
if (hierarchy) displayArray(hierarchy)
3940
// console.log('this is hierarchyArr', hierarchyArr)
4041

4142
actionsArr = hierarchyArr.map((snapshot, index) => {

src/app/reducers/mainReducer.js

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,22 @@ export default (state, action) => produce(state, draft => {
1111

1212

1313
// gabi and nate :: function that find the index in the hiearachy and extract the name of the equivalent index to add to the post message
14-
const findName = (index, hierarchy) => {
15-
if(hierarchy.index == index){
16-
return hierarchy.name;
14+
const findName = (index, hierarchy) => {
15+
if(hierarchy.index == index){
16+
return hierarchy.name;
17+
}
18+
else {
19+
const hierarchyChildArray = [];
20+
for (let hierarchyChild of hierarchy.children){
21+
hierarchyChildArray.push(findName(index, hierarchyChild));
1722
}
18-
else {
19-
const hierarchyChildArray = [];
20-
for (let hierarchyChild of hierarchy.children){
21-
hierarchyChildArray.push(findName(index, hierarchyChild));
23+
for (let hierarchyChildName of hierarchyChildArray){
24+
if(hierarchyChildName){
25+
return hierarchyChildName
2226
}
23-
for (let hierarchyChildName of hierarchyChildArray){
24-
if(hierarchyChildName){
25-
return hierarchyChildName
26-
}
27-
}
28-
}
29-
}
27+
}
28+
}
29+
}
3030

3131
switch (action.type) {
3232
case types.MOVE_BACKWARD: {
@@ -110,17 +110,27 @@ export default (state, action) => produce(state, draft => {
110110
tabs[currentTab].sliderIndex = 0;
111111
tabs[currentTab].viewIndex = -1;
112112
tabs[currentTab].playing = false;
113-
tabs[currentTab].snapshots.splice(1);
114-
// reset children in root node to reset graph
115-
if (tabs[currentTab].hierarchy) tabs[currentTab].hierarchy.children = [];
116-
// reassigning pointer to the appropriate node to branch off of
113+
// gabi :: activate empty mode
114+
tabs[currentTab].mode.empty = true
115+
// gabi :: record snapshot of page inicial state
116+
tabs[currentTab].inicialSnapshot.push(tabs[currentTab].snapshots[0]);
117+
// gabi :: reset snapshots to page last state recorded
118+
tabs[currentTab].snapshots = [ tabs[currentTab].snapshots[tabs[currentTab].snapshots.length - 1] ];
119+
// gabi :: record hierarchy of page inicial state
120+
tabs[currentTab].inicialHierarchy = {...tabs[currentTab].hierarchy};
121+
tabs[currentTab].inicialHierarchy.children = [];
122+
// gabi :: reset hierarchy
123+
tabs[currentTab].hierarchy.children = [];
124+
// gabi :: reset hierarchy to page last state recorded
125+
tabs[currentTab].hierarchy.stateSnapshot = tabs[currentTab].snapshots[0]
126+
// gabi :: reset currLocation to page last state recorded
117127
tabs[currentTab].currLocation = tabs[currentTab].hierarchy;
118-
// reset index
128+
// gabi :: reset index
119129
tabs[currentTab].index = 0;
120-
// gabi and nate :: reset name
121-
tabs[currentTab].name = 0;
122-
// gabi and nate :: reset branch
123-
tabs[currentTab].branch = 0;
130+
// gabi :: reset currParent plus current state
131+
tabs[currentTab].currParent = 1;
132+
// gabi :: reset currBranch
133+
tabs[currentTab].currBranch = 0;
124134
break;
125135
}
126136
case types.SET_PORT: {

src/extension/background.js

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ function createTabObj(title) {
1717
title,
1818
// snapshots is an array of ALL state snapshots for the reactime tab working on a specific user application
1919
snapshots: [],
20+
// gabi :: record inicial snapshot to refresh page in case empty function is called
21+
inicialSnapshot: [],
2022
// gabi and nate :: index here is the tab index that show total amount of state changes
2123
index: 0,
2224
//* 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)
@@ -27,10 +29,13 @@ function createTabObj(title) {
2729
currBranch: 0,
2830
//* inserting a new property to build out our hierarchy dataset for d3
2931
hierarchy: null,
32+
// gabi :: record inicial hierarchy to refresh page in case empty function is called
33+
inicialHierarchy: null,
3034
mode: {
3135
persist: false,
3236
locked: false,
3337
paused: false,
38+
empty: false,
3439
},
3540
};
3641
}
@@ -133,17 +138,27 @@ chrome.runtime.onConnect.addListener(port => {
133138
tabsObj[tabId].snapshots = payload;
134139
return true;
135140
case 'emptySnap':
136-
tabsObj[tabId].snapshots.splice(1);
137-
// reset children in root node to reset graph
141+
// gabi :: activate empty mode
142+
tabsObj[tabId].mode.empty = true
143+
// gabi :: record snapshot of page inicial state
144+
tabsObj[tabId].inicialSnapshot.push(tabsObj[tabId].snapshots[0]);
145+
// gabi :: reset snapshots to page last state recorded
146+
tabsObj[tabId].snapshots = [tabsObj[tabId].snapshots[tabsObj[tabId].snapshots.length - 1] ];
147+
// gabi :: record hierarchy of page inicial state
148+
tabsObj[tabId].inicialHierarchy = {...tabsObj[tabId].hierarchy};
149+
tabsObj[tabId].inicialHierarchy.children = [];
150+
// gabi :: reset hierarchy
138151
tabsObj[tabId].hierarchy.children = [];
139-
// reassigning pointer to the appropriate node to branch off of
152+
// gabi :: reset hierarchy to page last state recorded
153+
tabsObj[tabId].hierarchy.stateSnapshot = tabsObj[tabId].snapshots[0]
154+
// gabi :: reset currLocation to page last state recorded
140155
tabsObj[tabId].currLocation = tabsObj[tabId].hierarchy;
141-
// reset index
156+
// gabi :: reset index
142157
tabsObj[tabId].index = 0;
143-
// reset name
144-
tabs[currentTab].name = 0;
145-
// reset branch
146-
tabs[currentTab].branch = 0;
158+
// gabi :: reset currParent plus current state
159+
tabsObj[tabId].currParent = 1;
160+
// gabi :: reset currBranch
161+
tabsObj[tabId].currBranch = 0;
147162
return true;
148163
case 'setLock':
149164
tabsObj[tabId].mode.locked = payload;
@@ -185,13 +200,10 @@ chrome.runtime.onMessage.addListener((request, sender) => {
185200
tabsObj[tabId] = createTabObj(tabTitle);
186201
}
187202

188-
const { persist } = tabsObj[tabId].mode;
203+
const { persist, empty } = tabsObj[tabId].mode;
189204

190205
switch (action) {
191206
case 'jumpToSnap': {
192-
// console.log('this tabsObj[tabId] sent to changeCurrLocation', tabsObj[tabId])
193-
// console.log('this tabsObj[tabId].hierarchy sent to changeCurrLocation', tabsObj[tabId].hierarchy)
194-
// console.log('this index sent to changeCurrLocation', index)
195207
changeCurrLocation(tabsObj[tabId], tabsObj[tabId].hierarchy, index, name);
196208
break;
197209
}
@@ -201,20 +213,25 @@ chrome.runtime.onMessage.addListener((request, sender) => {
201213
tabsObj[tabId].mode.paused = false;
202214
// dont remove snapshots if persisting
203215
if (!persist) {
204-
tabsObj[tabId].snapshots.splice(1);
205-
// reset children in root node to reset graph
206-
if (tabsObj[tabId].hierarchy)
216+
if(empty){
217+
// gabi :: reset snapshots to page inicial state recorded when empted
218+
tabsObj[tabId].snapshots = tabsObj[tabId].inicialSnapshot;
219+
// gabi :: reset hierarchy to page inicial state recorded when empted
220+
tabsObj[tabId].hierarchy = tabsObj[tabId].inicialHierarchy
221+
} else {
222+
// gabi :: reset snapshots to page inicial state
223+
tabsObj[tabId].snapshots.splice(1);
224+
// gabi :: reset hierarchy to page inicial state
207225
tabsObj[tabId].hierarchy.children = [];
208-
// reassigning pointer to the appropriate node to branch off of
209-
// tabsObj[tabId].hierarchy = null;
210-
tabsObj[tabId].currLocation = tabsObj[tabId].hierarchy;
211-
// tabsObj[tabId].currLocation = null;
212-
// reset index
213-
tabsObj[tabId].index = 0;
214-
// reset currParent
215-
tabsObj[tabId].currParent = 0;
216-
// reset currBranch
217-
tabsObj[tabId].currBranch = 0;
226+
}
227+
// gabi :: reset currLocation to page inicial state
228+
tabsObj[tabId].currLocation = tabsObj[tabId].hierarchy;
229+
// gabi :: reset index
230+
tabsObj[tabId].index = 0;
231+
// gabi :: reset currParent plus current state
232+
tabsObj[tabId].currParent = 1;
233+
// gabi :: reset currBranch
234+
tabsObj[tabId].currBranch = 0;
218235

219236
// send a message to devtools
220237
portsArr.forEach(bg =>

0 commit comments

Comments
 (0)