Skip to content

Commit 4634818

Browse files
committed
fix: Fix the handleDragStart and handleDragEnd callbacks after the DnD re-write
#66
1 parent d833b0f commit 4634818

File tree

5 files changed

+21
-18
lines changed

5 files changed

+21
-18
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ This is the container component that encapsulates the lanes and cards
7575
| draggable | boolean | Makes all cards in the lanes draggable. Default: false |
7676
| editable | boolean | Makes the entire board editable. Allow cards to be added or deleted Default: false |
7777
| handleDragStart | function | Callback function triggered when card drag is started: `handleDragStart(cardId, laneId)` |
78-
| handleDragEnd | function | Callback function triggered when card drag ends: `handleDragEnd(cardId, sourceLaneId, targetLaneId)` |
78+
| handleDragEnd | function | Callback function triggered when card drag ends: `handleDragEnd(cardId, sourceLaneId, targetLaneId, position)` |
7979
| onLaneScroll | function | Called when a lane is scrolled to the end: `onLaneScroll(requestedPage, laneId)` |
8080
| onCardClick | function | Called when a card is clicked: `onCardClick(cardId, metadata, laneId) ` |
8181
| onCardAdd | function | Called when a new card is added: `onCardAdd(card, laneId) ` |

src/components/BoardContainer.js

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,23 @@ class BoardContainer extends Component {
4949
}
5050
}
5151

52+
onDragStart = card => {
53+
const {handleDragStart} = this.props
54+
handleDragStart(card.draggableId, card.source.droppableId)
55+
}
56+
5257
onDragEnd = result => {
58+
const {handleDragEnd} = this.props
5359
const {source, destination, draggableId} = result
54-
destination &&
55-
this.props.actions.moveCardAcrossLanes({
56-
fromLaneId: source.droppableId,
57-
toLaneId: destination.droppableId,
58-
cardId: draggableId,
59-
index: destination.index
60-
})
60+
if (destination) {
61+
this.props.actions.moveCardAcrossLanes({
62+
fromLaneId: source.droppableId,
63+
toLaneId: destination.droppableId,
64+
cardId: draggableId,
65+
index: destination.index
66+
})
67+
handleDragEnd(draggableId, source.droppableId, destination.droppableId, destination.index)
68+
}
6169
}
6270

6371
render() {
@@ -73,8 +81,6 @@ class BoardContainer extends Component {
7381
'laneSortFunction',
7482
'draggable',
7583
'editable',
76-
'handleDragStart',
77-
'handleDragEnd',
7884
'customCardLayout',
7985
'newCardTemplate',
8086
'customLaneHeader',
@@ -83,7 +89,7 @@ class BoardContainer extends Component {
8389
])
8490

8591
return (
86-
<DragDropContext onDragEnd={this.onDragEnd}>
92+
<DragDropContext onDragStart={this.onDragStart} onDragEnd={this.onDragEnd}>
8793
<BoardDiv style={style} {...otherProps}>
8894
{reducerData.lanes.map((lane, index) => {
8995
const {id, droppable, ...otherProps} = lane
@@ -130,6 +136,8 @@ BoardContainer.propTypes = {
130136

131137
BoardContainer.defaultProps = {
132138
onDataChange: () => {},
139+
handleDragStart: () => {},
140+
handleDragEnd: () => {},
133141
editable: false,
134142
draggable: false
135143
}

src/components/Card.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,6 @@ Card.propTypes = {
9090
onClick: PropTypes.func,
9191
onDelete: PropTypes.func,
9292
metadata: PropTypes.object,
93-
handleDragStart: PropTypes.func,
94-
handleDragEnd: PropTypes.func,
9593
cardStyle: PropTypes.object,
9694
tagStyle: PropTypes.object,
9795
customCardLayout: PropTypes.bool,

src/components/Lane.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,6 @@ class Lane extends Component {
155155
index={idx}
156156
customCardLayout={this.props.customCardLayout}
157157
customCard={this.props.children}
158-
handleDragStart={this.props.handleDragStart}
159-
handleDragEnd={this.props.handleDragEnd}
160158
tagStyle={tagStyle}
161159
cardStyle={cardStyle}
162160
moveCard={this.moveCard}
@@ -245,8 +243,6 @@ Lane.propTypes = {
245243
draggable: PropTypes.bool,
246244
droppable: PropTypes.bool,
247245
onLaneScroll: PropTypes.func,
248-
handleDragStart: PropTypes.func,
249-
handleDragEnd: PropTypes.func,
250246
onCardClick: PropTypes.func,
251247
onCardDelete: PropTypes.func,
252248
onCardAdd: PropTypes.func,

stories/DragDrop.story.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ storiesOf('Drag-n-Drop', module).add(
1515
console.log(`laneId: ${laneId}`)
1616
}
1717

18-
const handleDragEnd = (cardId, sourceLaneId, targetLaneId) => {
18+
const handleDragEnd = (cardId, sourceLaneId, targetLaneId, position) => {
1919
console.log('drag ended')
2020
console.log(`cardId: ${cardId}`)
2121
console.log(`sourceLaneId: ${sourceLaneId}`)
2222
console.log(`targetLaneId: ${targetLaneId}`)
23+
console.log(`newPosition: ${position}`)
2324
}
2425

2526
const shouldReceiveNewData = nextData => {

0 commit comments

Comments
 (0)