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

Commit

Permalink
refactor: Rename renameLane helper to changeLane (#251)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: The exported helper `renameLane(board, lane, newTitle)` to help you to deal with a
controlled board has changed to `changeLane(board, lane, { title: 'New title' })`.
  • Loading branch information
lourenci committed Feb 9, 2020
1 parent 442a9de commit 2f03c1b
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 17 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -411,13 +411,13 @@ When the user removes a card, this callback will be called passing these paramet
| `board` | Your board |
| `lane` | Lane to be removed |

#### `renameLane`
#### `changeLane`

| Arg | Description |
|-|-|
| `board` | Your board |
| `lane` | Lane to be renamed |
| `newtitle` | New title of the lane |
| `object` | Pass a object to be merged with the lane. You can add new props and/or change the existing ones |

#### `addCard`

Expand Down
4 changes: 2 additions & 2 deletions src/components/Board/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { when, partialRight } from '@services/utils'
import DefaultLaneHeader from './components/DefaultLaneHeader'
import DefaultCard from './components/DefaultCard'
import { getCard, getCoordinates, isALaneMove } from './services'
import { moveCard, moveLane, addLane, removeLane, renameLane, addCard, removeCard } from '@services/helpers'
import { moveCard, moveLane, addLane, removeLane, changeLane, addCard, removeCard } from '@services/helpers'

const StyledBoard = styled.div`
padding: 5px;
Expand Down Expand Up @@ -71,7 +71,7 @@ function UncontrolledBoard({
}

function handleLaneRename(lane, title) {
const boardWithRenamedLane = renameLane(board, lane, title)
const boardWithRenamedLane = changeLane(board, lane, { title })
onLaneRename(boardWithRenamedLane, { ...lane, title })
setBoard(boardWithRenamedLane)
}
Expand Down
3 changes: 2 additions & 1 deletion src/components/Board/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ describe('<Board />', () => {
expect(cards[0]).toHaveTextContent(/^1 - Card title - Card content$/)
})

// FIXME It shouldn't be receiving the bag, just the dragging prop?! Maybe, just a typo in spec.
it('passes the card content and the card bag as a parameter to the renderCard prop', () => {
expect(renderCard).toHaveBeenCalledWith(
{ id: 1, title: 'Card title', content: 'Card content' },
Expand Down Expand Up @@ -1195,7 +1196,7 @@ describe('<Board />', () => {
expect(subject.queryAllByTestId('lane')[0]).toHaveTextContent('New title')
})

it('calls the "onLaneRemove" callback passing both the updated board and the renamed lane', () => {
it('calls the "onLaneRename" callback passing both the updated board and the renamed lane', () => {
expect(onLaneRename).toHaveBeenCalledTimes(1)
expect(onLaneRename).toHaveBeenCalledWith(
{
Expand Down
4 changes: 2 additions & 2 deletions src/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import Board, { moveLane, moveCard, addLane, removeLane, renameLane, addCard, removeCard } from './'
import Board, { moveLane, moveCard, addLane, removeLane, changeLane, addCard, removeCard } from './'

it('exports the Component and the helpers', () => {
expect(Board).toEqual(expect.any(Function))
expect(moveLane).toEqual(expect.any(Function))
expect(moveCard).toEqual(expect.any(Function))
expect(addLane).toEqual(expect.any(Function))
expect(removeLane).toEqual(expect.any(Function))
expect(renameLane).toEqual(expect.any(Function))
expect(changeLane).toEqual(expect.any(Function))
expect(addCard).toEqual(expect.any(Function))
expect(removeCard).toEqual(expect.any(Function))
})
10 changes: 5 additions & 5 deletions src/services/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ function removeLane(board, lane) {
return { ...board, lanes: board.lanes.filter(({ id }) => id !== lane.id) }
}

function renameLane(board, lane, newTitle) {
const renamedLanes = replaceElementOfArray(board.lanes)({
function changeLane(board, lane, newLane) {
const changedLanes = replaceElementOfArray(board.lanes)({
when: ({ id }) => id === lane.id,
for: value => ({ ...value, title: newTitle })
for: value => ({ ...value, ...newLane })
})
return { ...board, lanes: renamedLanes }
return { ...board, lanes: changedLanes }
}

function addCard(board, inLane, card, { on } = {}) {
Expand All @@ -75,4 +75,4 @@ function removeCard(board, fromLane, card) {
return { ...board, lanes: filteredLanes }
}

export { moveLane, moveCard, addLane, removeLane, renameLane, addCard, removeCard }
export { moveLane, moveCard, addLane, removeLane, changeLane, addCard, removeCard }
10 changes: 5 additions & 5 deletions src/services/helpers.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { moveLane, moveCard, addLane, removeLane, renameLane, addCard, removeCard } from './helpers'
import { moveLane, moveCard, addLane, removeLane, changeLane, addCard, removeCard } from './helpers'

describe('#moveLane', () => {
it('returns a board with the lane moved to the specified position', () => {
Expand Down Expand Up @@ -102,18 +102,18 @@ describe('#removeLane', () => {
})
})

describe('#renameLane', () => {
it('returns a board with the specified lane renomed to the specified title', () => {
describe('#changeLane', () => {
it('returns a board with the specified lane changed according to passed lane', () => {
const board = {
lanes: [
{ id: 1, title: 'Doing', cards: [{ id: 1 }, { id: 2 }, { id: 3 }] },
{ id: 2, title: 'Done', cards: [{ id: 4 }, { id: 5 }, { id: 6 }] }
]
}

const boardWithTheRenamedLane = renameLane(board, { id: 1 }, 'New title')
const boardWithTheModifiedLane = changeLane(board, { id: 1 }, { title: 'New title' })

expect(boardWithTheRenamedLane).toEqual({
expect(boardWithTheModifiedLane).toEqual({
lanes: [
{ id: 1, title: 'New title', cards: [{ id: 1 }, { id: 2 }, { id: 3 }] },
{ id: 2, title: 'Done', cards: [{ id: 4 }, { id: 5 }, { id: 6 }] }
Expand Down

0 comments on commit 2f03c1b

Please sign in to comment.