From df55d514b8981f770fe63248e6ad7d4126f7c4c5 Mon Sep 17 00:00:00 2001 From: Leandro Lourenci Date: Sun, 9 Feb 2020 15:09:16 -0300 Subject: [PATCH] refactor: Rename renameLane helper to changeLane (#251) 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' })`. --- README.md | 4 ++-- src/components/Board/index.js | 4 ++-- src/components/Board/index.spec.js | 3 ++- src/index.spec.js | 4 ++-- src/services/helpers.js | 10 +++++----- src/services/helpers.spec.js | 10 +++++----- 6 files changed, 18 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 946ff61a..8295878b 100644 --- a/README.md +++ b/README.md @@ -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` diff --git a/src/components/Board/index.js b/src/components/Board/index.js index d2edacd5..fce91204 100644 --- a/src/components/Board/index.js +++ b/src/components/Board/index.js @@ -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; @@ -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) } diff --git a/src/components/Board/index.spec.js b/src/components/Board/index.spec.js index 1abcb819..a7e76f93 100644 --- a/src/components/Board/index.spec.js +++ b/src/components/Board/index.spec.js @@ -212,6 +212,7 @@ describe('', () => { 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' }, @@ -1195,7 +1196,7 @@ describe('', () => { 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( { diff --git a/src/index.spec.js b/src/index.spec.js index a5d3167d..bcfea27f 100644 --- a/src/index.spec.js +++ b/src/index.spec.js @@ -1,4 +1,4 @@ -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)) @@ -6,7 +6,7 @@ it('exports the Component and the helpers', () => { 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)) }) diff --git a/src/services/helpers.js b/src/services/helpers.js index 94e4a2f8..c3c6fb69 100644 --- a/src/services/helpers.js +++ b/src/services/helpers.js @@ -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 } = {}) { @@ -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 } diff --git a/src/services/helpers.spec.js b/src/services/helpers.spec.js index 864f69d0..a48412ea 100644 --- a/src/services/helpers.spec.js +++ b/src/services/helpers.spec.js @@ -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', () => { @@ -102,8 +102,8 @@ 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 }] }, @@ -111,9 +111,9 @@ describe('#renameLane', () => { ] } - 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 }] }