@@ -112,10 +112,11 @@ class Trello extends React.Component {
112
112
113
113
114
114
try {
115
- const currentLabels = ( await ( await this . fetch ( { path : `boards/${ boardId } /labels` , query : { fields : 'name' } } ) ) . json ( ) )
115
+ const currentLabels = ( await ( await this . fetch ( { path : `boards/${ boardId } /labels` , query : { fields : 'name,color ' } } ) ) . json ( ) )
116
116
const createLabelsPromices = TRELLO_LABELS . map ( l => this . createLabel ( boardId , l , currentLabels ) )
117
+ const removeLabelPromices = COLORS . map ( l => this . removeLabel ( boardId , l , currentLabels ) )
117
118
118
- await Promise . all ( createLabelsPromices )
119
+ await Promise . all ( [ ... createLabelsPromices , ... removeLabelPromices ] )
119
120
this . setState ( {
120
121
applying : false ,
121
122
alert : { type : 'success' , message : 'Setup completed !' }
@@ -156,11 +157,15 @@ class Trello extends React.Component {
156
157
} ) )
157
158
}
158
159
159
- async removeLabel ( boardId , { name } ) {
160
- await this . fetch (
161
- `https://Trello.com/api/v4/boards/${ boardId } /labels?name=${ name } ` ,
162
- 'DELETE'
163
- ) ;
160
+ async removeLabel ( boardId , { name } , currentLabels ) {
161
+ const cl = currentLabels . filter ( cl => cl . color === name && cl . name === "" ) . pop ( ) ;
162
+
163
+ if ( ! cl ) {
164
+ this . addApplyedLabel ( name ) ;
165
+ return ;
166
+ }
167
+
168
+ await this . fetch ( { path : `labels/${ cl . id } ` , method : 'DELETE' } ) ;
164
169
165
170
this . setState ( ( { applyedLabels } ) => ( {
166
171
applyedLabels : [ ...applyedLabels , name ] ,
@@ -193,6 +198,7 @@ class Trello extends React.Component {
193
198
selectedPreject = { selectedOption }
194
199
195
200
labelsToAdd = { TRELLO_LABELS }
201
+ labelsToRemove = { COLORS }
196
202
197
203
onApply = { ( selected ) => this . handleApply ( selected ) }
198
204
0 commit comments