Skip to content

Commit d2a7e2e

Browse files
Merge branch 'master' into keyCommands
2 parents a268844 + 931670f commit d2a7e2e

File tree

7 files changed

+143
-49
lines changed

7 files changed

+143
-49
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: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,13 @@ function ActionContainer() {
3131
hierarchyArr.push(newObj)
3232
if (obj.children) {
3333
obj.children.forEach((element) => {
34-
displayArray(element);
35-
});
34+
displayArray(element)
35+
})
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
// Edwin: handles keyboard presses, function passes an event and index of each action-component
4243
function handleOnKeyDown(e, i) {
@@ -59,7 +60,7 @@ function ActionContainer() {
5960
dispatch(changeSlider(currIndex));
6061
}
6162
}
62-
63+
6364
actionsArr = hierarchyArr.map((snapshot, index) => {
6465
const selected = index === viewIndex;
6566
return (
@@ -78,7 +79,6 @@ function ActionContainer() {
7879
);
7980
});
8081

81-
8282
return (
8383
<div className="action-container">
8484
<div className="action-component exclude">

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;

0 commit comments

Comments
 (0)