Skip to content

Commit aa6b070

Browse files
committed
Add ability to update card data inline
1 parent 48e88cc commit aa6b070

File tree

9 files changed

+3889
-499
lines changed

9 files changed

+3889
-499
lines changed

src/actions/LaneActions.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export const addCard = createAction('ADD_CARD')
44
export const removeCard = createAction('REMOVE_CARD')
55
export const moveCardAcrossLanes = createAction('MOVE_CARD')
66
export const updateCards = createAction('UPDATE_CARDS')
7+
export const updateCard = createAction('UPDATE_CARD')
78
export const updateLanes = createAction('UPDATE_LANES')
89
export const updateLane = createAction('UPDATE_LANE')
910
export const paginateLane = createAction('PAGINATE_LANE')

src/components/Card.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
Detail,
1010
Footer
1111
} from 'rt/styles/Base'
12+
import InlineInput from 'rt/widgets/InlineInput'
1213
import Tag from './Card/Tag'
1314
import DeleteButton from 'rt/widgets/DeleteButton'
1415

@@ -25,15 +26,22 @@ class Card extends Component {
2526
tagStyle,
2627
onClick,
2728
onDelete,
29+
onChange,
2830
className,
2931
id,
3032
title,
3133
label,
3234
description,
3335
tags,
34-
cardDraggable
36+
cardDraggable,
37+
editable,
38+
t
3539
} = this.props
3640

41+
const updateCard = (card) => {
42+
onChange({...card, id})
43+
}
44+
3745
return (
3846
<MovableCardWrapper
3947
data-id={id}
@@ -42,11 +50,17 @@ class Card extends Component {
4250
className={className}
4351
>
4452
<CardHeader>
45-
<CardTitle draggable={cardDraggable}>{title}</CardTitle>
46-
<CardRightContent>{label}</CardRightContent>
53+
<CardTitle draggable={cardDraggable}>
54+
{editable ? <InlineInput value={title} border placeholder={t('placeholder.title')} resize='vertical' onSave={(value) => updateCard({title: value})} /> : title}
55+
</CardTitle>
56+
<CardRightContent>
57+
{editable ? <InlineInput value={label} border placeholder={t('placeholder.label')} resize='vertical' onSave={(value) => updateCard({label: value})} /> : label}
58+
</CardRightContent>
4759
{showDeleteButton && <DeleteButton onClick={this.onDelete} />}
4860
</CardHeader>
49-
<Detail>{description}</Detail>
61+
<Detail>
62+
{editable ? <InlineInput value={description} border placeholder={t('placeholder.description')} resize='vertical' onSave={(value) => updateCard({description: value})} /> : description}
63+
</Detail>
5064
{tags && tags.length> 0 && (
5165
<Footer>
5266
{tags.map(tag => (

src/controllers/BoardContainer.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ class BoardContainer extends Component {
7676
})
7777
case 'UPDATE_CARDS':
7878
return actions.updateCards({laneId: event.laneId, cards: event.cards})
79+
case 'UPDATE_CARD':
80+
return actions.updateCard({laneId: event.laneId, updatedCard: event.card})
7981
case 'UPDATE_LANES':
8082
return actions.updateLanes(event.lanes)
8183
case 'UPDATE_LANE':
@@ -145,6 +147,7 @@ class BoardContainer extends Component {
145147
'onBeforeCardDelete',
146148
'onCardDelete',
147149
'onCardAdd',
150+
'onCardUpdate',
148151
'onLaneClick',
149152
'laneSortFunction',
150153
'draggable',
@@ -221,6 +224,7 @@ BoardContainer.propTypes = {
221224
onBeforeCardDelete: PropTypes.func,
222225
onCardDelete: PropTypes.func,
223226
onCardAdd: PropTypes.func,
227+
onCardUpdate: PropTypes.func,
224228
onLaneAdd: PropTypes.func,
225229
onLaneDelete: PropTypes.func,
226230
onLaneClick: PropTypes.func,
@@ -253,6 +257,7 @@ BoardContainer.defaultProps = {
253257
handleDragEnd: () => {},
254258
handleLaneDragStart: () => {},
255259
handleLaneDragEnd: () => {},
260+
onCardUpdate: () => {},
256261
onLaneAdd: () => {},
257262
onLaneDelete: () => {},
258263
onCardMoveAcrossLanes: () => {},

src/controllers/Lane.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ class Lane extends Component {
141141
}
142142
}
143143

144+
updateCard = updatedCard => {
145+
this.props.actions.updateCard({laneId: this.props.id, updatedCard})
146+
this.props.onCardUpdate(this.props.id, updatedCard)
147+
}
148+
144149
renderDragContainer = isDraggingOver => {
145150
const {
146151
id,
@@ -170,9 +175,12 @@ class Lane extends Component {
170175
className="react-trello-card"
171176
onDelete={onDeleteCard}
172177
onClick={e => this.handleCardClick(e, card)}
178+
onChange={updatedCard => this.updateCard(updatedCard)}
173179
showDeleteButton={!hideCardDeleteIcon}
174180
tagStyle={tagStyle}
175181
cardDraggable={cardDraggable}
182+
editable={editable}
183+
t={t}
176184
{...card}
177185
/>
178186
)
@@ -292,6 +300,7 @@ Lane.propTypes = {
292300
onBeforeCardDelete: PropTypes.func,
293301
onCardDelete: PropTypes.func,
294302
onCardAdd: PropTypes.func,
303+
onCardUpdate: PropTypes.func,
295304
onLaneDelete: PropTypes.func,
296305
onLaneUpdate: PropTypes.func,
297306
onLaneClick: PropTypes.func,
@@ -312,7 +321,8 @@ Lane.defaultProps = {
312321
label: undefined,
313322
editable: false,
314323
onLaneUpdate: () => {},
315-
onCardAdd: () => {}
324+
onCardAdd: () => {},
325+
onCardUpdate: () => {}
316326
}
317327

318328
const mapDispatchToProps = dispatch => ({

src/helpers/LaneHelper.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,24 @@ const LaneHelper = {
9595
return update(state, {lanes: {$set: lanes}})
9696
},
9797

98+
updateCardForLane: (state, {laneId, updatedCard}) => {
99+
const lanes = state.lanes.map(lane => {
100+
if (lane.id === laneId) {
101+
const cards = lane.cards.map(card => {
102+
if (card.id === updatedCard.id) {
103+
return {...card, ...updatedCard}
104+
} else {
105+
return card
106+
}
107+
})
108+
return update(lane, {cards: {$set: cards}})
109+
} else {
110+
return lane
111+
}
112+
})
113+
return update(state, {lanes: {$set: lanes}})
114+
},
115+
98116
updateLanes: (state, lanes) => {
99117
return {...state, ...{lanes: lanes}}
100118
},

src/reducers/BoardReducer.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ const boardReducer = (state = {lanes: []}, action) => {
1313
return Lh.moveCardAcrossLanes(state, payload)
1414
case 'UPDATE_CARDS':
1515
return Lh.updateCardsForLane(state, payload)
16+
case 'UPDATE_CARD':
17+
return Lh.updateCardForLane(state, payload)
1618
case 'UPDATE_LANES':
1719
return Lh.updateLanes(state, payload)
1820
case 'UPDATE_LANE':

src/styles/Base.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ export const Title = styled.span`
156156
`
157157

158158
export const RightContent = styled.span`
159-
width: 30%;
159+
width: 38%;
160160
text-align: right;
161161
padding-right: 10px;
162162
font-size: 13px;
@@ -266,19 +266,21 @@ export const CardForm = styled.div`
266266
export const InlineInput = styled.textarea`
267267
overflow-x: hidden; /* for Firefox (issue #5) */
268268
word-wrap: break-word;
269-
min-height: 28px;
269+
min-height: 18px;
270270
max-height: 112px; /* optional, but recommended */
271271
resize: none;
272272
width: 100%;
273-
height: 28px;
274-
font-size: 15px;
275-
line-height: 20px;
273+
height: 18px;
274+
font-size: inherit;
275+
font-weight: inherit;
276+
line-height: inherit;
277+
text-align: inherit;
276278
background-color: transparent;
277279
box-shadow: none;
278280
box-sizing: border-box;
279281
border-radius: 3px;
280282
border: 0;
281-
padding: 4px 8px;
283+
padding: 0 8px;
282284
outline: 0;
283285
${props => props.border && css`
284286
&:focus {

stories/EditableBoard.story.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,19 @@ storiesOf('Editable Board', module)
7171
{info: 'Can hide the add card button on specific lanes'}
7272
)
7373
.add(
74-
'Inline Edit Lane Title',
74+
'Inline Edit Lane Title and Cards',
7575
() => {
7676
return (
7777
<Board
7878
data={smallData}
7979
editable
8080
canAddLanes
8181
editLaneTitle
82+
onCardUpdate={ (cardId, data) => debug(`onCardUpdate: ${cardId} -> ${JSON.stringify(data, null, 2)}`)}
8283
onLaneUpdate={ (laneId, data) => debug(`onLaneUpdate: ${laneId} -> ${data.title}`)}
8384
onLaneAdd={t => debug('You added a line with title ' + t.title)}
8485
/>
8586
)
8687
},
87-
{info: 'Allow edit lane title'}
88+
{info: 'Allow edit lane title and cards'}
8889
)

0 commit comments

Comments
 (0)