Skip to content

Commit c096a37

Browse files
changeFocusChild functionality added
1 parent d35c51a commit c096a37

File tree

8 files changed

+60
-20
lines changed

8 files changed

+60
-20
lines changed

src/actionTypes/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export const ADD_CHILD = 'ADD_CHILD';
44
export const UPDATE_COMPONENT = 'UPDATE_COMPONENT';
55
export const DELETE_COMPONENT = 'DELETE_COMPONENT';
66
export const CHANGE_FOCUS_COMPONENT = 'CHANGE_FOCUS_COMPONENT';
7+
export const CHANGE_FOCUS_CHILD = 'CHANGE_FOCUS_CHILD';
78
export const UPDATE_CHILDREN = 'UPDATE_CHILDREN';
89
export const REASSIGN_PARENT = 'REASSIGN_PARENT';
910
export const SET_SELECTABLE_PARENTS = 'SET_SELECTABLE_PARENTS';

src/actions/components.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
UPDATE_COMPONENT,
66
DELETE_COMPONENT,
77
CHANGE_FOCUS_COMPONENT,
8+
CHANGE_FOCUS_CHILD,
89
UPDATE_CHILDREN,
910
REASSIGN_PARENT,
1011
SET_SELECTABLE_PARENTS,
@@ -109,6 +110,11 @@ export const changeFocusComponent = ({ title }) => (dispatch) => {
109110
dispatch({ type: CHANGE_FOCUS_COMPONENT, payload: { title } });
110111
};
111112

113+
// make sure childId is being sent in
114+
export const changeFocusChild = ({ title, childId }) => (dispatch) => {
115+
dispatch({ type: CHANGE_FOCUS_CHILD, payload: { title, childId } });
116+
};
117+
112118
// export const exportFiles = ({ components, path }) => (dispatch) => {
113119
// dispatch({
114120
// type: EXPORT_FILES,

src/components/KonvaStage.jsx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,20 @@ class KonvaStage extends Component {
2424
// ADD CHANG FOCUS CHILD FUNCTIONALITY HERE
2525
handleStageMouseDown = (e) => {
2626
// // clicked on stage - cler selection
27-
// if (e.target === e.target.getStage()) {
28-
// this.props.openExpansionPanel({});
29-
// return;
30-
// }
27+
if (e.target === e.target.getStage()) {
28+
// add functionality for allowing no focusChild
29+
return;
30+
}
3131
// // clicked on transformer - do nothing
32-
// const clickedOnTransformer = e.target.getParent().className === 'Transformer';
33-
// if (clickedOnTransformer) {
34-
// return;
35-
// }
32+
const clickedOnTransformer = e.target.getParent().className === 'Transformer';
33+
if (clickedOnTransformer) {
34+
return;
35+
}
3636

3737
// find clicked rect by its name
38-
const id = e.target.name();
39-
console.log(e.target);
40-
const rect = this.props.components.find(r => r.id === id);
41-
38+
const rectChildId = e.target.attrs.childId;
39+
console.log('e.target : ', rectChildId);
40+
this.props.changeFocusChild({ childId: rectChildId });
4241
// if (rect) {
4342
// this.props.openExpansionPanel(rect || this.props.focusComponent);
4443
// } else {
@@ -72,6 +71,7 @@ class KonvaStage extends Component {
7271
scaleY,
7372
focusComponent,
7473
focusChild,
74+
changeFocusChild,
7575
} = this.props;
7676
const { selectedShapeName } = this.state;
7777

src/components/LeftColExpansionPanel.jsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,19 @@ const LeftColExpansionPanel = (props) => {
2525
deleteComponent,
2626
addChild,
2727
changeFocusComponent,
28+
changeFocusChild,
2829
} = props;
2930
const { title, id, color } = component;
3031

3132
function isFocused() {
3233
return focusComponent.title === title ? 'focused' : '';
3334
}
3435

36+
function isAncestor() {
37+
// add logic for determining if given component is an ancestor of focusedComponent
38+
return false;
39+
}
40+
3541
return (
3642
<div className={classes.root}>
3743
<Grid item xs={12} md={6} style={{ color: 'red' }}>
@@ -57,7 +63,7 @@ const LeftColExpansionPanel = (props) => {
5763
style={{ color }}
5864
/>
5965
<ListItemSecondaryAction>
60-
{isFocused() ? (
66+
{isFocused() || isAncestor() ? (
6167
<div />
6268
) : (
6369
<IconButton aria-label="Add">
@@ -66,6 +72,8 @@ const LeftColExpansionPanel = (props) => {
6672
onClick={() => {
6773
console.log(title);
6874
addChild({ title });
75+
// get childId somewhere, or call changeFocusChild within addChild (better idea)
76+
// changeFocusChild({ title });
6977
}}
7078
/>
7179
</IconButton>

src/containers/LeftContainer.jsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const mapDispatchToProps = dispatch => ({
3232
// deleteAllData: () => dispatch(actions.deleteAllData()),
3333
addChild: ({ title }) => dispatch(actions.addChild({ title })),
3434
changeFocusComponent: ({ title }) => dispatch(actions.changeFocusComponent({ title })),
35+
changeFocusChild: ({ title, childId }) => dispatch(actions.changeFocusChild({ title, childId })),
3536
});
3637

3738
class LeftContainer extends Component {
@@ -62,6 +63,7 @@ class LeftContainer extends Component {
6263
classes,
6364
addChild,
6465
changeFocusComponent,
66+
changeFocusChild,
6567
} = this.props;
6668
const { componentName } = this.state;
6769

@@ -75,6 +77,7 @@ class LeftContainer extends Component {
7577
focusComponent={focusComponent}
7678
addChild={addChild}
7779
changeFocusComponent={changeFocusComponent}
80+
changeFocusChild={changeFocusChild}
7881
/>
7982
));
8083

src/containers/MainContainer.jsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ import { connect } from 'react-redux';
77
// import TextField from '@material-ui/core/TextField';
88
import { MuiThemeProvider } from '@material-ui/core/styles';
99
import theme from '../components/theme';
10-
import { toggleDragging, openExpansionPanel, handleTransform } from '../actions/components';
10+
import {
11+
toggleDragging,
12+
openExpansionPanel,
13+
handleTransform,
14+
changeFocusChild,
15+
} from '../actions/components';
1116
import KonvaStage from '../components/KonvaStage.jsx';
1217
// import MainContainerHeader from '../components/MainContainerHeader.jsx';
1318
// import createModal from '../utils/createModal.util';
@@ -28,6 +33,7 @@ const mapDispatchToProps = dispatch => ({
2833
),
2934
toggleComponentDragging: status => dispatch(toggleDragging(status)),
3035
openPanel: component => dispatch(openExpansionPanel(component)),
36+
changeFocusChild: ({ title, childId }) => dispatch(changeFocusChild({ title, childId })),
3137
});
3238

3339
const mapStateToProps = store => ({
@@ -87,6 +93,7 @@ class MainContainer extends Component {
8793
rightColumnOpen,
8894
focusComponent,
8995
focusChild,
96+
changeFocusChild,
9097
} = this.props;
9198
const {
9299
increaseHeight,
@@ -115,6 +122,7 @@ class MainContainer extends Component {
115122
openExpansionPanel={openPanel}
116123
focusComponent={focusComponent}
117124
focusChild={focusChild}
125+
changeFocusChild={changeFocusChild}
118126
/>
119127
) : (
120128
<p>Add some components</p>

src/reducers/componentReducer.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
UPDATE_COMPONENT,
66
DELETE_COMPONENT,
77
CHANGE_FOCUS_COMPONENT,
8+
CHANGE_FOCUS_CHILD,
89
UPDATE_CHILDREN,
910
REASSIGN_PARENT,
1011
SET_SELECTABLE_PARENTS,
@@ -31,6 +32,7 @@ import {
3132
updateComponent,
3233
deleteComponent,
3334
changeFocusComponent,
35+
changeFocusChild,
3436
updateChildren,
3537
reassignParent,
3638
setSelectableP,
@@ -83,7 +85,7 @@ const appComponent = {
8385
childrenArray: [],
8486
nextChildId: 1,
8587
focusChild: null,
86-
}
88+
};
8789

8890
const initialApplicationState = {
8991
totalComponents: 1,
@@ -92,7 +94,7 @@ const initialApplicationState = {
9294
successOpen: false,
9395
errorOpen: false,
9496
focusComponent: appComponent,
95-
focusChild: {
97+
focusChild: {
9698
childId: 0,
9799
componentName: null,
98100
position: {
@@ -129,6 +131,8 @@ const componentReducer = (state = initialApplicationState, action) => {
129131
return deleteComponent(state, action.payload);
130132
case CHANGE_FOCUS_COMPONENT:
131133
return changeFocusComponent(state, action.payload);
134+
case CHANGE_FOCUS_CHILD:
135+
return changeFocusChild(state, action.payload);
132136
case UPDATE_CHILDREN:
133137
return updateChildren(state, action.payload);
134138
case REASSIGN_PARENT:

src/utils/componentReducer.util.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,23 @@ export const deleteComponent = (state, { index, id }) => {
166166
};
167167

168168
export const changeFocusComponent = (state, { title }) => {
169-
const focusComp = state.components.filter((comp) => {
170-
if (comp.title === title) return comp;
171-
})[0];
169+
const newFocusComp = state.components.find(comp => comp.title === title);
170+
return {
171+
...state,
172+
focusComponent: newFocusComp,
173+
};
174+
};
172175

176+
export const changeFocusChild = (state, { title, childId }) => {
177+
// just finds first child with given title, need to pass in specific childId somehow
178+
// maybe default to title if childId is unknown
179+
const focComp = state.components.find(comp => comp.title === state.focusComponent.title);
180+
console.log('erusbdfd', focComp, childId);
181+
const newFocusChild = focComp.childrenArray.find(child => child.childId === childId) || state.focusChild;
182+
console.log('trying to changeFocusChild', state.focusComponent.childrenArray);
173183
return {
174184
...state,
175-
focusComponent: focusComp,
185+
focusChild: newFocusChild,
176186
};
177187
};
178188

0 commit comments

Comments
 (0)