Skip to content

Commit 27b00f7

Browse files
component and children ids are all numbers now
1 parent a77fb51 commit 27b00f7

File tree

7 files changed

+69
-72
lines changed

7 files changed

+69
-72
lines changed

src/components/DataTable.jsx

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
import React from "react";
1+
import React from 'react';
22
// import PropTypes from 'prop-types';
3-
import { withStyles } from "@material-ui/core/styles";
4-
import Table from "@material-ui/core/Table";
5-
import TableBody from "@material-ui/core/TableBody";
6-
import TableCell from "@material-ui/core/TableCell";
7-
import TableHead from "@material-ui/core/TableHead";
8-
import TableRow from "@material-ui/core/TableRow";
9-
import Paper from "@material-ui/core/Paper";
10-
import Button from "@material-ui/core/Button";
11-
import DeleteIcon from "@material-ui/icons/Delete";
12-
import { IconButton } from "@material-ui/core";
3+
import { withStyles } from '@material-ui/core/styles';
4+
import Table from '@material-ui/core/Table';
5+
import TableBody from '@material-ui/core/TableBody';
6+
import TableCell from '@material-ui/core/TableCell';
7+
import TableHead from '@material-ui/core/TableHead';
8+
import TableRow from '@material-ui/core/TableRow';
9+
import Paper from '@material-ui/core/Paper';
10+
import Button from '@material-ui/core/Button';
11+
import DeleteIcon from '@material-ui/icons/Delete';
12+
import { IconButton } from '@material-ui/core';
1313

1414
const styles = theme => ({
1515
root: {
16-
width: "80%",
17-
marginTop: theme.spacing.unit * 3
16+
width: '80%',
17+
marginTop: theme.spacing.unit * 3,
1818
// overflowX: "auto"
1919
},
2020
table: {
21-
minWidth: 500
22-
}
21+
minWidth: 500,
22+
},
2323
});
2424

2525
/** **************************
@@ -28,7 +28,9 @@ const styles = theme => ({
2828
* ****************************** */
2929

3030
function dataTable(props) {
31-
const { classes, rowData, rowHeader, deletePropHandler } = props;
31+
const {
32+
classes, rowData, rowHeader, deletePropHandler,
33+
} = props;
3234

3335
const renderHeader = rowHeader.map((col, idx) => (
3436
<TableCell key={`head_+${idx}`}>{col}</TableCell>
@@ -38,23 +40,19 @@ function dataTable(props) {
3840
if (!row) return;
3941
// for some reason we must put each value in a div.
4042
return rowHeader.map((header, idx) => (
41-
<TableCell align={"center"} key={`td_${idx}`}>
43+
<TableCell align={'center'} key={`td_${idx}`}>
4244
{/* <div align={'center'} padding = {'none'} >{typeof row[header] === 'string' ? row[header] : row[header].toString()}</div> */}
4345
{/* {row[header]} */}
44-
{typeof row[header] === "string" ? row[header] : row[header].toString()}
46+
{typeof row[header] === 'string' ? row[header] : row[header].toString()}
4547
</TableCell>
4648
));
4749
}
48-
//style={{height: 30}}
50+
// style={{height: 30}}
4951
const renderRows = rowData.map(row => (
5052
<TableRow key={`row-${row.id}`}>
5153
{renderRowCells(row)}
52-
<TableCell align={"center"} padding={"none"}>
53-
<IconButton
54-
color="default"
55-
fontSize="small"
56-
onClick={() => deletePropHandler(row.id)}
57-
>
54+
<TableCell align={'center'} padding={'none'}>
55+
<IconButton color="default" fontSize="small" onClick={() => deletePropHandler(row.id)}>
5856
<DeleteIcon />
5957
</IconButton>
6058
{/* <Button style={{height: 20}} onClick={() => deletePropHandler(row.id)}>Delete</Button> */}
@@ -64,7 +62,7 @@ function dataTable(props) {
6462

6563
return (
6664
<Paper className={classes.root}>
67-
<Table className={classes.table} selectable={"true"}>
65+
<Table className={classes.table} selectable={'true'}>
6866
<TableHead>
6967
<TableRow>{renderHeader}</TableRow>
7068
</TableHead>

src/components/GrandchildRectangle.jsx

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
1-
import React, { Component } from "react";
2-
import { Rect, Group } from "react-konva";
1+
import React, { Component } from 'react';
2+
import { Rect, Group } from 'react-konva';
33

44
class GrandchildRectangle extends Component {
55
getComponentColor(componentId) {
6-
const color = this.props.components.find(comp => comp.id == componentId)
7-
.color;
6+
const color = this.props.components.find(comp => comp.id == componentId).color;
87
return color;
98
}
109

1110
getPseudoChild() {
12-
return this.props.components.find(
13-
comp => comp.id === this.props.childComponentId
14-
);
11+
return this.props.components.find(comp => comp.id === this.props.childComponentId);
1512
}
1613

1714
render() {
@@ -28,7 +25,7 @@ class GrandchildRectangle extends Component {
2825
width,
2926
height,
3027
focusChild,
31-
components
28+
components,
3229
} = this.props;
3330

3431
// the Group is responsible for dragging of all children
@@ -54,21 +51,17 @@ class GrandchildRectangle extends Component {
5451
scaleY={1}
5552
width={width}
5653
height={height}
57-
stroke={
58-
childType === "COMP"
59-
? this.getComponentColor(childComponentId)
60-
: "#000000"
61-
}
54+
stroke={childType === 'COMP' ? this.getComponentColor(childComponentId) : '#000000'}
6255
// fill={color}
6356
// opacity={0.8}
6457
strokeWidth={4}
6558
strokeScaleEnabled={false}
6659
draggable={false}
6760
/>
68-
{childType === "COMP" &&
69-
components
61+
{childType === 'COMP'
62+
&& components
7063
.find(comp => comp.title === childComponentName)
71-
.childrenArray.filter(child => child.childId !== "-1")
64+
.childrenArray.filter(child => child.childId !== -1)
7265
.map((grandchild, i) => (
7366
<GrandchildRectangle
7467
key={i}
@@ -79,21 +72,17 @@ class GrandchildRectangle extends Component {
7972
childComponentId={grandchild.childComponentId}
8073
focusChild={focusChild}
8174
childId={childId}
82-
width={
83-
grandchild.position.width *
84-
(width / this.getPseudoChild().position.width)
85-
}
75+
width={grandchild.position.width * (width / this.getPseudoChild().position.width)}
8676
height={
87-
grandchild.position.height *
88-
(height / this.getPseudoChild().position.height)
77+
grandchild.position.height * (height / this.getPseudoChild().position.height)
8978
}
9079
x={
91-
(grandchild.position.x - this.getPseudoChild().position.x) *
92-
(width / this.getPseudoChild().position.width)
80+
(grandchild.position.x - this.getPseudoChild().position.x)
81+
* (width / this.getPseudoChild().position.width)
9382
}
9483
y={
95-
(grandchild.position.y - this.getPseudoChild().position.y) *
96-
(height / this.getPseudoChild().position.height)
84+
(grandchild.position.y - this.getPseudoChild().position.y)
85+
* (height / this.getPseudoChild().position.height)
9786
}
9887
/>
9988
))}

src/components/KonvaStage.jsx

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

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

2626
let childrenArrCopy = cloneDeep(childrenArr);
2727

2828
const pseudoChild = {
29-
childId: '-1',
29+
childId: -1,
3030
childComponentId: component.id,
3131
componentName: component.title,
3232
position: {
@@ -186,7 +186,7 @@ class KonvaStage extends Component {
186186
childComponentId={child.childComponentId}
187187
childComponentName={child.componentName}
188188
focusChild={focusChild}
189-
childId={child.childId} // '-1' for pseudoChild
189+
childId={child.childId} // -1 for pseudoChild
190190
x={child.position.x}
191191
y={child.position.y}
192192
scaleX={1}

src/components/Rectangle.jsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class Rectangle extends Component {
2525
.find(comp => comp.id === this.props.componentId)
2626
.childrenArray.find(child => child.childId === childId);
2727

28-
if (childId == '-1') {
28+
if (childId == -1) {
2929
focChild = this.props.components.find(comp => comp.id === this.props.componentId);
3030
}
3131
const transformation = {
@@ -108,8 +108,8 @@ class Rectangle extends Component {
108108
strokeWidth={4}
109109
strokeScaleEnabled={false}
110110
draggable={false}
111-
fill={childId === '-1' ? 'white' : null}
112-
shadowBlur={childId === '-1' ? 6 : null}
111+
fill={childId === -1 ? 'white' : null}
112+
shadowBlur={childId === -1 ? 6 : null}
113113
// dashEnabled={childId === "-1"} // dash line only enabled for pseudochild
114114
// dash={[10, 3]} // 10px dashes with 3px gaps
115115
/>
@@ -118,19 +118,19 @@ class Rectangle extends Component {
118118
fontStyle={'bold'}
119119
fontVariant={'small-caps'}
120120
// pseudochild's label should look different than normal children:
121-
text={childId === '-1' ? title.slice(0, title.length - 2) : title}
122-
fill={childId === '-1' ? this.getComponentColor(childComponentId) : '#000000'}
123-
fontSize={childId === '-1' ? 15 : 10}
121+
text={childId === -1 ? title.slice(0, title.length - 2) : title}
122+
fill={childId === -1 ? this.getComponentColor(childComponentId) : '#000000'}
123+
fontSize={childId === -1 ? 15 : 10}
124124
x={4}
125-
y={childId === '-1' ? -20 : -12}
125+
y={childId === -1 ? -20 : -12}
126126
/>
127127
</Label>
128128
{// for all children other than the pseudoChild, find their component's children array and recursively render the children found there
129-
childId !== '-1'
129+
childId !== -1
130130
&& childType == 'COMP'
131131
&& components
132132
.find(comp => comp.title === childComponentName)
133-
.childrenArray.filter(child => child.childId !== '-1')
133+
.childrenArray.filter(child => child.childId !== -1)
134134
// .sort((a, b) => parseInt(a.childId) - parseInt(b.childId)) // using i within map below, sorting by childId might be necessary
135135
.map((grandchild, i) => (
136136
<GrandchildRectangle

src/reducers/componentReducer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ import cloneDeep from '../utils/cloneDeep.ts';
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
@@ -51,7 +51,7 @@ export const addComponent = (state, { title }) => {
5151
}
5252

5353
const componentColor = getColor();
54-
const componentId = state.nextId.toString();
54+
const componentId = state.nextId;
5555

5656
const newComponent = {
5757
...initialComponentState,
@@ -80,7 +80,7 @@ export const addComponent = (state, { title }) => {
8080
focusComponent: newComponent,
8181
focusChild: newFocusChild,
8282
ancestors: [],
83-
selectableChildren, // new component so you everyone except yourself is available
83+
selectableChildren, // new component so everyone except yourself is available
8484
};
8585
};
8686

@@ -142,7 +142,7 @@ export const addChild = (state, { title, childType = '', HTMLInfo = {} }) => {
142142
};
143143

144144
const newChild = {
145-
childId: view.nextChildId.toString(),
145+
childId: view.nextChildId,
146146
childType,
147147
childComponentId: childType == 'COMP' ? parentComponent.id : null, // only relevant fot children of type COMPONENT
148148
componentName: strippedTitle,
@@ -202,7 +202,7 @@ export const deleteChild = (
202202
window.alert('No child selected');
203203
return state;
204204
}
205-
if (!calledFromDeleteComponent && childId === '-1') {
205+
if (!calledFromDeleteComponent && childId === -1) {
206206
window.alert('Cannot delete root child of a component');
207207
return state;
208208
}
@@ -240,7 +240,7 @@ export const deleteChild = (
240240
export const handleTransform = (state, {
241241
componentId, childId, x, y, width, height,
242242
}) => {
243-
if (childId === '-1') {
243+
if (childId === -1) {
244244
// the pseudochild has been transformed, its position is stored in the component
245245
const component = state.components.find(comp => comp.id === componentId);
246246
const transformedComponent = {
@@ -409,7 +409,7 @@ export const changeFocusChild = (state, { title, childId }) => {
409409

410410
if (!newFocusChild) {
411411
newFocusChild = {
412-
childId: '-1',
412+
childId: -1,
413413
childComponentId: focComp.id,
414414
componentName: focComp.title,
415415
position: {
@@ -602,7 +602,7 @@ export const addProp = (state, {
602602
const selectedComponent = state.components.find(comp => comp.id == state.focusComponent.id);
603603

604604
const newProp = {
605-
id: selectedComponent.nextPropId.toString(),
605+
id: selectedComponent.nextPropId,
606606
key,
607607
value: value || key,
608608
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)