Skip to content

Commit 709ee99

Browse files
MadinventorZerojonocrbuddhajjigaexkevinparkwilliamdyoon
committed
Big fix. Annotations needed some of the keys without random numbers, restricted that back to separators only so Annotations didn't break. Fixed a major bug where components broke on trying to nest inside themselves. Wrote a new function to validate nesting at the component level. Cleaned up DirectChild Render as it was duplicating the renderChildren helperfunction. This also cleaned up the annotations for components when they are dragged and dropped.
Co-authored-by: jonocr <[email protected]> Co-authored-by: buddhajjigae <[email protected]> Co-authored-by: xkevinpark <[email protected]> Co-authored-by: williamdyoon <[email protected]>
1 parent abdc21c commit 709ee99

File tree

6 files changed

+66
-155
lines changed

6 files changed

+66
-155
lines changed

app/src/components/main/DirectChildComponent.tsx

Lines changed: 2 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import { useDrag } from 'react-dnd';
88
import { ItemTypes } from '../../constants/ItemTypes';
99
import StateContext from '../../context/context';
1010
import { combineStyles } from '../../helperFunctions/combineStyles';
11-
import IndirectChild from './IndirectChild';
1211
import globalDefaultStyle from '../../public/styles/globalDefaultStyles';
12+
import renderChildren from '../../helperFunctions/renderChildren'
1313

1414
function DirectChildComponent({ childId, type, typeId, style }: ChildElement) {
1515
const [state, dispatch] = useContext(StateContext);
@@ -64,119 +64,13 @@ function DirectChildComponent({ childId, type, typeId, style }: ChildElement) {
6464
interactiveStyle
6565
);
6666

67-
// helper function to render children of direct child components
68-
// all children of direct child components will be indirect components
69-
// indirect child components are not interactive with the exception of route links which, when clicked, will change the canvas focus
70-
const renderIndirectChildren = (
71-
referencedComponent: Component | ChildElement
72-
) => {
73-
// iterate through all children of referenced
74-
return referencedComponent.children.map(child => {
75-
if (child.type === 'Component') {
76-
// If indirect child of referenced component is a component, find the top level component referenced by the child
77-
const childReferencedComponent: Component = state.components.find(
78-
(elem: Component) => elem.id === child.typeId
79-
);
80-
// combine the styles of the child with the reference component but give higher priority to the child's styles
81-
82-
const combinedStyle = combineStyles(
83-
childReferencedComponent.style,
84-
child.style
85-
);
86-
87-
// render an IndirectChild component, and also call renderIndirectChildren recursively to render any of the child Component's children
88-
return (
89-
<IndirectChild
90-
// combine styles of instance and referenced component. instance styles have higher priority
91-
key={
92-
'indChild' + child.childId.toString() + child.typeId.toString()
93-
}
94-
style={combinedStyle}
95-
placeHolder=""
96-
linkId={null}
97-
childId={childId}
98-
>
99-
{renderIndirectChildren(childReferencedComponent)}
100-
</IndirectChild>
101-
);
102-
} else if (child.type === 'HTML Element') {
103-
// if indirect child is an HTML element, render an IndirectChild component with no children
104-
// if the HTML element has children, then also render its children
105-
// get the default style/placeholder value for that type of HTML element
106-
// combine the default style of that HTML element and combine in with the custom styles applied to that element
107-
const HTMLType: HTMLType = state.HTMLTypes.find(
108-
(type: HTMLType) => type.id === child.typeId
109-
);
110-
const HTMLDefaultStyle = HTMLType.style;
111-
const HTMLDefaultPlaceholder = HTMLType.placeHolderShort;
112-
const combinedStyle = combineStyles(HTMLDefaultStyle, child.style);
113-
return (
114-
<React.Fragment
115-
key={
116-
'indChildFrag' +
117-
child.childId.toString() +
118-
child.typeId.toString()
119-
}
120-
>
121-
{child.children.length === 0 ? (
122-
<IndirectChild
123-
style={combinedStyle}
124-
placeHolder={HTMLDefaultPlaceholder}
125-
linkId={null}
126-
childId={childId}
127-
key={
128-
'indChildHTML' +
129-
child.childId.toString() +
130-
child.typeId.toString()
131-
}
132-
>
133-
{''}
134-
</IndirectChild>
135-
) : (
136-
<IndirectChild
137-
style={combinedStyle}
138-
placeHolder={HTMLDefaultPlaceholder}
139-
linkId={null}
140-
childId={childId}
141-
key={
142-
'indChildNest' +
143-
child.childId.toString() +
144-
child.typeId.toString()
145-
}
146-
>
147-
{renderIndirectChildren(child)}
148-
</IndirectChild>
149-
)}
150-
</React.Fragment>
151-
);
152-
} else if (child.type === 'Route Link') {
153-
// Render a next.js route link
154-
// pass the component id of the component referenced in the link as a prop
155-
// IndirectChild will render the referenced component name as a clickable link
156-
return (
157-
<IndirectChild
158-
key={
159-
'RouteLink' + child.childId.toString() + child.typeId.toString()
160-
}
161-
style={combinedStyle}
162-
placeHolder=""
163-
linkId={child.typeId}
164-
childId={childId}
165-
>
166-
{''}
167-
</IndirectChild>
168-
);
169-
}
170-
});
171-
};
17267
return (
17368
<div
17469
onClick={onClickHandler}
175-
// key={'childComp' + childId}
17670
style={combinedStyle}
17771
ref={drag}
17872
>
179-
{renderIndirectChildren(referencedComponent)}
73+
{renderChildren(referencedComponent.children)}
18074
</div>
18175
);
18276
}

app/src/components/main/DirectChildHTMLNestable.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import renderChildren from '../../helperFunctions/renderChildren';
99
// Caret
1010
import Annotation from './Annotation'
1111
import validateNewParent from '../../helperFunctions/changePositionValidation'
12+
import componentNest from '../../helperFunctions/componentNestValidation'
1213

1314
function DirectChildHTMLNestable({
1415
childId,
@@ -70,14 +71,16 @@ const snapShotFunc = () => {
7071
// updates state with new instance
7172
// if item dropped is going to be a new instance (i.e. it came from the left panel), then create a new child component
7273
if (item.newInstance) {
73-
dispatch({
74-
type: 'ADD CHILD',
75-
payload: {
76-
type: item.instanceType,
77-
typeId: item.instanceTypeId,
78-
childId: childId,
79-
}
80-
});
74+
if ((item.instanceType === 'Component' && componentNest(state.components[item.instanceTypeId - 1].children, childId)) || item.instanceType !== 'Component') {
75+
dispatch({
76+
type: 'ADD CHILD',
77+
payload: {
78+
type: item.instanceType,
79+
typeId: item.instanceTypeId,
80+
childId: childId,
81+
}
82+
});
83+
}
8184
}
8285
// if item is not a new instance, change position of element dragged inside div so that the div is the new parent
8386
else {

app/src/components/main/SeparatorChild.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { combineStyles } from '../../helperFunctions/combineStyles';
77
import globalDefaultStyle from '../../public/styles/globalDefaultStyles';
88
import renderChildren from '../../helperFunctions/renderChildren';
99
import validateNewParent from '../../helperFunctions/changePositionValidation'
10+
import componentNest from '../../helperFunctions/componentNestValidation'
1011

1112
function DirectChildHTMLNestable({
1213
childId,
@@ -54,14 +55,16 @@ function DirectChildHTMLNestable({
5455
// updates state with new instance
5556
// if item dropped is going to be a new instance (i.e. it came from the left panel), then create a new child component
5657
if (item.newInstance) {
57-
dispatch({
58-
type: 'ADD CHILD',
59-
payload: {
60-
type: item.instanceType,
61-
typeId: item.instanceTypeId,
62-
childId: childId
63-
}
64-
});
58+
if ((item.instanceType === 'Component' && componentNest(state.components[item.instanceTypeId - 1].children, childId)) || item.instanceType !== 'Component') {
59+
dispatch({
60+
type: 'ADD CHILD',
61+
payload: {
62+
type: item.instanceType,
63+
typeId: item.instanceTypeId,
64+
childId: childId,
65+
}
66+
});
67+
}
6568
}
6669
// if item is not a new instance, change position of element dragged inside separator so that separator is new parent (until replacement)
6770
else {

app/src/components/main/renderDemo.css

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
.text-color {
1+
.tst-text-color {
22
color: #cc0707;
33
}
4-
.btn {
4+
.tst-btn {
55
height: 20px;
66
width: 100px;
77
background-color: #ffffff
@@ -10,12 +10,12 @@
1010

1111
@import url(https://fonts.googleapis.com/css?family=Roboto:300);
1212

13-
.login-page {
13+
.tst-login-page {
1414
width: 360px;
1515
padding: 8% 0 0;
1616
margin: auto;
1717
}
18-
.form {
18+
.tst-form {
1919
position: relative;
2020
z-index: 1;
2121
background: #000000;
@@ -25,7 +25,7 @@
2525
text-align: center;
2626
box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.2), 0 5px 5px 0 rgba(0, 0, 0, 0.24);
2727
}
28-
.form input {
28+
.tst-form input {
2929
font-family: "Roboto", sans-serif;
3030
outline: 0;
3131
background: #f2f2f2;
@@ -36,7 +36,7 @@
3636
box-sizing: border-box;
3737
font-size: 14px;
3838
}
39-
.form button {
39+
.tst-form button {
4040
font-family: "Roboto", sans-serif;
4141
text-transform: uppercase;
4242
outline: 0;
@@ -50,55 +50,55 @@
5050
transition: all 0.3 ease;
5151
cursor: pointer;
5252
}
53-
.form button:hover,.form button:active,.form button:focus {
53+
.tst-form button:hover,.form button:active,.form button:focus {
5454
background: #43A047;
5555
}
56-
.form .message {
56+
.tst-form .message {
5757
margin: 15px 0 0;
5858
color: #b3b3b3;
5959
font-size: 12px;
6060
}
61-
.form .message-a {
61+
.tst-form .message-a {
6262
color: #4CAF50;
6363
text-decoration: none;
6464
}
65-
.form .register-form {
65+
.tst-form .register-form {
6666
display: none;
6767
}
68-
.container {
68+
.tst-container {
6969
position: relative;
7070
z-index: 1;
7171
max-width: 300px;
7272
margin: 0 auto;
7373
}
74-
.container:before, .container:after {
74+
.tst-container:before, .container:after {
7575
content: "";
7676
display: block;
7777
clear: both;
7878
}
79-
.container .info {
79+
.tst-container .info {
8080
margin: 50px auto;
8181
text-align: center;
8282
}
83-
.container .info h1 {
83+
.tst-container .info h1 {
8484
margin: 0 0 15px;
8585
padding: 0;
8686
font-size: 36px;
8787
font-weight: 300;
8888
color: #1a1a1a;
8989
}
90-
.container .info span {
90+
.tst-container .info span {
9191
color: #4d4d4d;
9292
font-size: 12px;
9393
}
94-
.container .info span a {
94+
.tst-container .info span a {
9595
color: #000000;
9696
text-decoration: none;
9797
}
98-
.container .info span .fa {
98+
.tst-container .info span .fa {
9999
color: #EF3B3A;
100100
}
101-
.container-body {
101+
.tst-container-body {
102102
height: 100vh;
103103
background: #76b852; /* fallback for old browsers */
104104
background: -webkit-linear-gradient(right, #76b852, #8DC26F);
@@ -111,7 +111,7 @@
111111
}
112112

113113

114-
.list-example .body-container {
114+
.tst-list-example .body-container {
115115
margin: 0;
116116
height: 100vh;
117117
display: flex;
@@ -120,12 +120,12 @@
120120
background-color: #333;
121121
}
122122

123-
.list-example ul {
123+
.tst-list-example ul {
124124
padding: 0;
125125
list-style-type: none;
126126
}
127127

128-
.list-example li {
128+
.tst-list-example li {
129129
font-size: 25px;
130130
width: 8em;
131131
height: 2em;
@@ -136,8 +136,8 @@
136136
cursor: pointer;
137137
}
138138

139-
.list-example li::before,
140-
.list-example li::after
139+
.tst-list-example li::before,
140+
.tst-list-example li::after
141141
{
142142
content: '';
143143
position: absolute;
@@ -146,21 +146,21 @@
146146
z-index: -1;
147147
}
148148

149-
.list-example li::before {
149+
.tst-list-example li::before {
150150
height: 80%;
151151
top: 10%;
152152
left: calc(-0.15em - 0.08em * 2);
153153
filter: brightness(0.8);
154154
}
155155

156-
.list-example li::after {
156+
.tst-list-example li::after {
157157
height: 60%;
158158
top: 20%;
159159
left: calc(-0.15em * 2 - 0.08em * 3);
160160
filter: brightness(0.6);
161161
}
162162

163-
.list-example li span {
163+
.tst-list-example li span {
164164
position: relative;
165165
height: 120%;
166166
top: -10%;
@@ -176,7 +176,7 @@
176176
transition: 0.3s;
177177
}
178178

179-
.list-example li:hover span {
179+
.tst-list-example li:hover span {
180180
transform: translateX(0.15em);
181181
}
182182

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const componentNest = (children: any, nestId: Number) => {
2+
console.log('Made it to this point')
3+
let notNested = true;
4+
for (const element of children) {
5+
if (element.childId === nestId) return false;
6+
else if (element.children.length > 0) notNested = componentNest(element.children, nestId);
7+
}
8+
return notNested
9+
}
10+
11+
export default componentNest;

0 commit comments

Comments
 (0)