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

Commit

Permalink
Fix the card moving when the lane id is a non-number (#231)
Browse files Browse the repository at this point in the history
  • Loading branch information
lourenci authored Feb 1, 2020
1 parent 593f12c commit b6a6450
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
4 changes: 2 additions & 2 deletions assets/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import getUrlParams from './services/getUrlParams'
const board = {
lanes: [
{
id: 1,
id: '0206c8d7-4d48-4d97-b867-86fc2d21074d',
title: 'Lane Backlog',
cards: [
{
id: 1,
id: '0206c8d7-4d48-4d97-b867-86fc2d21075d',
title: 'Card title 1',
description: 'Card content'
},
Expand Down
2 changes: 1 addition & 1 deletion src/components/Board/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ function BoardContainer({
onCardDragEnd
}) {
function handleOnDragEnd(event) {
const coordinates = getCoordinates(event)
const coordinates = getCoordinates(event, board)
if (!coordinates.source) return

isALaneMove(event.type)
Expand Down
10 changes: 7 additions & 3 deletions src/components/Board/services/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function getCoordinates(event) {
function getCoordinates(event, board) {
if (event.destination === null) return {}

const laneSource = { fromPosition: event.source.index }
Expand All @@ -9,8 +9,8 @@ function getCoordinates(event) {
}

return {
source: { ...laneSource, fromLaneId: parseInt(event.source.droppableId) },
destination: { ...laneDestination, toLaneId: parseInt(event.destination.droppableId) }
source: { ...laneSource, fromLaneId: getLane(board, event.source.droppableId).id },
destination: { ...laneDestination, toLaneId: getLane(board, event.destination.droppableId).id }
}
}

Expand All @@ -23,4 +23,8 @@ function getCard(board, sourceCoordinate) {
return lane.cards[sourceCoordinate.fromPosition]
}

function getLane(board, droppableId) {
return board.lanes.find(({ id }) => String(id) === droppableId)
}

export { getCard, getCoordinates, isALaneMove }
17 changes: 12 additions & 5 deletions src/components/Board/services/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,23 @@ describe('#getCoordinates', () => {
})

describe('when the event is a card move', () => {
const board = {
lanes: [
{ id: 1, cards: [{ id: 1 }] },
{ id: '2', cards: [{ id: 2 }] }
]
}

const event = {
type: 'CARD',
source: { index: 0, droppableId: 0 },
destination: { index: 1, droppableId: 1 }
source: { index: 0, droppableId: '1' },
destination: { index: 1, droppableId: '2' }
}

it('returns the card coordinates', () => {
expect(getCoordinates(event)).toEqual({
destination: { toLaneId: 1, toPosition: 1 },
source: { fromLaneId: 0, fromPosition: 0 }
expect(getCoordinates(event, board)).toEqual({
source: { fromLaneId: 1, fromPosition: 0 },
destination: { toLaneId: '2', toPosition: 1 }
})
})
})
Expand Down

0 comments on commit b6a6450

Please sign in to comment.