Skip to content

Commit ac61fc2

Browse files
added changeComponentFocusChild to reducers
1 parent 4621bd3 commit ac61fc2

File tree

7 files changed

+58
-28
lines changed

7 files changed

+58
-28
lines changed

src/actionTypes/index.js

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
1-
export const LOAD_INIT_DATA = "LOAD_INIT_DATA";
2-
export const ADD_COMPONENT = "ADD_COMPONENT";
3-
export const ADD_CHILD = "ADD_CHILD";
4-
export const DELETE_CHILD = "DELETE_CHILD";
5-
export const UPDATE_COMPONENT = "UPDATE_COMPONENT";
6-
export const DELETE_COMPONENT = "DELETE_COMPONENT";
7-
export const CHANGE_FOCUS_COMPONENT = "CHANGE_FOCUS_COMPONENT";
8-
export const CHANGE_FOCUS_CHILD = "CHANGE_FOCUS_CHILD";
9-
export const UPDATE_CHILDREN = "UPDATE_CHILDREN";
10-
export const REASSIGN_PARENT = "REASSIGN_PARENT";
11-
export const SET_SELECTABLE_PARENTS = "SET_SELECTABLE_PARENTS";
12-
export const EXPORT_FILES = "EXPORT_FILES";
13-
export const EXPORT_FILES_SUCCESS = "EXPORT_FILES_SUCCESS";
14-
export const EXPORT_FILES_ERROR = "EXPORT_FILES_ERROR";
15-
export const HANDLE_CLOSE = "HANDLE_CLOSE";
16-
export const HANDLE_TRANSFORM = "HANDLE_TRANSFORM";
17-
export const CREATE_APPLICATION = "CREATE_APPLICATION";
18-
export const CREATE_APPLICATION_SUCCESS = "CREATE_APPLICATION_SUCCESS";
19-
export const CREATE_APPLICATION_ERROR = "CREATE_APPLICATION_ERROR";
20-
export const TOGGLE_DRAGGING = "TOGGLE_DRAGGING";
21-
export const MOVE_TO_BOTTOM = "MOVE_TO_BOTTOM";
22-
export const MOVE_TO_TOP = "MOVE_TO_TOP";
23-
export const OPEN_EXPANSION_PANEL = "OPEN_EXPANSION_PANEL";
24-
export const DELETE_PROP = "DELETE_PROP";
25-
export const ADD_PROP = "ADD_PROP";
26-
export const DELETE_ALL_DATA = "DELETE_ALL_DATA";
27-
export const CHANGE_IMAGE_PATH = "CHANGE_IMAGE_PATH";
1+
export const LOAD_INIT_DATA = 'LOAD_INIT_DATA';
2+
export const ADD_COMPONENT = 'ADD_COMPONENT';
3+
export const ADD_CHILD = 'ADD_CHILD';
4+
export const DELETE_CHILD = 'DELETE_CHILD';
5+
export const UPDATE_COMPONENT = 'UPDATE_COMPONENT';
6+
export const DELETE_COMPONENT = 'DELETE_COMPONENT';
7+
export const CHANGE_FOCUS_COMPONENT = 'CHANGE_FOCUS_COMPONENT';
8+
export const CHANGE_COMPONENT_FOCUS_CHILD = 'CHANGE_COMPONENT_FOCUS_CHILD';
9+
export const CHANGE_FOCUS_CHILD = 'CHANGE_FOCUS_CHILD';
10+
export const UPDATE_CHILDREN = 'UPDATE_CHILDREN';
11+
export const REASSIGN_PARENT = 'REASSIGN_PARENT';
12+
export const SET_SELECTABLE_PARENTS = 'SET_SELECTABLE_PARENTS';
13+
export const EXPORT_FILES = 'EXPORT_FILES';
14+
export const EXPORT_FILES_SUCCESS = 'EXPORT_FILES_SUCCESS';
15+
export const EXPORT_FILES_ERROR = 'EXPORT_FILES_ERROR';
16+
export const HANDLE_CLOSE = 'HANDLE_CLOSE';
17+
export const HANDLE_TRANSFORM = 'HANDLE_TRANSFORM';
18+
export const CREATE_APPLICATION = 'CREATE_APPLICATION';
19+
export const CREATE_APPLICATION_SUCCESS = 'CREATE_APPLICATION_SUCCESS';
20+
export const CREATE_APPLICATION_ERROR = 'CREATE_APPLICATION_ERROR';
21+
export const TOGGLE_DRAGGING = 'TOGGLE_DRAGGING';
22+
export const MOVE_TO_BOTTOM = 'MOVE_TO_BOTTOM';
23+
export const MOVE_TO_TOP = 'MOVE_TO_TOP';
24+
export const OPEN_EXPANSION_PANEL = 'OPEN_EXPANSION_PANEL';
25+
export const DELETE_PROP = 'DELETE_PROP';
26+
export const ADD_PROP = 'ADD_PROP';
27+
export const DELETE_ALL_DATA = 'DELETE_ALL_DATA';
28+
export const CHANGE_IMAGE_PATH = 'CHANGE_IMAGE_PATH';

src/actions/components.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
DELETE_COMPONENT,
88
CHANGE_FOCUS_COMPONENT,
99
CHANGE_FOCUS_CHILD,
10+
CHANGE_COMPONENT_FOCUS_CHILD,
1011
UPDATE_CHILDREN,
1112
REASSIGN_PARENT,
1213
SET_SELECTABLE_PARENTS,
@@ -133,6 +134,10 @@ export const changeFocusChild = ({ title, childId }) => (dispatch) => {
133134
dispatch({ type: CHANGE_FOCUS_CHILD, payload: { title, childId } });
134135
};
135136

137+
export const changeComponentFocusChild = ({ componentId, childId }) => (dispatch) => {
138+
dispatch({ type: CHANGE_COMPONENT_FOCUS_CHILD, payload: { componentId, childId } });
139+
};
140+
136141
// export const exportFiles = ({ components, path }) => (dispatch) => {
137142
// dispatch({
138143
// type: EXPORT_FILES,

src/components/KonvaStage.jsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ class KonvaStage extends Component {
5959
const rectChildId = e.target.attrs.childId;
6060
console.log('e.target : ', rectChildId);
6161
this.props.changeFocusChild({ childId: rectChildId });
62+
this.props.changeComponentFocusChild({
63+
componentId: this.props.focusComponent.id,
64+
childId: rectChildId,
65+
});
6266
// put individual component's focus child logic here
6367
};
6468

@@ -73,6 +77,7 @@ class KonvaStage extends Component {
7377
focusComponent,
7478
focusChild,
7579
changeFocusChild,
80+
changeComponentFocusChild,
7681
} = this.props;
7782
const { selectedShapeName } = this.state;
7883

src/components/Rectangle.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class Rectangle extends Component {
117117
color={grandchild.color}
118118
/>
119119
))}
120-
{focusChild.childId === childId && draggable ? (
120+
{focusChild && focusChild.childId === childId && draggable ? (
121121
<TransformerComponent focusChild={focusChild} />
122122
) : (
123123
<Label />

src/containers/MainContainer.jsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
openExpansionPanel,
1313
handleTransform,
1414
changeFocusChild,
15+
changeComponentFocusChild,
1516
deleteChild,
1617
deleteComponent,
1718
} from '../actions/components';
@@ -36,6 +37,7 @@ const mapDispatchToProps = dispatch => ({
3637
toggleComponentDragging: status => dispatch(toggleDragging(status)),
3738
openPanel: component => dispatch(openExpansionPanel(component)),
3839
changeFocusChild: ({ title, childId }) => dispatch(changeFocusChild({ title, childId })),
40+
changeComponentFocusChild: ({ componentId, childId }) => dispatch(changeComponentFocusChild({ componentId, childId })),
3941
deleteChild: ({}) => dispatch(deleteChild({})), // if u send no prms, function will delete focus child.
4042
deleteComponent: ({ componentId, stateComponents }) => dispatch(deleteComponent({ componentId, stateComponents })),
4143
});
@@ -85,6 +87,7 @@ class MainContainer extends Component {
8587
focusComponent,
8688
focusChild,
8789
changeFocusChild,
90+
changeComponentFocusChild,
8891
deleteChild,
8992
deleteComponent,
9093
stateComponents,
@@ -124,6 +127,7 @@ class MainContainer extends Component {
124127
focusComponent={focusComponent}
125128
focusChild={focusChild}
126129
changeFocusChild={changeFocusChild}
130+
changeComponentFocusChild={changeComponentFocusChild}
127131
deleteChild={deleteChild}
128132
/>
129133
</div>

src/reducers/componentReducer.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
DELETE_COMPONENT,
88
CHANGE_FOCUS_COMPONENT,
99
CHANGE_FOCUS_CHILD,
10+
CHANGE_COMPONENT_FOCUS_CHILD,
1011
UPDATE_CHILDREN,
1112
REASSIGN_PARENT,
1213
SET_SELECTABLE_PARENTS,
@@ -34,6 +35,7 @@ import {
3435
updateComponent,
3536
deleteComponent,
3637
changeFocusComponent,
38+
changeComponentFocusChild,
3739
changeFocusChild,
3840
updateChildren,
3941
reassignParent,
@@ -139,6 +141,8 @@ const componentReducer = (state = initialApplicationState, action) => {
139141
return changeFocusComponent(state, action.payload);
140142
case CHANGE_FOCUS_CHILD:
141143
return changeFocusChild(state, action.payload);
144+
case CHANGE_COMPONENT_FOCUS_CHILD:
145+
return changeComponentFocusChild(state, action.payload);
142146
case UPDATE_CHILDREN:
143147
return updateChildren(state, action.payload);
144148
case REASSIGN_PARENT:

src/utils/componentReducer.util.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ export const addChild = (state, { title }) => {
100100
const component = {
101101
...view,
102102
childrenArray: compsChildrenArr,
103+
focusChildId: newChild.childId,
103104
nextChildId: view.nextChildId + 1,
104105
};
105106

@@ -306,6 +307,16 @@ export const changeFocusChild = (state, { title, childId }) => {
306307
};
307308
};
308309

310+
export const changeComponentFocusChild = (state, { componentId, childId }) => {
311+
const component = state.components.find(comp => comp.id == componentId);
312+
component.focusChildId = childId;
313+
const components = state.components.filter(comp => comp.id != componentId);
314+
return {
315+
...state,
316+
components: [component, ...components],
317+
};
318+
};
319+
309320
// Add or remove children
310321
export const updateChildren = (state, { parentIds, childId }) => {
311322
const components = state.components.map((component) => {

0 commit comments

Comments
 (0)