Skip to content

Commit 28c2c0f

Browse files
committed
Merge branch 'master' into theme-changer
2 parents 87c51d7 + 2b9b121 commit 28c2c0f

File tree

9 files changed

+156
-98
lines changed

9 files changed

+156
-98
lines changed

app/src/components/left/ComponentPanel.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@ const ComponentPanel = (): JSX.Element => {
162162
{state.components
163163
.filter(comp => state.rootComponents.includes(comp.id))
164164
.map(comp => {
165-
//console.log('root comp', comp.name)
166165
return (
167166
<ComponentPanelItem
168167
isFocus={isFocus(comp.id)}
@@ -180,8 +179,6 @@ const ComponentPanel = (): JSX.Element => {
180179
{state.components
181180
.filter(comp => !state.rootComponents.includes(comp.id))
182181
.map(comp => {
183-
//console.log('all root comps', state.rootComponents);
184-
//console.log('all reusable comps', state.components);
185182
return (
186183
<ComponentPanelItem
187184
isFocus={isFocus(comp.id)}

app/src/components/left/ComponentPanelItem.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ const ComponentPanelItem: React.FC<{
1414
}> = ({ name, id, root, isFocus }) => {
1515
const classes = useStyles();
1616
const [state, dispatch] = useContext(stateContext);
17-
1817
// useDrag hook allows components in left panel to be drag source
1918
const [{ isDragging }, drag] = useDrag({
2019
item: {

app/src/components/left/HTMLPanel.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ const HTMLPanel = (): JSX.Element => {
1414
const [errorMsg, setErrorMsg] = useState('');
1515
const [errorStatus, setErrorStatus] = useState(false);
1616

17+
const buttonClasses = "MuiButtonBase-root MuiButton-root MuiButton-text makeStyles-button-12 MuiButton-textPrimary";
18+
1719
const handleTagChange = (e: React.ChangeEvent<HTMLInputElement>) => {
1820
resetError();
1921
setTag(e.target.value);
@@ -138,12 +140,7 @@ const HTMLPanel = (): JSX.Element => {
138140
/>
139141
{errorStatus && <span>{errorMsg}</span>}
140142
</label>
141-
<input
142-
className={classes.button}
143-
color="primary"
144-
type="submit"
145-
value="Add Element"
146-
/>
143+
<input className={buttonClasses} color="primary" type="submit" value="Add Element" style={{marginTop:'15px'}}/>
147144
</form>
148145
</div>
149146
</div>

app/src/components/main/Canvas.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ function Canvas() {
3030
const [{ isOver }, drop] = useDrop({
3131
accept: ItemTypes.INSTANCE,
3232
drop: (item: DragItem, monitor: DropTargetMonitor) => {
33-
//console.log(isOver);
3433
const didDrop = monitor.didDrop(); // returns false for direct drop target
3534
if (didDrop) {
3635
return;
@@ -49,7 +48,6 @@ function Canvas() {
4948
}
5049
// if item is not a new instance, change position of element dragged inside div so that the div is the new parent
5150
else {
52-
console.log('dispatch change position');
5351
dispatch({
5452
type: 'CHANGE POSITION',
5553
payload: {
@@ -75,8 +73,7 @@ function Canvas() {
7573
// Combine the default styles of the canvas with the custom styles set by the user for that component
7674
// The render children function renders all direct children of a given component
7775
// Direct children are draggable/clickable
78-
//console.log('curr comp =>', currentComponent);
79-
//console.log('curr comp style', currentComponent.style);
76+
8077
const canvasStyle = combineStyles(defaultCanvasStyle, currentComponent.style);
8178
return (
8279
<div ref={drop} style={canvasStyle} onClick={onClickHandler}>

app/src/components/main/DirectChildComponent.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ function DirectChildComponent({ childId, type, typeId, style }: ChildElement) {
7171
const renderIndirectChildren = (
7272
referencedComponent: Component | ChildElement
7373
) => {
74-
console.log('referenced comp => ', referencedComponent);
7574
// iterate through all children of referenced
7675
return referencedComponent.children.map(child => {
7776
if (child.type === 'Component') {

app/src/constants/ErrorMessages.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export default {
2+
deleteIndexTitle: 'You cannot delete index.',
3+
deleteIndexMessage: 'You must have at least one page.',
4+
deleteComponentTitle: 'You cannot delete this component.',
5+
deleteComponentMessage: 'Reusable components inside of a page must be deleted from the page.'
6+
}

app/src/containers/RightContainer.tsx

Lines changed: 87 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1-
import React, { useState, useContext, useEffect, useMemo } from 'react';
2-
1+
import React, { useState, useContext, useEffect, useMemo, Component } from 'react';
32
import { makeStyles } from '@material-ui/core/styles';
43
import FormControl from '@material-ui/core/FormControl';
54
import Select from '@material-ui/core/Select';
65
import MenuItem from '@material-ui/core/MenuItem';
76
import TextField from '@material-ui/core/TextField';
87
import Button from '@material-ui/core/Button';
9-
108
import { stateContext } from '../context/context';
11-
9+
import HTMLTypes from '../context/HTMLTypes';
1210
import ProjectManager from '../components/right/ProjectManager';
11+
import Dialog from '@material-ui/core/Dialog';
12+
import DialogActions from '@material-ui/core/DialogActions';
13+
import DialogContent from '@material-ui/core/DialogContent';
14+
import DialogContentText from '@material-ui/core/DialogContentText';
15+
import DialogTitle from '@material-ui/core/DialogTitle';
16+
import ErrorMessages from '../constants/ErrorMessages';
1317

1418
// need to pass in props to use the useHistory feature of react router
1519
const RightContainer = (props): JSX.Element => {
@@ -22,10 +26,11 @@ const RightContainer = (props): JSX.Element => {
2226
const [BGColor, setBGColor] = useState('');
2327
const [compWidth, setCompWidth] = useState('');
2428
const [compHeight, setCompHeight] = useState('');
29+
const [dialogError, setDialogError] = useState(false);
30+
const [deleteIndexError, setDeleteIndexError] = useState(false);
31+
const [deleteComponentError, setDeleteComponentError] = useState(false);
2532

2633
const resetFields = () => {
27-
//console.log(configTarget);
28-
//console.log(configTarget.children);
2934
const style = configTarget.child
3035
? configTarget.child.style
3136
: configTarget.style;
@@ -137,6 +142,25 @@ const RightContainer = (props): JSX.Element => {
137142
.some(el => el.id === configTarget.id);
138143
}
139144

145+
const isIndex = (): boolean => configTarget.id === 1;
146+
147+
const isChildOfPage = (): boolean => {
148+
// TODO: refactor
149+
// TODO: output parent name and id to refocus canvas on parent
150+
let isChild: boolean = false;
151+
const { id } = configTarget;
152+
state.components.forEach(comp => {
153+
comp.children.forEach(child => {
154+
if (child.type === 'Component' && child.typeId === id) {
155+
isChild = true;
156+
}
157+
});
158+
});
159+
return isChild;
160+
}
161+
162+
163+
140164
// dispatch to 'UPDATE CSS' called when save button is clicked,
141165
// passing in style object constructed from all changed input values
142166
const handleSave = (): Object => {
@@ -163,11 +187,16 @@ const RightContainer = (props): JSX.Element => {
163187
};
164188

165189
const handlePageDelete = (id) => () => {
166-
dispatch({ type: 'DELETE PAGE', payload: { id }});
190+
// TODO: return modal
191+
isIndex()
192+
? handleDialogError('index')
193+
: dispatch({ type: 'DELETE PAGE', payload: { id }});
167194
}
168-
195+
169196
const handleDeleteReusableComponent = () => {
170-
dispatch({ type: 'DELETE REUSABLE COMPONENT', payload: {} });
197+
isChildOfPage()
198+
? handleDialogError('component')
199+
: dispatch({ type: 'DELETE REUSABLE COMPONENT', payload: {} });
171200
}
172201

173202
const isReusable = (configTarget): boolean => {
@@ -177,6 +206,16 @@ const RightContainer = (props): JSX.Element => {
177206
.some(el => el.id == configTarget.id);
178207
}
179208

209+
const handleDialogError = (err) => {
210+
if (err === 'index') setDeleteIndexError(true);
211+
else setDeleteComponentError(true);
212+
}
213+
214+
const handleCloseDialogError = () => {
215+
setDeleteIndexError(false);
216+
setDeleteComponentError(false);
217+
}
218+
180219
return (
181220
<div className="column right ">
182221
<div className="rightPanelWrapper">
@@ -387,22 +426,57 @@ const RightContainer = (props): JSX.Element => {
387426
DELETE PAGE
388427
</Button>
389428
</div>
390-
) : isReusable(configTarget) ? (
429+
) : (
391430
<div className={classes.buttonRow}>
392431
<Button
393432
color="secondary"
394433
className={classes.button}
395434
onClick={handleDeleteReusableComponent}
396435
>
397-
DELETE PAGE
436+
DELETE REUSABLE COMPONENT
398437
</Button>
399438
</div>
400-
) :
401-
''
439+
)
402440
)}
403441
</div>
404442
<ProjectManager />
405443
</div>
444+
<Dialog
445+
open={deleteIndexError}
446+
onClose={handleCloseDialogError}
447+
aria-labelledby="alert-dialog-title"
448+
aria-describedby="alert-dialog-description"
449+
>
450+
<DialogTitle id="alert-dialog-title">{ErrorMessages.deleteIndexTitle}</DialogTitle>
451+
<DialogContent>
452+
<DialogContentText id="alert-dialog-description">
453+
{ErrorMessages.deleteIndexMessage}
454+
</DialogContentText>
455+
</DialogContent>
456+
<DialogActions>
457+
<Button onClick={handleCloseDialogError} color="primary">
458+
OK
459+
</Button>
460+
</DialogActions>
461+
</Dialog>
462+
<Dialog
463+
open={deleteComponentError}
464+
onClose={handleCloseDialogError}
465+
aria-labelledby="alert-dialog-title"
466+
aria-describedby="alert-dialog-description"
467+
>
468+
<DialogTitle id="alert-dialog-title">{ErrorMessages.deleteComponentTitle}</DialogTitle>
469+
<DialogContent>
470+
<DialogContentText id="alert-dialog-description">
471+
{ErrorMessages.deleteComponentMessage}
472+
</DialogContentText>
473+
</DialogContent>
474+
<DialogActions>
475+
<Button onClick={handleCloseDialogError} color="primary">
476+
OK
477+
</Button>
478+
</DialogActions>
479+
</Dialog>
406480
</div>
407481
);
408482
};

0 commit comments

Comments
 (0)