Skip to content

Commit c67bb8f

Browse files
duplicate component names no longer allowed
1 parent e662560 commit c67bb8f

File tree

4 files changed

+13
-13
lines changed

4 files changed

+13
-13
lines changed

src/components/LeftColExpansionPanel.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const LeftColExpansionPanel = (props) => {
3333
return focusComponent.title === title ? 'focused' : '';
3434
}
3535

36-
function isAncestor() {
36+
function isAncestorOfFocused() {
3737
// add logic for determining if given component is an ancestor of focusedComponent
3838
return false;
3939
}
@@ -62,7 +62,7 @@ const LeftColExpansionPanel = (props) => {
6262
style={{ color }}
6363
/>
6464
<ListItemSecondaryAction>
65-
{isFocused() || isAncestor() ? (
65+
{isFocused() || isAncestorOfFocused() ? (
6666
<div />
6767
) : (
6868
<IconButton aria-label="Add">

src/components/Rectangle.jsx

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ class Rectangle extends Component {
3636
focusChild,
3737
focusComponent,
3838
} = this.props;
39+
40+
// the Group is responsible for dragging of all children
41+
// the Rect emits changes to child width and height with help from Transformer
3942
return (
4043
<Group
4144
draggable={true}
@@ -66,17 +69,6 @@ class Rectangle extends Component {
6669
strokeWidth={4}
6770
strokeScaleEnabled={false}
6871
draggable={false}
69-
70-
// use dragBoundFunc to bind children within parents
71-
// (but if only children are rendered/movable, and parent is size of canvas, won't need this anyways )
72-
// dragBoundFunc={function dragBoundFunc(pos) {
73-
// const newY = pos.y < 200 ? 200 : pos.y;
74-
// const newX = pos.x < 200 ? 200 : pos.x;
75-
// return {
76-
// x: newX,
77-
// y: newY,
78-
// };
79-
// }}
8072
/>
8173
<Label>
8274
<Text text={title} fill={'white'} />

src/components/TransformerComponent.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export default class TransformerComponent extends Component {
1111
this.checkNode();
1212
}
1313

14+
// this function makes sure the transformer follows along with the focusChild
1415
checkNode() {
1516
const stage = this.transformer.getStage();
1617
const { focusChild } = this.props;

src/utils/componentReducer.util.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ export const addComponent = (state, { title }) => {
4141
const strippedTitle = title
4242
.replace(/[a-z]+/gi, word => word[0].toUpperCase() + word.slice(1))
4343
.replace(/[-_\s0-9\W]+/gi, '');
44+
45+
if (state.components.find(comp => comp.title === strippedTitle)) {
46+
// alert the user that duplicate component names are not allowed
47+
return {
48+
...state,
49+
};
50+
}
4451
const newComponent = {
4552
...initialComponentState,
4653
title: strippedTitle,

0 commit comments

Comments
 (0)