Skip to content

Commit cb026fc

Browse files
Merge pull request #66 from ChristianEdwardPadilla/development
major object interfaces added, small reducer changes, no more string ids
2 parents 6a021bb + 2b1da94 commit cb026fc

File tree

10 files changed

+119
-74
lines changed

10 files changed

+119
-74
lines changed

src/actions/components.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,15 @@ export const deleteChild = ({}) => dispatch => {
7878

7979
export const deleteComponent = ({ componentId, stateComponents }) => dispatch => {
8080
// find all places where the "to be delted" is a child and do what u gotta do
81-
stateComponents.forEach(parent => {
82-
parent.childrenArray
83-
.filter(child => child.childComponentId == componentId)
84-
.forEach(child => {
85-
dispatch({
86-
type: DELETE_CHILD,
87-
payload: {
88-
parentId: parent.id,
89-
childId: child.childId,
90-
calledFromDeleteComponent: true,
91-
},
92-
});
81+
stateComponents.forEach((parent) => {
82+
parent.childrenArray.filter(child => child.childComponentId === componentId).forEach((child) => {
83+
dispatch({
84+
type: DELETE_CHILD,
85+
payload: {
86+
parentId: parent.id,
87+
childId: child.childId,
88+
calledFromDeleteComponent: true,
89+
},
9390
});
9491
});
9592

@@ -135,8 +132,13 @@ export const changeFocusComponent = ({ title }) => dispatch => {
135132
};
136133

137134
// make sure childId is being sent in
135+
<<<<<<< HEAD
138136
export const changeFocusChild = ({ title, childId }) => dispatch => {
139137
dispatch({ type: CHANGE_FOCUS_CHILD, payload: { title, childId } });
138+
=======
139+
export const changeFocusChild = ({ childId }) => (dispatch) => {
140+
dispatch({ type: CHANGE_FOCUS_CHILD, payload: { childId } });
141+
>>>>>>> c532596... reducer cleanup, working version
140142
};
141143

142144
export const changeComponentFocusChild = ({ componentId, childId }) => dispatch => {

src/components/GrandchildRectangle.jsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import React, { Component } from 'react';
22
import { Rect, Group } from 'react-konva';
3+
// import findComponentById from '../utils/findComponentById.ts';
34

45
class GrandchildRectangle extends Component {
56
getComponentColor(componentId) {
6-
const color = this.props.components.find(comp => comp.id == componentId).color;
7+
// const color = findComponentById(componentId, this.props.components).color;
8+
const color = this.props.components.find(comp => comp.id === componentId).color;
79
return color;
810
}
911

@@ -26,7 +28,6 @@ class GrandchildRectangle extends Component {
2628
height,
2729
focusChild,
2830
components,
29-
childType,
3031
} = this.props;
3132

3233
// the Group is responsible for dragging of all children
@@ -54,7 +55,7 @@ class GrandchildRectangle extends Component {
5455
{childType === 'COMP' &&
5556
components
5657
.find(comp => comp.title === childComponentName)
57-
.childrenArray.filter(child => child.childId !== '-1')
58+
.childrenArray.filter(child => child.childId !== -1)
5859
.map((grandchild, i) => (
5960
<GrandchildRectangle
6061
key={i}

src/components/KonvaStage.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ class KonvaStage extends Component {
1919
getDirectChildrenCopy(focusComponent) {
2020
const component = this.props.components.find(comp => comp.id === focusComponent.id);
2121

22-
const childrenArr = component.childrenArray.filter(child => child.childId !== '-1');
22+
const childrenArr = component.childrenArray.filter(child => child.childId !== -1);
2323

2424
let childrenArrCopy = cloneDeep(childrenArr);
2525

2626
const pseudoChild = {
27-
childId: '-1',
27+
childId: -1,
2828
childComponentId: component.id,
2929
componentName: component.title,
3030
position: {
@@ -182,7 +182,7 @@ class KonvaStage extends Component {
182182
childComponentId={child.childComponentId}
183183
childComponentName={child.componentName}
184184
focusChild={focusChild}
185-
childId={child.childId} // '-1' for pseudoChild
185+
childId={child.childId} // -1 for pseudoChild
186186
x={child.position.x}
187187
y={child.position.y}
188188
scaleX={1}

src/components/LeftColExpansionPanel.jsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ const LeftColExpansionPanel = (props) => {
2828

2929
// show a string of all direct parents. SO the user can gaze at it.
3030
const directParents = components
31-
.filter(comp => comp.childrenArray.some(kiddy => kiddy.childComponentId == id))
31+
.filter(comp => comp.childrenArray.some(child => child.childComponentId === id))
3232
.map(comp => comp.title)
3333
.join(',');
3434

3535
function isFocused() {
36-
return focusComponent.id == id ? 'focused' : '';
36+
return focusComponent.id === id ? 'focused' : '';
3737
}
3838

3939
return (
@@ -67,7 +67,7 @@ const LeftColExpansionPanel = (props) => {
6767
</ListItem>
6868
</List>
6969
</Grid>
70-
{id == 1 || !isFocused() ? (
70+
{id === 1 || !isFocused() ? (
7171
<div />
7272
) : (
7373
<Fragment>
@@ -134,7 +134,7 @@ const LeftColExpansionPanel = (props) => {
134134
</Grid>
135135

136136
<Grid item xs={3}>
137-
{id == 1 || isFocused() || !selectableChildren.includes(id) ? (
137+
{id === 1 || isFocused() || !selectableChildren.includes(id) ? (
138138
<div />
139139
) : (
140140
<IconButton aria-label="Add">

src/components/Rectangle.tsx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class Rectangle extends Component {
88
if (componentId === '888') {
99
return '#000000';
1010
}
11-
const color = this.props.components.find(comp => comp.id == componentId).color;
11+
const color = this.props.components.find(comp => comp.id === componentId).color;
1212
return color;
1313
}
1414

@@ -23,7 +23,7 @@ class Rectangle extends Component {
2323
.find(comp => comp.id === this.props.componentId)
2424
.childrenArray.find(child => child.childId === childId);
2525

26-
if (childId == '-1') {
26+
if (childId === -1) {
2727
focChild = this.props.components.find(comp => comp.id === this.props.componentId);
2828
}
2929
const transformation = {
@@ -110,8 +110,8 @@ class Rectangle extends Component {
110110
strokeWidth={4}
111111
strokeScaleEnabled={false}
112112
draggable={false}
113-
fill={childId === '-1' ? 'white' : null}
114-
shadowBlur={childId === '-1' ? 6 : null}
113+
fill={childId === -1 ? 'white' : null}
114+
shadowBlur={childId === -1 ? 6 : null}
115115
// dashEnabled={childId === "-1"} // dash line only enabled for pseudochild
116116
// dash={[10, 3]} // 10px dashes with 3px gaps
117117
/>
@@ -120,19 +120,19 @@ class Rectangle extends Component {
120120
fontStyle={'bold'}
121121
fontVariant={'small-caps'}
122122
// pseudochild's label should look different than normal children:
123-
text={childId === '-1' ? title.slice(0, title.length - 2) : title}
124-
fill={childId === '-1' ? this.getComponentColor(childComponentId) : '#000000'}
125-
fontSize={childId === '-1' ? 15 : 10}
123+
text={childId === -1 ? title.slice(0, title.length - 2) : title}
124+
fill={childId === -1 ? this.getComponentColor(childComponentId) : '#000000'}
125+
fontSize={childId === -1 ? 15 : 10}
126126
x={4}
127-
y={childId === '-1' ? -20 : -12}
127+
y={childId === -1 ? -20 : -12}
128128
/>
129129
</Label>
130130
{// for all children other than the pseudoChild, find their component's children array and recursively render the children found there
131-
childId !== '-1' &&
132-
childType == 'COMP' &&
131+
childId !== -1 &&
132+
childType === 'COMP' &&
133133
components
134134
.find(comp => comp.title === childComponentName)
135-
.childrenArray.filter(child => child.childId !== '-1')
135+
.childrenArray.filter(child => child.childId !== -1)
136136
// .sort((a, b) => parseInt(a.childId) - parseInt(b.childId)) // using i within map below, sorting by childId might be necessary
137137
.map((grandchild, i) => (
138138
<GrandchildRectangle

src/containers/LeftContainer.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const mapDispatchToProps = dispatch => ({
2525
),
2626
addChild: ({ title, childType, HTMLInfo }) => dispatch(actions.addChild({ title, childType, HTMLInfo })),
2727
changeFocusComponent: ({ title }) => dispatch(actions.changeFocusComponent({ title })),
28-
changeFocusChild: ({ title, childId }) => dispatch(actions.changeFocusChild({ title, childId })),
28+
changeFocusChild: ({ childId }) => dispatch(actions.changeFocusChild({ childId })),
2929
deleteComponent: ({ componentId, stateComponents }) =>
3030
dispatch(actions.deleteComponent({ componentId, stateComponents })),
3131
});

src/containers/MainContainer.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const mapDispatchToProps = dispatch => ({
3434
}),
3535
),
3636
openPanel: component => dispatch(openExpansionPanel(component)),
37-
changeFocusChild: ({ title, childId }) => dispatch(changeFocusChild({ title, childId })),
37+
changeFocusChild: ({ childId }) => dispatch(changeFocusChild({ childId })),
3838
changeComponentFocusChild: ({ componentId, childId }) =>
3939
dispatch(changeComponentFocusChild({ componentId, childId })),
4040
deleteChild: ({}) => dispatch(deleteChild({})), // if u send no prms, function will delete focus child.
@@ -205,7 +205,7 @@ class MainContainer extends Component {
205205
const directParents = !focusComponent.id
206206
? 'Waiting for a focused component'
207207
: stateComponents
208-
.filter(comp => comp.childrenArray.some(kiddy => kiddy.childComponentId == focusComponent.id))
208+
.filter(comp => comp.childrenArray.some(kiddy => kiddy.childComponentId === focusComponent.id))
209209
.map(comp => comp.title)
210210
.join(',');
211211

src/reducers/componentReducer.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,14 @@ interface Component {
7171
}
7272

7373
const appComponent = {
74-
id: '1',
74+
id: 1,
7575
stateful: false,
7676
title: 'App',
7777
parentIds: [],
7878
color: '#FF6D00',
7979
draggable: true,
8080
childrenIds: [],
8181
selectableParents: [],
82-
expanded: true,
8382
props: [],
8483
nextPropId: 1,
8584
position: {

0 commit comments

Comments
 (0)