Skip to content

Commit 996e25f

Browse files
Merge pull request #3 from oslabs-beta/c2
C2 (Chris and Crys) Branch Merging to Dev-46 Branch
2 parents a051a72 + cc29ba4 commit 996e25f

File tree

8 files changed

+33
-23
lines changed

8 files changed

+33
-23
lines changed

app/src/components/left/DragDropPanel.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const DragDropPanel = (props): JSX.Element => {
4848
>
4949
<h3>HTML ELEMENTS</h3>
5050
{htmlTypesToRender.map(option => {
51-
if(option.id !== 17 || option.id !== 18) {
51+
if(option.id !== 17 && option.id !== 18) {
5252
return (
5353
<HTMLItem
5454
name={option.name}

app/src/components/main/Canvas.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function Canvas() {
2525
function onClickHandler(event) {
2626
event.stopPropagation();
2727
// note: a null value for the child id means that we are focusing on the top-level component rather than any child
28-
console.log(state.canvasFocus);
28+
console.log(state.canvasFocus);
2929
changeFocus(state.canvasFocus.componentId, null);
3030
};
3131

@@ -51,7 +51,6 @@ function Canvas() {
5151
}
5252
// if item dropped is going to be a new instance (i.e. it came from the left panel), then create a new child component
5353
if (item.newInstance) {
54-
console.log('Canvas first dispatch')
5554
dispatch({
5655
type: 'ADD CHILD',
5756
payload: {

app/src/components/main/DemoRender.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import React, {
33
useState, useCallback, useContext, useEffect,
44
} from 'react';
5+
import { BrowserRouter as Router, Switch, Route, Link } from "react-router-dom";
56
import Button from '@material-ui/core/Button';
67
import Box from '@material-ui/core/Box';
78
import StateContext from '../../context/context';
@@ -37,6 +38,9 @@ const DemoRender = (props): JSX.Element => {
3738
if (elementType === 'input') componentsToRender.push(<Box component={elementType} className={classRender} style={elementStyle} key={key} id={`rend${childId}`}></Box>);
3839
else if (elementType === 'img') componentsToRender.push(<Box component={elementType} src={activeLink} className={classRender} style={elementStyle} key={key} id={`rend${childId}`}></Box>);
3940
else if (elementType === 'a') componentsToRender.push(<Box component={elementType} href={activeLink} className={classRender} style={elementStyle} key={key} id={`rend${childId}`}>{innerText}</Box>);
41+
else if (elementType === 'Switch') componentsToRender.push(<Switch>{renderedChildren}</Switch>);
42+
else if (elementType === 'Route') componentsToRender.push(<Route exact path={activeLink}>{renderedChildren}</Route>);
43+
else if (elementType === 'LinkTo') componentsToRender.push(<Link to={activeLink}>{innerText}</Link>);
4044
else componentsToRender.push(<Box component={elementType} className={classRender} style={elementStyle} key={key} id={`rend${childId}`}>{innerText}{renderedChildren}</Box>);
4145
key += 1;
4246
}
@@ -57,9 +61,12 @@ const DemoRender = (props): JSX.Element => {
5761

5862

5963
return (
60-
<div id={'renderFocus'} style={demoContainerStyle}>
61-
{components.map((component, index) => component)}
62-
</div>
64+
<Router>
65+
<div id={'renderFocus'} style={demoContainerStyle}>
66+
{components.map((component, index) => component)}
67+
</div>
68+
</Router>
69+
6370
);
6471
};
6572

app/src/components/main/DirectChildComponent.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ import { ItemTypes } from '../../constants/ItemTypes';
99
import StateContext from '../../context/context';
1010
import { combineStyles } from '../../helperFunctions/combineStyles';
1111
import globalDefaultStyle from '../../public/styles/globalDefaultStyles';
12-
import renderChildren from '../../helperFunctions/renderChildren'
1312

14-
function DirectChildComponent({ childId, type, typeId, style }: ChildElement) {
13+
function DirectChildComponent({ childId, type, typeId, style, name }: ChildElement) {
1514
const [state, dispatch] = useContext(StateContext);
1615

1716
// find the top-level component corresponding to this instance of the component
@@ -64,13 +63,17 @@ function DirectChildComponent({ childId, type, typeId, style }: ChildElement) {
6463
interactiveStyle
6564
);
6665

67-
return (
66+
67+
// Renders name and not children of subcomponents to clean up Canvas view when dragging components
68+
// into the main canvas. To render html elements on canvas, import and invoke renderChildren
69+
return (
6870
<div
6971
onClick={onClickHandler}
7072
style={combinedStyle}
7173
ref={drag}
7274
>
73-
{renderChildren(referencedComponent.children)}
75+
<strong>{name}</strong>
76+
{` (${childId})`}
7477
</div>
7578
);
7679
}

app/src/components/main/DirectChildHTMLNestable.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ function DirectChildHTMLNestable({
2020
children,
2121
name,
2222
annotations,
23+
attributes
2324
}: ChildElement) {
2425
const [state, dispatch] = useContext(StateContext);
2526
const ref = useRef(null);
@@ -143,6 +144,7 @@ const snapShotFunc = () => {
143144
<div onClick={onClickHandler} style={combinedStyle} ref={ref} id={`canv${childId}`}>
144145
<strong>{HTMLType.placeHolderShort}</strong>
145146
{` ( ${childId} )`}
147+
<strong style={{ color: "#0099E6" }}>{attributes && attributes.compLink ? ` ${attributes.compLink}` : ''}</strong>
146148
{routeButton}
147149
<Annotation
148150
id={childId}

app/src/context/HTMLTypes.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -165,15 +165,6 @@ const HTMLTypes: HTMLType[] = [
165165
placeHolderLong: '',
166166
icon: ListIcon
167167
},
168-
{
169-
id: 18,
170-
tag: 'Link',
171-
name: 'LinkTo',
172-
style: {},
173-
placeHolderShort: 'link to',
174-
placeHolderLong: '',
175-
icon: ListIcon
176-
},
177168
{
178169
id: -1,
179170
tag: 'Route',
@@ -182,6 +173,15 @@ const HTMLTypes: HTMLType[] = [
182173
placeHolderShort: 'Route',
183174
placeHolderLong: '',
184175
icon: LinkIcon
176+
},
177+
{
178+
id: 18,
179+
tag: 'LinkTo',
180+
name: 'LinkTo',
181+
style: {},
182+
placeHolderShort: 'LinkTo',
183+
placeHolderLong: '',
184+
icon: ListIcon
185185
}
186186
];
187187

app/src/helperFunctions/generateCode.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,8 @@ const generateUnformattedCode = (
141141
return `${levelSpacer(level, 5)}<${childElement.tag} href="${activeLink}" ${elementTagDetails(childElement)}>${innerText}</${childElement.tag}>${levelSpacer(2, (3 + level))}`;
142142
} else if (childElement.tag === 'input') {
143143
return `${levelSpacer(level, 5)}<${childElement.tag}${elementTagDetails(childElement)}></${childElement.tag}>${levelSpacer(2, (3 + level))}`;
144-
} else if (childElement.tag === 'Link') {
145-
return `${levelSpacer(level, 5)}<${childElement.tag} to="${activeLink}" ${elementTagDetails(childElement)}>${innerText}
146-
${tabSpacer(level)}${writeNestedElements(childElement.children, level + 1)}
147-
${tabSpacer(level - 1)}</${childElement.tag}>${levelSpacer(2, (3 + level))}`;
144+
} else if (childElement.tag === 'LinkTo') {
145+
return `${levelSpacer(level, 5)}<Link to="${activeLink}"${elementTagDetails(childElement)}>${innerText}</Link>${levelSpacer(2, (3 + level))}`;
148146
} else if (nestable) {
149147
const routePath = (childElement.tag === 'Route') ? (' ' + 'exact path="' + activeLink + '"') : '';
150148
return `${levelSpacer(level, 5)}<${childElement.tag}${elementTagDetails(childElement)}${routePath}>${innerText}

app/src/helperFunctions/renderChildren.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ const renderChildren = (children: ChildElement[]) => {
5858
key={'DirChildHTMLNest' + childId.toString() + name}
5959
name={name}
6060
annotations={annotations}
61+
attributes={attributes}
6162
/>
6263
);
6364
}

0 commit comments

Comments
 (0)