Skip to content

Commit 430b85b

Browse files
authored
Merge pull request #146 from ahmetcetin/patch-5
allow drop to be cancellable
2 parents be98cc9 + 77f5633 commit 430b85b

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ This is the container component that encapsulates the lanes and cards
9696
| canAddLanes | boolean | Allows new lanes to be added to the board. Default: false |
9797
| addLaneTitle | string | Changes add lane button description. Default: false |
9898
| handleDragStart | function | Callback function triggered when card drag is started: `handleDragStart(cardId, laneId)` |
99-
| handleDragEnd | function | Callback function triggered when card drag ends: `handleDragEnd(cardId, sourceLaneId, targetLaneId, position, cardDetails)` |
99+
| handleDragEnd | function | Callback function triggered when card drag ends, return false if you want to cancel drop: `handleDragEnd(cardId, sourceLaneId, targetLaneId, position, cardDetails)` |
100100
| handleLaneDragStart | function | Callback function triggered when lane drag is started: `handleLaneDragStart(laneId)` |
101101
| handleLaneDragEnd | function | Callback function triggered when lane drag ends: `handleLaneDragEnd(laneId, newPosition, payload)` |
102102
| cardDragClass | string | CSS class to be applied to Card when being dragged |

src/components/Lane.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import PropTypes from 'prop-types'
33
import {bindActionCreators} from 'redux'
44
import {connect} from 'react-redux'
55
import isEqual from 'lodash/isEqual'
6+
import cloneDeep from 'lodash/cloneDeep'
67
import Container from '../dnd/Container'
78
import Draggable from '../dnd/Draggable'
89
import uuidv1 from 'uuid/v1'
@@ -151,13 +152,17 @@ class Lane extends Component {
151152
const {addedIndex, payload} = result
152153
this.setState({isDraggingOver: false})
153154
if (addedIndex != null) {
154-
this.props.actions.moveCardAcrossLanes({
155-
fromLaneId: payload.laneId,
156-
toLaneId: laneId,
157-
cardId: payload.id,
158-
index: addedIndex
159-
})
160-
handleDragEnd && handleDragEnd(payload.id, payload.laneId, laneId, addedIndex, payload)
155+
const newCard = {...cloneDeep(payload), laneId}
156+
const response = handleDragEnd ? handleDragEnd(payload.id, payload.laneId, laneId, addedIndex, newCard) : true
157+
if (response === undefined || !!response) {
158+
this.props.actions.moveCardAcrossLanes({
159+
fromLaneId: payload.laneId,
160+
toLaneId: laneId,
161+
cardId: payload.id,
162+
index: addedIndex
163+
})
164+
}
165+
return response
161166
}
162167
}
163168

0 commit comments

Comments
 (0)