1
1
import React , { Component } from 'react'
2
- import PropTypes from 'prop-types'
3
- import pick from 'lodash/pick'
4
- import isEqual from 'lodash/isEqual'
5
- import { BoardDiv } from '../styles/Base'
6
2
import { bindActionCreators } from 'redux'
7
3
import { connect } from 'react-redux'
8
- import Lane from './Lane'
9
4
import Container from '../dnd/Container'
10
5
import Draggable from '../dnd/Draggable'
6
+ import PropTypes from 'prop-types'
7
+ import pick from 'lodash/pick'
8
+ import isEqual from 'lodash/isEqual'
9
+ import { BoardDiv , LaneSection } from '../styles/Base'
10
+ import { NewLaneButton } from '../styles/Elements'
11
+ import Lane from './Lane'
12
+ import NewLane from './NewLane'
13
+
11
14
import * as boardActions from '../actions/BoardActions'
12
15
import * as laneActions from '../actions/LaneActions'
13
16
14
17
class BoardContainer extends Component {
15
- wireEventBus = ( ) => {
16
- const { actions, eventBusHandle} = this . props
17
- let eventBus = {
18
- publish : event => {
19
- switch ( event . type ) {
20
- case 'ADD_CARD' :
21
- return actions . addCard ( { laneId : event . laneId , card : event . card } )
22
- case 'REMOVE_CARD' :
23
- return actions . removeCard ( { laneId : event . laneId , cardId : event . cardId } )
24
- case 'REFRESH_BOARD' :
25
- return actions . loadBoard ( event . data )
26
- case 'MOVE_CARD' :
27
- return actions . moveCardAcrossLanes ( {
28
- fromLaneId : event . fromLaneId ,
29
- toLaneId : event . toLaneId ,
30
- cardId : event . cardId ,
31
- index : event . index
32
- } )
33
- case 'UPDATE_LANES' :
34
- return actions . updateLanes ( event . lanes )
35
- }
36
- }
37
- }
38
- eventBusHandle ( eventBus )
18
+ //+add 2018.08.23
19
+ state = {
20
+ addLaneMode : false
39
21
}
40
22
23
+ //+end
41
24
componentWillMount ( ) {
42
25
const { actions, eventBusHandle} = this . props
43
26
actions . loadBoard ( this . props . data )
@@ -58,27 +41,81 @@ class BoardContainer extends Component {
58
41
}
59
42
}
60
43
61
- getCardDetails = ( laneId , cardIndex ) => {
62
- return this . props . reducerData . lanes . find ( lane => lane . id === laneId ) . cards [ cardIndex ]
63
- }
64
-
65
44
onDragStart = ( { payload} ) => {
66
45
const { handleLaneDragStart} = this . props
67
46
handleLaneDragStart ( payload . id )
68
47
}
69
48
70
49
onLaneDrop = ( { removedIndex, addedIndex, payload} ) => {
71
50
const { actions, handleLaneDragEnd} = this . props
72
- actions . moveLane ( { oldIndex : removedIndex , newIndex : addedIndex } )
73
- handleLaneDragEnd ( payload . id , addedIndex )
51
+ if ( removedIndex !== addedIndex ) { // 2018.08.22
52
+ // actions.moveLane({oldIndex: removedIndex, newIndex: addedIndex});
53
+ handleLaneDragEnd ( removedIndex , addedIndex , payload )
54
+ }
55
+ }
56
+ getCardDetails = ( laneId , cardIndex ) => {
57
+ return this . props . reducerData . lanes . find ( lane => lane . id === laneId ) . cards [ cardIndex ]
74
58
}
75
-
76
59
getLaneDetails = index => {
77
60
return this . props . reducerData . lanes [ index ]
78
61
}
79
62
63
+ wireEventBus = ( ) => {
64
+ const { actions, eventBusHandle} = this . props
65
+ let eventBus = {
66
+ publish : event => {
67
+ switch ( event . type ) {
68
+ case 'ADD_CARD' :
69
+ return actions . addCard ( { laneId : event . laneId , card : event . card } )
70
+ case 'REMOVE_CARD' :
71
+ return actions . removeCard ( { laneId : event . laneId , cardId : event . cardId } )
72
+ case 'REFRESH_BOARD' :
73
+ return actions . loadBoard ( event . data )
74
+ case 'MOVE_CARD' :
75
+ return actions . moveCardAcrossLanes ( {
76
+ fromLaneId : event . fromLaneId ,
77
+ toLaneId : event . toLaneId ,
78
+ cardId : event . cardId ,
79
+ index : event . index
80
+ } ) ;
81
+ case 'UPDATE_LANES' :
82
+ return actions . updateLanes ( event . lanes )
83
+ }
84
+ } ,
85
+ } ;
86
+ eventBusHandle ( eventBus )
87
+ }
88
+
89
+ // + add
90
+ hideEditableLane = ( ) => {
91
+ this . setState ( { addLaneMode : false } )
92
+ }
93
+
94
+ showEditableLane = ( ) => {
95
+ this . setState ( { addLaneMode : true } )
96
+ }
97
+
98
+ addNewLane = params => {
99
+ this . hideEditableLane ( )
100
+ this . props . actions . addLane ( params )
101
+ }
102
+
103
+ renderNewLane = ( ) => {
104
+ const { newLaneTemplate} = this . props
105
+ if ( newLaneTemplate ) {
106
+ const newCardWithProps = React . cloneElement ( newLaneTemplate , {
107
+ onCancel : this . hideEditableLane ,
108
+ onAdd : this . addNewLane
109
+ } )
110
+ return < span > { newCardWithProps } </ span >
111
+ } else {
112
+ return < NewLane onCancel = { this . hideEditableLane } onAdd = { this . addNewLane } />
113
+ }
114
+ }
115
+
80
116
render ( ) {
81
- const { id, reducerData, draggable, laneDraggable, laneDragClass, style, ...otherProps } = this . props
117
+ const { id, reducerData, draggable, laneDraggable, laneDragClass, style, addLaneTitle, editable, ...otherProps } = this . props
118
+ const { addLaneMode} = this . state
82
119
// Stick to whitelisting attributes to segregate board and lane props
83
120
const passthroughProps = pick ( this . props , [
84
121
'onLaneScroll' ,
@@ -94,14 +131,17 @@ class BoardContainer extends Component {
94
131
'editable' ,
95
132
'hideCardDeleteIcon' ,
96
133
'customCardLayout' ,
97
- 'newCardTemplate' ,
98
134
'customLaneHeader' ,
99
135
'tagStyle' ,
100
136
'handleDragStart' ,
101
137
'handleDragEnd' ,
102
138
'cardDragClass' ,
103
- 'children'
104
- ] )
139
+ 'children' ,
140
+ 'addLaneTitle' ,
141
+ 'addCardTitle' ,
142
+ 'newLaneTemplate' ,
143
+ 'newCardTemplate'
144
+ ] ) ;
105
145
106
146
return (
107
147
< BoardDiv style = { style } { ...otherProps } draggable = { false } >
@@ -110,9 +150,10 @@ class BoardContainer extends Component {
110
150
onDragStart = { this . onDragStart }
111
151
dragClass = { laneDragClass }
112
152
onDrop = { this . onLaneDrop }
113
- lockAxis = { 'x' }
153
+ lockAxis = "x"
114
154
getChildPayload = { index => this . getLaneDetails ( index ) }
115
- groupName = { `TrelloBoard${ id } ` } >
155
+ groupName = { `TrelloBoard${ id } ` }
156
+ >
116
157
{ reducerData . lanes . map ( ( lane , index ) => {
117
158
const { id, droppable, ...otherProps } = lane
118
159
const laneToRender = (
@@ -125,16 +166,25 @@ class BoardContainer extends Component {
125
166
{ ...otherProps }
126
167
{ ...passthroughProps }
127
168
/>
128
- )
169
+ ) ;
129
170
return draggable && laneDraggable ? (
130
171
< Draggable key = { lane . id } > { laneToRender } </ Draggable >
131
172
) : (
132
173
< span key = { lane . id } > { laneToRender } </ span >
133
- )
174
+ ) ;
134
175
} ) }
135
176
</ Container >
177
+ < Container
178
+ orientation = "horizontal"
179
+ >
180
+ { editable && ! addLaneMode ? (
181
+ < LaneSection style = { { width : 200 } } >
182
+ < NewLaneButton onClick = { this . showEditableLane } > { addLaneTitle } </ NewLaneButton >
183
+ </ LaneSection >
184
+ ) : ( addLaneMode && this . renderNewLane ( ) ) }
185
+ </ Container >
136
186
</ BoardDiv >
137
- )
187
+ ) ;
138
188
}
139
189
}
140
190
@@ -161,15 +211,17 @@ BoardContainer.propTypes = {
161
211
handleLaneDragStart : PropTypes . func ,
162
212
handleLaneDragEnd : PropTypes . func ,
163
213
customCardLayout : PropTypes . bool ,
164
- newCardTemplate : PropTypes . node ,
165
214
customLaneHeader : PropTypes . element ,
166
215
style : PropTypes . object ,
167
216
tagStyle : PropTypes . object ,
168
217
laneDraggable : PropTypes . bool ,
169
218
cardDraggable : PropTypes . bool ,
170
219
cardDragClass : PropTypes . string ,
171
- laneDragClass : PropTypes . string
172
- }
220
+ laneDragClass : PropTypes . string ,
221
+ addLaneTitle : PropTypes . string ,
222
+ addCardTitle : PropTypes . string ,
223
+ newLaneTemplate : PropTypes . node
224
+ } ;
173
225
174
226
BoardContainer . defaultProps = {
175
227
onDataChange : ( ) => { } ,
@@ -184,12 +236,14 @@ BoardContainer.defaultProps = {
184
236
laneDraggable : true ,
185
237
cardDraggable : true ,
186
238
cardDragClass : 'react_trello_dragClass' ,
187
- laneDragClass : 'react_trello_dragLaneClass'
188
- }
239
+ laneDragClass : 'react_trello_dragLaneClass' ,
240
+ addLaneTitle : '+ Add another lane' ,
241
+ addCardTitle : 'Add Card'
242
+ } ;
189
243
190
244
const mapStateToProps = state => {
191
245
return state . lanes ? { reducerData : state } : { }
192
- }
246
+ } ;
193
247
194
248
const mapDispatchToProps = dispatch => ( { actions : bindActionCreators ( { ...boardActions , ...laneActions } , dispatch ) } )
195
249
0 commit comments