Commit 413e98bb by hfpp2012 yinsigan

delete

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