Skip to content

Commit a268844

Browse files
added key command functionality on each action component; able to press arrows to scroll up/down and can jump to a state with the enter key
1 parent abc698a commit a268844

File tree

2 files changed

+70
-57
lines changed

2 files changed

+70
-57
lines changed

src/app/components/Action.jsx

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +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

11-
// function arrowKeys(event, indexx) {
12-
// if (event.keyCode === 40) {
13-
// indexx += 1;
14-
// console.log('down was pushed; index : ', indexx);
15-
// dispatch(changeView(indexx));
16-
// } else if (event.keyCode === 38) {
17-
18-
// console.log('up was pushed indexx, : ', indexx);
19-
// dispatch(changeView(indexx));
20-
// }
21-
// }
22-
2312
return (
2413
<div
14+
// Edwin: invoking keyboard functionality; functionality is in ActionContainer;
15+
onKeyDown={e => handleOnkeyDown(e, viewIndex)}
2516
className={selected ? 'action-component selected' : 'action-component'}
26-
onClick={() => dispatch(changeView(index))}
17+
onClick={() => {
18+
dispatch(changeView(index));
19+
}}
2720
role="presentation"
2821
style={index > sliderIndex ? { color: '#5f6369' } : {}}
29-
onKeyDown={e => {
30-
if (e.keyCode === 13) {
31-
e.stopPropagation();
32-
dispatch(changeView(index));
33-
dispatch(changeSlider(index));
34-
}
35-
}}
3622
tabIndex={index}
3723
>
3824
<div className="action-component-text">
39-
{`${displayName}: ${componentName} `}
25+
{`${displayName}: ${componentName} `}
4026
</div>
4127
<button
4228
className="jump-button"
@@ -61,7 +47,9 @@ Action.propTypes = {
6147
dispatch: PropTypes.func.isRequired,
6248
displayName: PropTypes.string.isRequired,
6349
componentName: PropTypes.string.isRequired,
64-
state: PropTypes.object.isRequired
50+
state: PropTypes.object.isRequired,
51+
handleOnkeyDown: PropTypes.func.isRequired,
52+
viewIndex: PropTypes.number.isRequired,
6553
};
6654

6755
export default Action;

src/app/containers/ActionContainer.jsx

Lines changed: 59 additions & 34 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,39 +20,64 @@ 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-
}
37-
}
38-
displayArray(hierarchy)
39-
console.log('this is hierarchyArr', hierarchyArr)
40-
41-
actionsArr = hierarchyArr.map((snapshot, index) => {
42-
const selected = index === viewIndex;
43-
return (
44-
<Action
45-
key={`action${index}`}
46-
index={index}
47-
state={snapshot.state}
48-
displayName={snapshot.displayName}
49-
componentName={snapshot.componentName}
50-
selected={selected}
51-
dispatch={dispatch}
52-
sliderIndex={sliderIndex}
53-
/>
54-
);
55-
});
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+
}
37+
}
38+
displayArray(hierarchy)
39+
console.log('this is hierarchyArr', hierarchyArr)
40+
41+
// Edwin: handles keyboard presses, function passes an event and index of each action-component
42+
function handleOnKeyDown(e, i) {
43+
let currIndex = i;
44+
// up array key pressed
45+
if (e.keyCode === 38) {
46+
currIndex -= 1;
47+
if (currIndex < 0) return;
48+
dispatch(changeView(currIndex));
49+
}
50+
// down arrow key pressed
51+
else if (e.keyCode === 40) {
52+
currIndex += 1;
53+
if (currIndex > hierarchyArr.length - 1) return;
54+
dispatch(changeView(currIndex));
55+
}
56+
// enter key pressed
57+
else if (e.keyCode === 13) {
58+
e.stopPropagation();
59+
dispatch(changeSlider(currIndex));
60+
}
61+
}
62+
63+
actionsArr = hierarchyArr.map((snapshot, index) => {
64+
const selected = index === viewIndex;
65+
return (
66+
<Action
67+
key={`action${index}`}
68+
index={index}
69+
state={snapshot.state}
70+
displayName={snapshot.displayName}
71+
componentName={snapshot.componentName}
72+
selected={selected}
73+
dispatch={dispatch}
74+
sliderIndex={sliderIndex}
75+
handleOnkeyDown={handleOnKeyDown}
76+
viewIndex={viewIndex}
77+
/>
78+
);
79+
});
80+
5681

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

0 commit comments

Comments
 (0)