Skip to content

Commit f57e286

Browse files
committed
Merge branch 'improved-editability-cards' of https://github.com/joeyparis/react-trello
2 parents ae68ca9 + aa6b070 commit f57e286

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
@@ -5,6 +5,7 @@ export const updateCard = createAction('UPDATE_CARD')
55
export const removeCard = createAction('REMOVE_CARD')
66
export const moveCardAcrossLanes = createAction('MOVE_CARD')
77
export const updateCards = createAction('UPDATE_CARDS')
8+
export const updateCard = createAction('UPDATE_CARD')
89
export const updateLanes = createAction('UPDATE_LANES')
910
export const updateLane = createAction('UPDATE_LANE')
1011
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
@@ -78,6 +78,8 @@ class BoardContainer extends Component {
7878
})
7979
case 'UPDATE_CARDS':
8080
return actions.updateCards({laneId: event.laneId, cards: event.cards})
81+
case 'UPDATE_CARD':
82+
return actions.updateCard({laneId: event.laneId, updatedCard: event.card})
8183
case 'UPDATE_LANES':
8284
return actions.updateLanes(event.lanes)
8385
case 'UPDATE_LANE':
@@ -147,6 +149,7 @@ class BoardContainer extends Component {
147149
'onBeforeCardDelete',
148150
'onCardDelete',
149151
'onCardAdd',
152+
'onCardUpdate',
150153
'onLaneClick',
151154
'laneSortFunction',
152155
'draggable',
@@ -223,6 +226,7 @@ BoardContainer.propTypes = {
223226
onBeforeCardDelete: PropTypes.func,
224227
onCardDelete: PropTypes.func,
225228
onCardAdd: PropTypes.func,
229+
onCardUpdate: PropTypes.func,
226230
onLaneAdd: PropTypes.func,
227231
onLaneDelete: PropTypes.func,
228232
onLaneClick: PropTypes.func,
@@ -255,6 +259,7 @@ BoardContainer.defaultProps = {
255259
handleDragEnd: () => {},
256260
handleLaneDragStart: () => {},
257261
handleLaneDragEnd: () => {},
262+
onCardUpdate: () => {},
258263
onLaneAdd: () => {},
259264
onLaneDelete: () => {},
260265
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
@@ -117,6 +117,24 @@ const LaneHelper = {
117117
return update(state, {lanes: {$set: lanes}})
118118
},
119119

120+
updateCardForLane: (state, {laneId, updatedCard}) => {
121+
const lanes = state.lanes.map(lane => {
122+
if (lane.id === laneId) {
123+
const cards = lane.cards.map(card => {
124+
if (card.id === updatedCard.id) {
125+
return {...card, ...updatedCard}
126+
} else {
127+
return card
128+
}
129+
})
130+
return update(lane, {cards: {$set: cards}})
131+
} else {
132+
return lane
133+
}
134+
})
135+
return update(state, {lanes: {$set: lanes}})
136+
},
137+
120138
updateLanes: (state, lanes) => {
121139
return {...state, ...{lanes: lanes}}
122140
},

src/reducers/BoardReducer.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ const boardReducer = (state = {lanes: []}, action) => {
1515
return Lh.moveCardAcrossLanes(state, payload)
1616
case 'UPDATE_CARDS':
1717
return Lh.updateCardsForLane(state, payload)
18+
case 'UPDATE_CARD':
19+
return Lh.updateCardForLane(state, payload)
1820
case 'UPDATE_LANES':
1921
return Lh.updateLanes(state, payload)
2022
case 'UPDATE_LANE':

src/styles/Base.js

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

155155
export const RightContent = styled.span`
156-
width: 30%;
156+
width: 38%;
157157
text-align: right;
158158
padding-right: 10px;
159159
font-size: 13px;
@@ -263,19 +263,21 @@ export const CardForm = styled.div`
263263
export const InlineInput = styled.textarea`
264264
overflow-x: hidden; /* for Firefox (issue #5) */
265265
word-wrap: break-word;
266-
min-height: 28px;
266+
min-height: 18px;
267267
max-height: 112px; /* optional, but recommended */
268268
resize: none;
269269
width: 100%;
270-
height: 28px;
271-
font-size: 15px;
272-
line-height: 20px;
270+
height: 18px;
271+
font-size: inherit;
272+
font-weight: inherit;
273+
line-height: inherit;
274+
text-align: inherit;
273275
background-color: transparent;
274276
box-shadow: none;
275277
box-sizing: border-box;
276278
border-radius: 3px;
277279
border: 0;
278-
padding: 4px 8px;
280+
padding: 0 8px;
279281
outline: 0;
280282
${props =>
281283
props.border &&

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)