Skip to content

Commit 931670f

Browse files
authored
Merge pull request #13 from oslabs-beta/staging
Staging
2 parents fcc8e14 + b5c675f commit 931670f

File tree

7 files changed

+140
-45
lines changed

7 files changed

+140
-45
lines changed

src/app/components/Chart.jsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ class Chart extends Component {
2323

2424
componentDidMount() {
2525
const { hierarchy } = this.props;
26-
console.log('this is hierarchy on didMount chart', hierarchy)
26+
// console.log('this is hierarchy on didMount chart', hierarchy)
2727
root = JSON.parse(JSON.stringify(hierarchy));
2828
this.maked3Tree();
2929
}
3030

3131
componentDidUpdate() {
3232
const { hierarchy } = this.props;
33-
console.log('this is hierarchy on didUpdate chart', hierarchy)
33+
// console.log('this is hierarchy on didUpdate chart', hierarchy)
3434
root = JSON.parse(JSON.stringify(hierarchy));
3535
this.maked3Tree();
3636
}
@@ -52,7 +52,7 @@ class Chart extends Component {
5252
};
5353
const width = 600 - margin.right - margin.left;
5454
const height = 700 - margin.top - margin.bottom;
55-
console.log('this is this.chartRef.current on chart', this.chartRef.current)
55+
// console.log('this is this.chartRef.current on chart', this.chartRef.current)
5656
const chartContainer = d3.select(this.chartRef.current)
5757
.append('svg') // chartContainer is now pointing to svg
5858
.attr('width', width)
@@ -145,7 +145,7 @@ class Chart extends Component {
145145
// this arranges the angle of the text
146146
.attr('transform', function (d) { return 'rotate(' + (d.x < Math.PI ? d.x - Math.PI / 2 : d.x + Math.PI / 2) * 1 / Math.PI + ')'; })
147147
.text(function (d) {
148-
console.log('this is d from text char line 148', d)
148+
// console.log('this is d from text char line 148', d)
149149
// save d.data.index to variable
150150
// gabi and nate :: display the name of of specific patch
151151
return `${d.data.name}.${d.data.branch}`;

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: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ function ActionContainer() {
3434
displayArray(element)
3535
})
3636
}
37-
}
38-
displayArray(hierarchy)
39-
console.log('this is hierarchyArr', hierarchyArr)
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)
40+
// console.log('this is hierarchyArr', hierarchyArr)
4041

4142
actionsArr = hierarchyArr.map((snapshot, index) => {
4243
const selected = index === viewIndex;

src/app/containers/MainContainer.jsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@ import { useStoreContext } from '../store';
1313
function MainContainer() {
1414
const [store, dispatch] = useStoreContext();
1515
const { tabs, currentTab, port: currentPort } = store;
16-
console.log('entered MainContainer');
16+
// console.log('entered MainContainer');
1717

1818
// add event listeners to background script
1919
useEffect(() => {
2020
// only open port once
2121
if (currentPort) return;
2222
// open connection with background script
23-
console.log('opening connection with background script');
23+
// console.log('opening connection with background script');
2424
const port = chrome.runtime.connect();
25-
console.log('connection opened?');
25+
// console.log('connection opened?');
2626

2727
// listen for a message containing snapshots from the background script
2828
port.onMessage.addListener(message => {
29-
console.log('this is message from port', message)
29+
// console.log('this is message from port', message)
3030
const { action, payload, sourceTab } = message;
3131
switch (action) {
3232
case 'deleteTab': {

src/app/reducers/mainReducer.js

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,44 @@
22
import produce from 'immer';
33
import * as types from '../constants/actionTypes';
44

5+
56
export default (state, action) => produce(state, draft => {
67
const { port, currentTab, tabs } = draft;
78
const {
8-
snapshots, mode, intervalId, viewIndex, sliderIndex,
9+
hierarchy, snapshots, mode, intervalId, viewIndex, sliderIndex,
910
} = tabs[currentTab] || {};
11+
12+
13+
// 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;
17+
}
18+
else {
19+
const hierarchyChildArray = [];
20+
for (let hierarchyChild of hierarchy.children){
21+
hierarchyChildArray.push(findName(index, hierarchyChild));
22+
}
23+
for (let hierarchyChildName of hierarchyChildArray){
24+
if(hierarchyChildName){
25+
return hierarchyChildName
26+
}
27+
}
28+
}
29+
}
1030

1131
switch (action.type) {
1232
case types.MOVE_BACKWARD: {
1333
if (snapshots.length > 0 && sliderIndex > 0) {
1434
const newIndex = sliderIndex - 1;
35+
// gabi and nate :: find the name by the newIndex parsing through the hierarchy to send to background.js the current name in the jump action
36+
const nameFromIndex = findName(newIndex, hierarchy)
1537

1638
port.postMessage({
1739
action: 'jumpToSnap',
1840
payload: snapshots[newIndex],
1941
index: newIndex,
42+
name: nameFromIndex,
2043
tabId: currentTab,
2144
});
2245
clearInterval(intervalId);
@@ -29,10 +52,13 @@ export default (state, action) => produce(state, draft => {
2952
case types.MOVE_FORWARD: {
3053
if (sliderIndex < snapshots.length - 1) {
3154
const newIndex = sliderIndex + 1;
55+
// gabi and nate :: find the name by the newIndex parsing through the hierarchy to send to background.js the current name in the jump action
56+
const nameFromIndex = findName(newIndex, hierarchy)
3257

3358
port.postMessage({
3459
action: 'jumpToSnap',
3560
index: newIndex,
61+
name: nameFromIndex,
3662
payload: snapshots[newIndex],
3763
tabId: currentTab,
3864
});
@@ -48,9 +74,11 @@ export default (state, action) => produce(state, draft => {
4874
break;
4975
}
5076
case types.SLIDER_ZERO: {
77+
// gabi and nate :: reset name to 0 to send to background.js the current name in the jump action
5178
port.postMessage({
5279
action: 'jumpToSnap',
5380
index: 0,
81+
name: 0,
5482
payload: snapshots[0],
5583
tabId: currentTab,
5684
});
@@ -64,10 +92,14 @@ export default (state, action) => produce(state, draft => {
6492
break;
6593
}
6694
case types.CHANGE_SLIDER: {
95+
// gabi and nate :: finds the name by the action.payload, parsing through the hierarchy to send to background.js the current name in the jump action
96+
const nameFromIndex = findName(action.payload, hierarchy)
97+
6798
port.postMessage({
6899
action: 'jumpToSnap',
69100
payload: snapshots[action.payload],
70101
index: action.payload,
102+
name: nameFromIndex,
71103
tabId: currentTab,
72104
});
73105
tabs[currentTab].sliderIndex = action.payload;
@@ -78,13 +110,27 @@ export default (state, action) => produce(state, draft => {
78110
tabs[currentTab].sliderIndex = 0;
79111
tabs[currentTab].viewIndex = -1;
80112
tabs[currentTab].playing = false;
81-
tabs[currentTab].snapshots.splice(1);
82-
// reset children in root node to reset graph
83-
if (tabs[currentTab].hierarchy) tabs[currentTab].hierarchy.children = [];
84-
// 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
85127
tabs[currentTab].currLocation = tabs[currentTab].hierarchy;
86-
// reset index
128+
// gabi :: reset index
87129
tabs[currentTab].index = 0;
130+
// gabi :: reset currParent plus current state
131+
tabs[currentTab].currParent = 1;
132+
// gabi :: reset currBranch
133+
tabs[currentTab].currBranch = 0;
88134
break;
89135
}
90136
case types.SET_PORT: {
@@ -168,7 +214,7 @@ export default (state, action) => produce(state, draft => {
168214
break;
169215
}
170216
case types.SET_TAB: {
171-
console.log('this is action.payload', action.payload)
217+
// console.log('this is SET_TAB action.payload', action.payload)
172218
if (typeof action.payload === 'number') {
173219
draft.currentTab = action.payload;
174220
break;

src/extension/background.js

Lines changed: 48 additions & 22 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
}
@@ -69,13 +74,13 @@ function sendToHierarchy(tabObj, newNode) {
6974
}
7075
}
7176

72-
function changeCurrLocation(tabObj, rootNode, index) {
77+
function changeCurrLocation(tabObj, rootNode, index, name) {
7378
// gabi and nate :: index comes from the app's main reducer to locate the right current location on tabObj
7479
// check if current node has the index wanted
7580
if (rootNode.index === index) {
7681
tabObj.currLocation = rootNode;
7782
// gabi and nate :: index of current location from where the next node will be a child
78-
tabObj.currParent = index;
83+
tabObj.currParent = name;
7984
return;
8085
}
8186
// base case if no children
@@ -85,7 +90,7 @@ function changeCurrLocation(tabObj, rootNode, index) {
8590
}
8691
if (rootNode.children) {
8792
rootNode.children.forEach(child => {
88-
changeCurrLocation(tabObj, child, index);
93+
changeCurrLocation(tabObj, child, index, name);
8994
});
9095
}
9196
}
@@ -133,13 +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
142-
tabsObj[tabId].index = 1;
156+
// gabi :: reset index
157+
tabsObj[tabId].index = 0;
158+
// gabi :: reset currParent plus current state
159+
tabsObj[tabId].currParent = 1;
160+
// gabi :: reset currBranch
161+
tabsObj[tabId].currBranch = 0;
143162
return true;
144163
case 'setLock':
145164
tabsObj[tabId].mode.locked = payload;
@@ -164,7 +183,7 @@ chrome.runtime.onMessage.addListener((request, sender) => {
164183
if (request.type === 'SIGN_CONNECT') return true;
165184
const tabTitle = sender.tab.title;
166185
const tabId = sender.tab.id;
167-
const { action, index } = request;
186+
const { action, index, name } = request;
168187
let isReactTimeTravel = false;
169188

170189
// Filter out tabs that don't have reactime
@@ -181,14 +200,11 @@ chrome.runtime.onMessage.addListener((request, sender) => {
181200
tabsObj[tabId] = createTabObj(tabTitle);
182201
}
183202

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

186205
switch (action) {
187206
case 'jumpToSnap': {
188-
// console.log('this tabsObj[tabId] sent to changeCurrLocation', tabsObj[tabId])
189-
// console.log('this tabsObj[tabId].hierarchy sent to changeCurrLocation', tabsObj[tabId].hierarchy)
190-
// console.log('this index sent to changeCurrLocation', index)
191-
changeCurrLocation(tabsObj[tabId], tabsObj[tabId].hierarchy, index);
207+
changeCurrLocation(tabsObj[tabId], tabsObj[tabId].hierarchy, index, name);
192208
break;
193209
}
194210
// this case causes d3 graph to display 1 instead of 0
@@ -197,15 +213,25 @@ chrome.runtime.onMessage.addListener((request, sender) => {
197213
tabsObj[tabId].mode.paused = false;
198214
// dont remove snapshots if persisting
199215
if (!persist) {
200-
tabsObj[tabId].snapshots.splice(1);
201-
// reset children in root node to reset graph
202-
// if (tabsObj[tabId].hierarchy)
203-
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
204225
tabsObj[tabId].hierarchy.children = [];
205-
// reassigning pointer to the appropriate node to branch off of
206-
tabsObj[tabId].currLocation = tabsObj[tabId].hierarchy;
207-
// reset index
208-
tabsObj[tabId].index = 1;
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;
209235

210236
// send a message to devtools
211237
portsArr.forEach(bg =>

0 commit comments

Comments
 (0)