Skip to content
This repository has been archived by the owner on Oct 8, 2022. It is now read-only.

Commit

Permalink
Pass the moved lane on the onLaneDragEnd callback (#240)
Browse files Browse the repository at this point in the history
  • Loading branch information
lourenci committed Feb 9, 2020
1 parent 7f9a1a0 commit bc823d4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ When the user moves a lane, this callback will be called passing these parameter
| Arg | Description |
|--------------|------------------------------------------------------- |
| `board` | The modified board |
| `lane` | The moved lane |
| `source` | An object with the lane source `{ fromPosition }` |
| `destination`| An object with the lane destination `{ toPosition }`|

Expand Down
19 changes: 8 additions & 11 deletions src/components/Board/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,9 @@ function UncontrolledBoard({
const handleOnCardDragEnd = partialRight(handleOnDragEnd, { moveCallback: moveCard, notifyCallback: onCardDragEnd })
const handleOnLaneDragEnd = partialRight(handleOnDragEnd, { moveCallback: moveLane, notifyCallback: onLaneDragEnd })

function handleOnDragEnd({ source, destination, card }, { moveCallback, notifyCallback }) {
function handleOnDragEnd({ source, destination, subject }, { moveCallback, notifyCallback }) {
const reorderedBoard = moveCallback(board, source, destination)
when(notifyCallback)(callback =>
card ? callback(reorderedBoard, card, source, destination) : callback(reorderedBoard, source, destination)
)
when(notifyCallback)(callback => callback(reorderedBoard, subject, source, destination))
setBoard(reorderedBoard)
}

Expand Down Expand Up @@ -158,12 +156,11 @@ function ControlledBoard({
disableCardDrag,
disableLaneDrag
}) {
function handleOnCardDragEnd({ source, destination, card }) {
when(onCardDragEnd)(callback => callback(card, source, destination))
}
const handleOnCardDragEnd = partialRight(handleOnDragEnd, { notifyCallback: onCardDragEnd })
const handleOnLaneDragEnd = partialRight(handleOnDragEnd, { notifyCallback: onLaneDragEnd })

function handleOnLaneDragEnd({ source, destination }) {
when(onLaneDragEnd)(callback => callback(source, destination))
function handleOnDragEnd({ source, destination, subject }, { notifyCallback }) {
when(notifyCallback)(callback => callback(subject, source, destination))
}

return (
Expand Down Expand Up @@ -216,8 +213,8 @@ function BoardContainer({
if (!coordinates.source) return

isALaneMove(event.type)
? onLaneDragEnd(coordinates)
: onCardDragEnd({ ...coordinates, card: getCard(board, coordinates.source) })
? onLaneDragEnd({ ...coordinates, subject: board.lanes[coordinates.source.fromPosition] })
: onCardDragEnd({ ...coordinates, subject: getCard(board, coordinates.source) })
}

return (
Expand Down
17 changes: 13 additions & 4 deletions src/components/Board/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,13 @@ describe('<Board />', () => {
})
})

it('calls the onLaneDragEnd callback passing the lane move coordinates', () => {
it('calls the onLaneDragEnd callback passing the lane and the move coordinates', () => {
expect(onLaneDragEnd).toHaveBeenCalledTimes(1)
expect(onLaneDragEnd).toHaveBeenCalledWith({ fromPosition: 0 }, { toPosition: 1 })
expect(onLaneDragEnd).toHaveBeenCalledWith(
expect.objectContaining({ title: 'Lane Backlog' }),
{ fromPosition: 0 },
{ toPosition: 1 }
)
})
})
})
Expand Down Expand Up @@ -690,7 +694,7 @@ describe('<Board />', () => {
})
})

it('calls the onLaneDragEnd callback passing the modified board and the lane move coordinates', () => {
it('calls the onLaneDragEnd callback passing the modified board, the lane, and the lane move coordinates', () => {
const expectedBoard = {
lanes: [
{
Expand Down Expand Up @@ -724,7 +728,12 @@ describe('<Board />', () => {
}

expect(onLaneDragEnd).toHaveBeenCalledTimes(1)
expect(onLaneDragEnd).toHaveBeenCalledWith(expectedBoard, { fromPosition: 0 }, { toPosition: 1 })
expect(onLaneDragEnd).toHaveBeenCalledWith(
expectedBoard,
expect.objectContaining({ title: 'Lane Backlog' }),
{ fromPosition: 0 },
{ toPosition: 1 }
)
})
})
})
Expand Down

0 comments on commit bc823d4

Please sign in to comment.