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

Pass the moved lane on the onLaneDragEnd callback #240

Merged
merged 3 commits into from
Feb 8, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 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, lane, card }, { 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, lane || card, source, destination))
setBoard(reorderedBoard)
}

Expand Down Expand Up @@ -162,8 +160,8 @@ function ControlledBoard({
when(onCardDragEnd)(callback => callback(card, source, destination))
}

function handleOnLaneDragEnd({ source, destination }) {
when(onLaneDragEnd)(callback => callback(source, destination))
function handleOnLaneDragEnd({ source, destination, lane }) {
when(onLaneDragEnd)(callback => callback(lane, source, destination))
}

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

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

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