Commit 413e98bb by hfpp2012 yinsigan

delete

1 parent 179e0aff
...@@ -2,3 +2,7 @@ export const cloneElement = (element) => ({ ...@@ -2,3 +2,7 @@ export const cloneElement = (element) => ({
type: 'CLONE_ELEMENT', type: 'CLONE_ELEMENT',
element element
}) })
export const deleteLastElement = () => ({
type: 'DELETE_LAST_ELEMENT'
})
...@@ -4,7 +4,7 @@ import ReactAddonsUpdate from 'react-addons-update' ...@@ -4,7 +4,7 @@ import ReactAddonsUpdate from 'react-addons-update'
import autobind from 'autobind-decorator' import autobind from 'autobind-decorator'
import { connect } from 'react-redux' import { connect } from 'react-redux'
import { cloneElement } from '../actions/headergroup'; import { cloneElement, deleteLastElement } from '../actions/headergroup';
@autobind @autobind
class ElementGroup extends React.Component { class ElementGroup extends React.Component {
...@@ -25,13 +25,13 @@ class ElementGroup extends React.Component { ...@@ -25,13 +25,13 @@ class ElementGroup extends React.Component {
} }
render() { render() {
const { elements, cloneElement } = this.props const { elements, cloneElement, deleteLastElement } = this.props
return ( return (
<div> <div>
{ {
elements.map(function(element) { elements.map(function(element) {
return ( return (
<Element meta_element={ element } key={ "key_" + element.id } id={ element.id } name={ element.name } initialPos={ element.initialPos } target_type={ element.target_type } handleCloneElement={ cloneElement } handleDeleteElement={ this.deleteElement } handleDeleteLastElement={ this.deleteLastElement } /> <Element meta_element={ element } key={ "key_" + element.id } id={ element.id } name={ element.name } initialPos={ element.initialPos } target_type={ element.target_type } handleCloneElement={ cloneElement } handleDeleteElement={ this.deleteElement } handleDeleteLastElement={ deleteLastElement } />
) )
}.bind(this)) }.bind(this))
} }
...@@ -45,12 +45,15 @@ const mapStateToProps = (state, ownProps) => ({ ...@@ -45,12 +45,15 @@ const mapStateToProps = (state, ownProps) => ({
}) })
const mapDispatchToProps = (dispatch, ownProps) => ({ const mapDispatchToProps = (dispatch, ownProps) => ({
cloneElement: cloneElement cloneElement: (element) => {
dispatch(cloneElement(element))
},
deleteLastElement: () => {
dispatch(deleteLastElement())
}
}) })
const VisibleElementGroup = connect( export default connect(
mapStateToProps, mapStateToProps,
mapDispatchToProps mapDispatchToProps
)(ElementGroup) )(ElementGroup)
export default VisibleElementGroup
...@@ -5,7 +5,15 @@ const init_state = [ ...@@ -5,7 +5,15 @@ const init_state = [
] ]
const headergroup = (state = init_state, action) => { const headergroup = (state = init_state, action) => {
switch (action.type) {
case 'CLONE_ELEMENT':
return [
...state,
action.element
]
default:
return state return state
}
} }
export default headergroup export default headergroup
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!