Skip to content

Commit 87f621c

Browse files
committed
Merge branch 'master' into chart
2 parents 25eb195 + 3ff6a8a commit 87f621c

File tree

2 files changed

+70
-37
lines changed

2 files changed

+70
-37
lines changed

src/app/components/Action.jsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,26 @@ import PropTypes from 'prop-types';
33
import { changeView, changeSlider } from '../actions/actions';
44

55
/* // gabi and nate :: index and delta props were removed from Action.jsx */
6+
// viewIndex and handleonkeyDown added to props
67
const Action = props => {
78
const {
8-
selected, index, sliderIndex, dispatch, displayName, componentName, state
9+
selected, index, sliderIndex, dispatch, displayName, componentName, state, viewIndex, handleOnkeyDown,
910
} = props;
1011

1112
return (
1213
<div
14+
// Edwin: invoking keyboard functionality; functionality is in ActionContainer;
15+
onKeyDown={e => handleOnkeyDown(e, viewIndex)}
1316
className={selected ? 'action-component selected' : 'action-component'}
14-
onClick={() => dispatch(changeView(index))}
17+
onClick={() => {
18+
dispatch(changeView(index));
19+
}}
1520
role="presentation"
1621
style={index > sliderIndex ? { color: '#5f6369' } : {}}
22+
tabIndex={index}
1723
>
1824
<div className="action-component-text">
19-
{`${displayName}: ${componentName} `}
25+
{`${displayName}: ${componentName} `}
2026
</div>
2127
<button
2228
className="jump-button"
@@ -41,7 +47,9 @@ Action.propTypes = {
4147
dispatch: PropTypes.func.isRequired,
4248
displayName: PropTypes.string.isRequired,
4349
componentName: PropTypes.string.isRequired,
44-
state: PropTypes.object.isRequired
50+
state: PropTypes.object.isRequired,
51+
handleOnkeyDown: PropTypes.func.isRequired,
52+
viewIndex: PropTypes.number.isRequired,
4553
};
4654

4755
export default Action;

src/app/containers/ActionContainer.jsx

Lines changed: 58 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import React from 'react';
44
import { diff } from 'jsondiffpatch';
55
import Action from '../components/Action';
66

7-
import { emptySnapshots } from '../actions/actions';
7+
import { emptySnapshots, changeView, changeSlider } from '../actions/actions';
88
import { useStoreContext } from '../store';
99

1010
const resetSlider = () => {
@@ -20,40 +20,65 @@ function ActionContainer() {
2020
let actionsArr = [];
2121
let hierarchyArr = [];
2222

23-
// gabi and nate :: delete function to traverse state from snapshots, now we are tranversing state from hiararchy and alsog getting infromation on display name and component name
24-
const displayArray = (obj) => {
25-
const newObj = {
26-
index: obj.index,
27-
displayName : `${obj.name}.${obj.branch}`,
28-
state: obj.stateSnapshot.children[0].state,
29-
componentName: obj.stateSnapshot.children[0].name,
30-
}
31-
hierarchyArr.push(newObj)
32-
if(obj.children){
33-
obj.children.forEach((element) => {
34-
displayArray(element)
35-
})
36-
}
23+
// gabi and nate :: delete function to traverse state from snapshots, now we are tranversing state from hiararchy and alsog getting infromation on display name and component name
24+
const displayArray = (obj) => {
25+
const newObj = {
26+
index: obj.index,
27+
displayName: `${obj.name}.${obj.branch}`,
28+
state: obj.stateSnapshot.children[0].state,
29+
componentName: obj.stateSnapshot.children[0].name,
3730
}
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 initialize involk displayArray to display the hierarchy
39-
if (hierarchy) displayArray(hierarchy)
40-
// console.log('this is hierarchyArr', hierarchyArr)
31+
32+
hierarchyArr.push(newObj)
33+
if (obj.children) {
34+
obj.children.forEach((element) => {
35+
displayArray(element)
36+
})
37+
}
38+
}
39+
// 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
40+
if (hierarchy) displayArray(hierarchy)
41+
// console.log('this is hierarchyArr', hierarchyArr)
42+
43+
// Edwin: handles keyboard presses, function passes an event and index of each action-component
44+
function handleOnKeyDown(e, i) {
45+
let currIndex = i;
46+
// up array key pressed
47+
if (e.keyCode === 38) {
48+
currIndex -= 1;
49+
if (currIndex < 0) return;
50+
dispatch(changeView(currIndex));
51+
}
52+
// down arrow key pressed
53+
else if (e.keyCode === 40) {
54+
currIndex += 1;
55+
if (currIndex > hierarchyArr.length - 1) return;
56+
dispatch(changeView(currIndex));
57+
}
58+
// enter key pressed
59+
else if (e.keyCode === 13) {
60+
e.stopPropagation();
61+
dispatch(changeSlider(currIndex));
62+
}
63+
}
4164

42-
actionsArr = hierarchyArr.map((snapshot, index) => {
43-
const selected = index === viewIndex;
44-
return (
45-
<Action
46-
key={`action${index}`}
47-
index={index}
48-
state={snapshot.state}
49-
displayName={snapshot.displayName}
50-
componentName={snapshot.componentName}
51-
selected={selected}
52-
dispatch={dispatch}
53-
sliderIndex={sliderIndex}
54-
/>
55-
);
56-
});
65+
actionsArr = hierarchyArr.map((snapshot, index) => {
66+
const selected = index === viewIndex;
67+
return (
68+
<Action
69+
key={`action${index}`}
70+
index={index}
71+
state={snapshot.state}
72+
displayName={snapshot.displayName}
73+
componentName={snapshot.componentName}
74+
selected={selected}
75+
dispatch={dispatch}
76+
sliderIndex={sliderIndex}
77+
handleOnkeyDown={handleOnKeyDown}
78+
viewIndex={viewIndex}
79+
/>
80+
);
81+
});
5782

5883
return (
5984
<div className="action-container">

0 commit comments

Comments
 (0)