Skip to content

Commit b7effb1

Browse files
authored
Merge pull request #73 from jzuniga206/prelim
corrected merged code that was removed
2 parents 1342072 + a4d0fab commit b7effb1

File tree

2 files changed

+115
-89
lines changed

2 files changed

+115
-89
lines changed

src/components/bottom/HtmlAttr.tsx

Lines changed: 67 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -14,73 +14,12 @@ import { HTMLelements } from '../../utils/htmlElements.util';
1414
import { PropsInt, PropInt } from '../../interfaces/Interfaces';
1515

1616
interface HTMLAttrPropsInt extends PropsInt {
17-
classes: any;
18-
updateHtmlAttr(arg: { attr: string; value: string }): void;
19-
deleteProp(id: number): void;
20-
addProp(prop: PropInt): void;
17+
classes?: any;
18+
updateHtmlAttr?: (arg: { attr: string; value: string }) => void;
2119
}
2220

2321
interface StateInt {}
2422

25-
const styles = (theme: Theme): any => ({
26-
root: {
27-
display: 'flex',
28-
justifyContent: 'center',
29-
flexWrap: 'wrap',
30-
height: '30px',
31-
width: '15rem',
32-
marginTop: '1rem',
33-
borderRadius: '5px'
34-
// border: '1px solid orange'
35-
},
36-
cssLabel: {
37-
color: 'white',
38-
marginTop: '10px'
39-
// border: '1px solid blue'
40-
},
41-
cssFocused: {
42-
color: 'green'
43-
},
44-
input: {
45-
color: '#fff',
46-
opacity: '0.7',
47-
height: '45px',
48-
width: '146px',
49-
marginTop: '20px',
50-
borderRadius: '5px',
51-
border: '1px solid #33eb91'
52-
},
53-
select: {
54-
background: '#424242',
55-
height: '45px',
56-
width: '146px',
57-
marginTop: '0px',
58-
color: '#fff',
59-
paddingLeft: '14px',
60-
borderRadius: '5px'
61-
},
62-
selectLabel: {
63-
color: 'white',
64-
zIndex: '10',
65-
dropShadow: '1px 1px 3px #fff',
66-
marginTop: '10px'
67-
// border: '1px solid blue'
68-
},
69-
70-
save: {
71-
height: '45px',
72-
width: '146px',
73-
marginTop: '23px',
74-
marginLeft: '35px',
75-
borderRadius: '2px'
76-
}
77-
// input: { // commented out b/c Typescript/Material doesn't allow 'input' in its styles object
78-
// color: '#fff',
79-
// opacity: '0.7',
80-
// marginBottom: '15px'
81-
// }
82-
});
83-
8423
const mapDispatchToProps = (dispatch: any) => ({
8524
updateHtmlAttr: ({ attr, value }: { attr: string; value: string }) => {
8625
dispatch(updateHtmlAttr({ attr, value }));
@@ -126,14 +65,6 @@ class HtmlAttr extends Component<HTMLAttrPropsInt, StateInt> {
12665
| React.ChangeEvent<HTMLInputElement>
12766
| React.ChangeEvent<HTMLSelectElement>
12867
) => {
129-
// if ( -- COMMENTED OUT UNNEEDED CODE. DROPDOWN ONLY HAS THOSE THREE OPTIONS. REMOVE THIS EVENTUALLY.
130-
// event.target.value == 'button' ||
131-
// event.target.value == 'submit' ||
132-
// event.target.value == 'reset'
133-
// ) {
134-
// buttonTypeTemp = event.target.value;
135-
// }
136-
13768
// reassigns global variable for use by other listener functions
13869
buttonTypeTemp = event.target.value;
13970

@@ -180,15 +111,17 @@ class HtmlAttr extends Component<HTMLAttrPropsInt, StateInt> {
180111
condition to render a "select" component rather than a text-input component */}
181112
{attr == 'type' ? (
182113
<FormControl required>
183-
<InputLabel className={classes.selectLabel} htmlFor='htmlType'>
114+
<InputLabel className={classes.selectLabel} htmlFor="htmlType">
184115
Type
185116
</InputLabel>
186117
<Select
187118
native
188119
className={classes.select}
189-
id='htmlType'
190-
placeholder='title'
191-
onChange={event => this.handleChange(event)}
120+
id="htmlType"
121+
placeholder="title"
122+
onChange={(event: React.ChangeEvent<HTMLSelectElement>) =>
123+
this.handleChange(event)
124+
}
192125
value={buttonTypeTemp}
193126
defaultValue={`${``}`}
194127
required
@@ -202,32 +135,27 @@ class HtmlAttr extends Component<HTMLAttrPropsInt, StateInt> {
202135
classes: {
203136
root: classes.cssLabel,
204137
focused: classes.cssFocused
205-
// input: classes.inputLabel -- commented out because 'input' not valid on Material typing
206138
}
207139
}}
208140
InputProps={{
209141
className: classes.input
210142
}}
211143
label={attr}
212-
variant='outlined'
144+
variant="outlined"
213145
id={attr}
214-
onChange={this.handleChange}
146+
onChange={(event: React.ChangeEvent<HTMLInputElement>) =>
147+
this.handleChange
148+
}
215149
value={this.state[attr]}
216150
/>
217151
)}
218152
</Grid>
219153
<Grid item xs={2}>
220154
<Fab
221-
variant='extended'
222-
size='small'
223-
color='default'
224-
aria-label='Save'
225-
// style={{
226-
// marginLeft: '10px',
227-
// marginTop: '5px',
228-
// marginBottom: '10px',
229-
// border: '2px solid pink'
230-
// }}
155+
variant="extended"
156+
size="small"
157+
color="default"
158+
aria-label="Save"
231159
className={classes.save}
232160
onClick={e => {
233161
e.preventDefault();
@@ -255,6 +183,57 @@ class HtmlAttr extends Component<HTMLAttrPropsInt, StateInt> {
255183
}
256184
}
257185

186+
const styles = (theme: Theme): any => ({
187+
root: {
188+
display: 'flex',
189+
justifyContent: 'center',
190+
flexWrap: 'wrap',
191+
height: '30px',
192+
width: '15rem',
193+
marginTop: '1rem',
194+
borderRadius: '5px'
195+
},
196+
cssLabel: {
197+
color: 'white',
198+
marginTop: '10px'
199+
},
200+
cssFocused: {
201+
color: 'green'
202+
},
203+
input: {
204+
color: '#fff',
205+
opacity: '0.7',
206+
height: '45px',
207+
width: '146px',
208+
marginTop: '20px',
209+
borderRadius: '5px',
210+
border: '1px solid #33eb91'
211+
},
212+
select: {
213+
background: '#424242',
214+
height: '45px',
215+
width: '146px',
216+
marginTop: '0px',
217+
color: '#fff',
218+
paddingLeft: '14px',
219+
borderRadius: '5px'
220+
},
221+
selectLabel: {
222+
color: 'white',
223+
zIndex: '10',
224+
dropShadow: '1px 1px 3px #fff',
225+
marginTop: '10px'
226+
},
227+
228+
save: {
229+
height: '45px',
230+
width: '146px',
231+
marginTop: '23px',
232+
marginLeft: '35px',
233+
borderRadius: '2px'
234+
}
235+
});
236+
258237
export default connect(
259238
mapStateToProps,
260239
mapDispatchToProps

src/reducers/leftReducers.ts

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,12 +466,57 @@ export const editComponent = (
466466
let toEdit = components.find((element: ComponentInt) => element.id === id);
467467
toEdit.title = title;
468468

469+
// code preview edit mode resets if component name is changed
470+
if (!state.codeReadOnly) {
471+
const check = window.confirm(
472+
`Are you sure you want to change the name of the ${state.focusComponent.title} component while the program is in the "Edit Mode"? \n\nAll of the changes to the "Code Preview" for the ${state.focusComponent.title} component will be overridden!`
473+
);
474+
if (!check) {
475+
return {
476+
...state
477+
};
478+
}
479+
}
480+
481+
// remove whitespace and digits, capitalize first char
482+
const strippedTitle = title
483+
.replace(/[a-z]+/gi, word => word[0].toUpperCase() + word.slice(1))
484+
.replace(/[-_\s0-9\W]+/gi, '');
485+
// duplicate component names not allowed
486+
if (
487+
state.components.find(
488+
(comp: ComponentInt) => comp.title === strippedTitle
489+
) &&
490+
toEdit.title !== strippedTitle
491+
) {
492+
window.alert(
493+
`A component with the name: "${strippedTitle}" already exists.\nPlease think of another name.`
494+
);
495+
return {
496+
...state
497+
};
498+
}
499+
500+
// empty component name not allowed
501+
if (strippedTitle === '') {
502+
window.alert(
503+
`Can't leave the name of the component blank.\nPlease enter a name.`
504+
);
505+
return {
506+
...state
507+
};
508+
}
509+
toEdit.title = strippedTitle;
510+
toEdit.changed = true;
511+
469512
for (const [index, each] of components.entries()) {
513+
each.changed = true;
470514
// iterate over each components array that contains its children (components it renders)
471515
for (const value of each.childrenArray) {
472516
// rename each instance of this component in all components children arrays
473517
// so there is no broken chain of hierarchy (all components are updated with the renamed component)
474518
if (value.childComponentId === id) {
519+
value.componentName = strippedTitle;
475520
value.componentName = title;
476521
}
477522
}
@@ -480,8 +525,10 @@ export const editComponent = (
480525
return {
481526
...state,
482527
focusChild: state.initialApplicationFocusChild,
528+
focusComponent: toEdit,
483529
editMode: -1,
484-
components
530+
components,
531+
codeReadOnly: true
485532
};
486533
};
487534

0 commit comments

Comments
 (0)