Skip to content

Commit

Permalink
Merge pull request #12 from ChristianEdwardPadilla/development
Browse files Browse the repository at this point in the history
addChild button functionality started
  • Loading branch information
spincycle01 authored and ChristianEdwardPadilla committed May 18, 2019
2 parents 47352c5 + eea18ea commit 50f9c03
Show file tree
Hide file tree
Showing 3 changed files with 209 additions and 87 deletions.
18 changes: 5 additions & 13 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
{
"extends": [
"plugin:react/recommended",
"airbnb-base"
],
"extends": ["plugin:react/recommended", "airbnb-base"],
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 2018,
"sourceType": "module"
},
"plugins": [
"import",
"react",
"jest",
"jsx-a11y",
"babel"
],
"plugins": ["import", "react", "jest", "jsx-a11y", "babel"],
"parser": "babel-eslint",
"env": {
"browser": true,
Expand All @@ -25,6 +16,7 @@
"jest": true
},
"rules": {
"class-methods-use-this": "off"
"class-methods-use-this": "off",
"linebreak-style": 0
}
}
}
90 changes: 16 additions & 74 deletions src/components/LeftColExpansionPanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,7 @@ const styles = theme => ({

const LeftColExpansionPanel = (props) => {
const {
index,
classes,
focusComponent,
component,
updateComponent,
deleteComponent,
onExpansionPanelChange,
moveToBottom,
moveToTop,
index, classes, focusComponent, component, deleteComponent, addChild,
} = props;
const {
title,
Expand Down Expand Up @@ -149,71 +141,21 @@ const LeftColExpansionPanel = (props) => {
value={color}
onChange={event => updateComponent({ color: event.target.value, index, id })}
/>
</div>
<div className={classes.column}>
<InputLabel className={classes.label} htmlFor='parentSelect'>selectedParents</InputLabel>
<Select
className={classes.light}
multiple
value={parents}
id='parentSelect'
name='parentName'
disabled={selectableParents.length < 1}
onChange={handleParentChange}
input={<Input id='parentSelect' />}
renderValue={selectedP => (
<div className={classes.chips}>
{selectedP.map(parent => (
<Chip
key={parent.id}
label={parent.title}
className={classes.chip}
onDelete={() => handleParentChange(null, parent.id)}
deleteIcon={<RemoveCircleOutlineIcon className={classes.icon} />}
/>
))}
</div>
)}
>
{selectableParents.map(parentObj => (
<MenuItem key={parentObj.id} value={parentObj}>
<ListItemText primary={parentObj.title} />
</MenuItem>
))}
</Select>
</div>
</ExpansionPanelDetails>
<Divider />
<ExpansionPanelActions className={classes.actions}>
<Tooltip title="move layer up">
<IconButton
className={classes.button}
onClick={() => moveToTop(id)}
aria-label='Flip to back'>
<FlipToFrontIcon className={classes.light} />
</IconButton>
</Tooltip>
<Tooltip title="move layer down">
<IconButton
className={classes.button}
onClick={() => moveToBottom(id)}
aria-label='Flip to back'>
<FlipToBackIcon className={classes.light} />
</IconButton>
</Tooltip>
<IconButton
className={classes.button}
onClick={() => {
deleteComponent({
index, id, parentIds,
});
}}
aria-label='Delete'>
<DeleteIcon className={classes.light} />
</IconButton>
</ExpansionPanelActions>
</ExpansionPanel>
</div >
<ListItemSecondaryAction>
<IconButton aria-label="Add">
<AddIcon
style={{ color, float: 'right' }}
onClick={() => {
console.log(title);
addChild(title);
}}
/>
</IconButton>
</ListItemSecondaryAction>
</ListItem>
</List>
</Grid>
</div>
);
};

Expand Down
188 changes: 188 additions & 0 deletions src/containers/LeftContainer.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { compose } from 'redux';
// import PropTypes from 'prop-types';
import FormControl from '@material-ui/core/FormControl';
import TextField from '@material-ui/core/TextField';
import Button from '@material-ui/core/Button';
import AddIcon from '@material-ui/icons/Add';
import Grid from '@material-ui/core/Grid';
import { withStyles } from '@material-ui/core/styles';
import LeftColExpansionPanel from '../components/LeftColExpansionPanel.jsx';
// import createModal from '../utils/createModal.util';
import * as actions from '../actions/components';

const mapDispatchToProps = dispatch => ({
addComponent: ({ title }) => dispatch(actions.addComponent({ title })),
updateComponent: ({
id, index, newParentId = null, color = null, stateful = null,
}) => dispatch(
actions.updateComponent({
id,
index,
newParentId,
color,
stateful,
}),
),
deleteComponent: ({ index, id, parentIds }) => dispatch(actions.deleteComponent({ index, id, parentIds })),
// moveToBottom: componentId => dispatch(actions.moveToBottom(componentId)),
// moveToTop: componentId => dispatch(actions.moveToTop(componentId)),
// openExpansionPanel: component => dispatch(actions.openExpansionPanel(component)),
// deleteAllData: () => dispatch(actions.deleteAllData()),
addChild: ({ title }) => dispatch(actions.addChild({ title })),
});

class LeftContainer extends Component {
state = {
componentName: '',
};

handleChange = (event) => {
this.setState({
[event.target.name]: event.target.value,
});
};

handleAddComponent = () => {
this.props.addComponent({ title: this.state.componentName });
this.setState({
componentName: '',
});
};

render() {
const {
components,
updateComponent,
deleteComponent,
focusComponent,
totalComponents,
classes,
addChild,
} = this.props;
const { componentName } = this.state;

const componentsExpansionPanel = components.map((component, i) => (
<LeftColExpansionPanel
key={component.id}
index={i}
id={component.id}
updateComponent={updateComponent}
component={component}
focusComponent={focusComponent}
addChild={addChild}
/>
));

return (
<div className="column left">
<Grid container alignItems="baseline" align="stretch">
<Grid item xs={10}>
<TextField
id="title-input"
label="Add a new component"
placeholder="AppComponent"
margin="normal"
autoFocus
onChange={this.handleChange}
onKeyPress={(ev) => {
if (ev.key === 'Enter') {
// Do code here
this.handleAddComponent();
ev.preventDefault();
}
}}
value={componentName}
name="componentName"
className={classes.light}
InputProps={{
className: classes.input,
}}
InputLabelProps={{
className: classes.input,
}}
/>
</Grid>
<Grid item xs={2}>
<Button
variant="fab"
mini
color="primary"
className={classes.button}
aria-label="Add"
onClick={this.handleAddComponent}
disabled={!this.state.componentName}
>
<AddIcon />
</Button>
</Grid>
</Grid>
<div className="expansionPanel">{componentsExpansionPanel}</div>
</div>
);
}
}

export default compose(
withStyles(styles),
connect(
null,
mapDispatchToProps,
),
)(LeftContainer);

// LeftContainer.propTypes = {
// components: PropTypes.array.isRequired,
// addComponent: PropTypes.func.isRequired,
// deleteComponent: PropTypes.func.isRequired,
// updateComponent: PropTypes.func.isRequired,
// deleteAllData: PropTypes.func.isRequired,
// moveToBottom: PropTypes.func.isRequired,
// moveToTop: PropTypes.func.isRequired,
// focusComponent: PropTypes.object.isRequired,
// openExpansionPanel: PropTypes.func.isRequired,
// totalComponents: PropTypes.number.isRequired,
// classes: PropTypes.object,
// };

function styles() {
return {
cssLabel: {
color: 'white',

'&$cssFocused': {
color: 'green',
},
},
cssFocused: {},
input: {
color: '#fff',
opacity: '0.7',
marginBottom: '10px',
},
underline: {
color: 'white',
'&::before': {
color: 'white',
},
},
button: {
color: '#fff',

'&:disabled': {
color: 'grey',
},
},
clearButton: {
top: '96%',
position: 'sticky!important',
zIndex: '1',

'&:disabled': {
color: 'grey',
backgroundColor: '#424242',
},
},
};
}

0 comments on commit 50f9c03

Please sign in to comment.