Skip to content

Commit 8ec50b7

Browse files
authored
Merge pull request #10 from aquinojardim/chart
add branch notation to actions display
2 parents b092a42 + 75c0a13 commit 8ec50b7

File tree

3 files changed

+34
-56
lines changed

3 files changed

+34
-56
lines changed

src/app/components/Action.jsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ import React from 'react';
22
import PropTypes from 'prop-types';
33
import { changeView, changeSlider } from '../actions/actions';
44

5+
/* // gabi and nate :: index and delta props were removed from Action.jsx */
56
const Action = props => {
67
const {
7-
selected, index, delta, sliderIndex, dispatch,
8+
selected, index, sliderIndex, dispatch, displayName, componentName, state
89
} = props;
910

1011
return (
@@ -15,9 +16,7 @@ const Action = props => {
1516
style={index > sliderIndex ? { color: '#5f6369' } : {}}
1617
>
1718
<div className="action-component-text">
18-
{`${index
19-
}: ${delta}`}
20-
19+
{`${displayName}: ${componentName} `}
2120
</div>
2221
<button
2322
className="jump-button"
@@ -34,13 +33,15 @@ const Action = props => {
3433
</div>
3534
);
3635
};
37-
36+
// gabi and nate :: added displayName, componentName and State props to propTypes
3837
Action.propTypes = {
3938
sliderIndex: PropTypes.number.isRequired,
4039
selected: PropTypes.bool.isRequired,
4140
index: PropTypes.number.isRequired,
4241
dispatch: PropTypes.func.isRequired,
43-
delta: PropTypes.string.isRequired,
42+
displayName: PropTypes.string.isRequired,
43+
componentName: PropTypes.string.isRequired,
44+
state: PropTypes.object.isRequired
4445
};
4546

4647
export default Action;

src/app/containers/ActionContainer.jsx

Lines changed: 25 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -14,69 +14,46 @@ const resetSlider = () => {
1414

1515
function ActionContainer() {
1616
const [{ tabs, currentTab }, dispatch] = useStoreContext();
17-
const { hierarchy, snapshots, sliderIndex, viewIndex } = tabs[currentTab];
17+
const { hierarchy, sliderIndex, viewIndex } = tabs[currentTab];
1818
console.log('actionContainer tabs[currentTab];', tabs[currentTab])
19-
console.log('actionContainer snapshots;', snapshots)
2019

2120
let actionsArr = [];
22-
// build actions array
23-
if (snapshots.length > 0) {
24-
// breadth first function - take in an delta obj
25-
function breadthFirst(delta) {
26-
if (delta === undefined) return '';
27-
// aux array = current and one called next
28-
let current = Object.values(delta.children); // Object.keys(delta.children);
29-
let next = [];
30-
let result = '';
31-
// return a string
32-
while (current.length > 0) {
33-
const shifted = current.shift();
34-
if (shifted.state) {
35-
// eslint-disable-next-line no-loop-func
36-
Object.keys(shifted.state).forEach(key => {
37-
result = result.concat(key, ', ');
38-
});
39-
}
40-
if (shifted.children) {
41-
// eslint-disable-next-line no-loop-func
42-
Object.keys(shifted.children).forEach(el => {
43-
next.push(shifted.children[el]);
44-
});
45-
}
46-
if (current.length === 0) {
47-
current = next;
48-
next = [];
49-
}
50-
}
51-
return result;
52-
}
21+
let hierarchyArr = [];
5322

54-
function truncate(newDiff, num = 15) {
55-
if (newDiff.length <= num) return newDiff.replace(',', '');
56-
const thisdiff = newDiff.slice(0, num);
57-
return thisdiff.concat('...');
58-
}
59-
actionsArr = snapshots.map((snapshot, index) => {
60-
const selected = index === viewIndex;
61-
let newDiff = '';
62-
// if index is greater than 0
63-
if (index > 0) {
64-
// calculate the diff
65-
const delta = diff(snapshots[index - 1], snapshot);
66-
newDiff = truncate(breadthFirst(delta));
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+
})
6736
}
37+
}
38+
displayArray(hierarchy)
39+
console.log('this is hierarchyArr', hierarchyArr)
40+
41+
actionsArr = hierarchyArr.map((snapshot, index) => {
42+
const selected = index === viewIndex;
6843
return (
6944
<Action
7045
key={`action${index}`}
7146
index={index}
47+
state={snapshot.state}
48+
displayName={snapshot.displayName}
49+
componentName={snapshot.componentName}
7250
selected={selected}
7351
dispatch={dispatch}
7452
sliderIndex={sliderIndex}
75-
delta={newDiff}
7653
/>
7754
);
7855
});
79-
}
56+
8057
return (
8158
<div className="action-container">
8259
<div className="action-component exclude">

src/extension/background.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ function sendToHierarchy(tabObj, newNode) {
6262
if(tabObj.currLocation.children.length > 1){
6363
// gabi and nate :: increment the value of the nodes branch by 1
6464
newNode.branch+=1
65-
// gabi and nate :: reassign value of current branch to be the length of the children array less one
66-
tabObj.currBranch = tabObj.currLocation.children.length-1;
65+
// gabi and nate :: reassign value of current branch the newNode branch value
66+
tabObj.currBranch = newNode.branch;
6767
}
6868
tabObj.currLocation = newNode;
6969
}

0 commit comments

Comments
 (0)