Skip to content

Commit 732efed

Browse files
component and children ids are all numbers now
1 parent 82f839d commit 732efed

File tree

6 files changed

+31
-22
lines changed

6 files changed

+31
-22
lines changed

src/components/GrandchildRectangle.jsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ class GrandchildRectangle extends Component {
2626
height,
2727
focusChild,
2828
components,
29-
childType,
3029
} = this.props;
3130

3231
// the Group is responsible for dragging of all children
@@ -54,7 +53,7 @@ class GrandchildRectangle extends Component {
5453
{childType === 'COMP' &&
5554
components
5655
.find(comp => comp.title === childComponentName)
57-
.childrenArray.filter(child => child.childId !== '-1')
56+
.childrenArray.filter(child => child.childId !== -1)
5857
.map((grandchild, i) => (
5958
<GrandchildRectangle
6059
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/Rectangle.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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' &&
131+
childId !== -1 &&
132132
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/reducers/componentReducer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ interface Component {
7171
}
7272

7373
const appComponent = {
74-
id: '1',
74+
id: 1,
7575
stateful: false,
7676
title: 'App',
7777
parentIds: [],

src/utils/componentReducer.util.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export const addComponent = (state, { title }) => {
4949
}
5050

5151
const componentColor = getColor();
52-
const componentId = state.nextId.toString();
52+
const componentId = state.nextId;
5353

5454
const newComponent = {
5555
...initialComponentState,
@@ -76,7 +76,7 @@ export const addComponent = (state, { title }) => {
7676
focusComponent: newComponent,
7777
focusChild: newFocusChild,
7878
ancestors: [],
79-
selectableChildren, // new component so you everyone except yourself is available
79+
selectableChildren, // new component so everyone except yourself is available
8080
};
8181
};
8282

@@ -137,7 +137,7 @@ export const addChild = (state, { title, childType = '', HTMLInfo = {} }) => {
137137
};
138138

139139
const newChild = {
140-
childId: view.nextChildId.toString(),
140+
childId: view.nextChildId,
141141
childType,
142142
childComponentId: childType == 'COMP' ? parentComponent.id : null, // only relevant fot children of type COMPONENT
143143
componentName: strippedTitle,
@@ -193,7 +193,7 @@ export const deleteChild = (
193193
window.alert('No child selected');
194194
return state;
195195
}
196-
if (!calledFromDeleteComponent && childId === '-1') {
196+
if (!calledFromDeleteComponent && childId === -1) {
197197
window.alert('Cannot delete root child of a component');
198198
return state;
199199
}
@@ -227,7 +227,7 @@ export const deleteChild = (
227227
};
228228

229229
export const handleTransform = (state, { componentId, childId, x, y, width, height }) => {
230-
if (childId === '-1') {
230+
if (childId === -1) {
231231
// the pseudochild has been transformed, its position is stored in the component
232232
const component = state.components.find(comp => comp.id === componentId);
233233
const transformedComponent = {
@@ -396,7 +396,7 @@ export const changeFocusChild = (state, { title, childId }) => {
396396

397397
if (!newFocusChild) {
398398
newFocusChild = {
399-
childId: '-1',
399+
childId: -1,
400400
childComponentId: focComp.id,
401401
componentName: focComp.title,
402402
position: {
@@ -587,7 +587,7 @@ export const addProp = (state, { key, value = null, required, type }) => {
587587
const selectedComponent = state.components.find(comp => comp.id == state.focusComponent.id);
588588

589589
const newProp = {
590-
id: selectedComponent.nextPropId.toString(),
590+
id: selectedComponent.nextPropId,
591591
key,
592592
value: value || key,
593593
required,

src/utils/findComponentById.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
interface component{
3+
id: string;
4+
}
5+
6+
function findComponentById(id: number, components: ){
7+
8+
}
9+
10+
export default findComponentById

0 commit comments

Comments
 (0)