Skip to content

Commit aef2664

Browse files
authored
Merge pull request #7 from lucassabreu/remove-trello-labels
remove default trello labels
2 parents dbf3b48 + fe62996 commit aef2664

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
66

77
## [Unreleased]
88

9+
## [0.1.5] - 2018-02-25
10+
11+
### Added
12+
- Remove default Trello labels
13+
914
## [0.1.4] - 2018-02-25
1015

1116
### Added

src/Origins/Trello.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,11 @@ class Trello extends React.Component {
112112

113113

114114
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())
116116
const createLabelsPromices = TRELLO_LABELS.map(l => this.createLabel(boardId, l, currentLabels))
117+
const removeLabelPromices = COLORS.map(l => this.removeLabel(boardId, l, currentLabels))
117118

118-
await Promise.all(createLabelsPromices)
119+
await Promise.all([...createLabelsPromices, ...removeLabelPromices])
119120
this.setState({
120121
applying: false,
121122
alert: { type: 'success', message: 'Setup completed !' }
@@ -156,11 +157,15 @@ class Trello extends React.Component {
156157
}))
157158
}
158159

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' });
164169

165170
this.setState(({ applyedLabels }) => ({
166171
applyedLabels: [...applyedLabels, name],
@@ -193,6 +198,7 @@ class Trello extends React.Component {
193198
selectedPreject={selectedOption}
194199

195200
labelsToAdd={TRELLO_LABELS}
201+
labelsToRemove={COLORS}
196202

197203
onApply={(selected) => this.handleApply(selected)}
198204

0 commit comments

Comments
 (0)