Skip to content
This repository has been archived by the owner on Feb 17, 2021. It is now read-only.

Commit

Permalink
delete function added to list
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanflorentin committed Aug 18, 2016
1 parent 1973c5e commit c0fe213
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default function (compDef) {
const relationDisplay = props[`${relation}Templates`][`${relation}Display`]
console.log('this component was selected', relationDisplay, props[relation])
return <div key={fieldName}>
<relationDisplay props={props[relation]}/>
<relationDisplay component={props[relation]}/>
<label>{relation}</label>

<Button icon='add' onClick={(e) => {
Expand Down
8 changes: 7 additions & 1 deletion src/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ export default function (compDef) {
onClick={() =>{
props[`select${componentProperName}`](props[listName][index])
props.goBack()
}}/>]}
}}/>,
<Button key='delete' icon='close' floating accent mini
onClick={() =>{
props[`delete${componentProperName}`](props[listName][index])
}}/>
]}
/>
})

Expand Down Expand Up @@ -69,6 +74,7 @@ export default function (compDef) {
ComponentList.propTypes[compDef.listName] = PropTypes.array
ComponentList.propTypes[`deselect${componentProperName}`] = PropTypes.func
ComponentList.propTypes[`select${componentProperName}`] = PropTypes.func
ComponentList.propTypes[`delete${componentProperName}`] = PropTypes.func
ComponentList.propTypes.routing = PropTypes.object
return ComponentList
}
15 changes: 12 additions & 3 deletions src/providers.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,20 +142,29 @@ export default function (compDef) {
return action.list
}
case STORE: {
if (action.component.id === undefined) {
if (action.component.uuid === undefined) {
return [
...state,
Object.assign({}, action.component, {id: uuid.v4()})
Object.assign({}, action.component, {uuid: uuid.v4()})
]
}
const next = state.map((component)=>{
if (component.id === action.component.id) {
if (component.id === action.component.uuid) {
return action.component
}
return component
})
return next
}
case DELETE: {
let next = []
state.map((component) =>{
if (component.uuid !== action.component.uuid) {
next.push(component)
}
})
return next
}
default: {
return state
}
Expand Down

0 comments on commit c0fe213

Please sign in to comment.