Skip to content

Commit

Permalink
Merge pull request #7 from lucassabreu/remove-trello-labels
Browse files Browse the repository at this point in the history
remove default trello labels
  • Loading branch information
lucassabreu authored Feb 25, 2018
2 parents dbf3b48 + fe62996 commit aef2664
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

## [0.1.5] - 2018-02-25

### Added
- Remove default Trello labels

## [0.1.4] - 2018-02-25

### Added
Expand Down
20 changes: 13 additions & 7 deletions src/Origins/Trello.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,11 @@ class Trello extends React.Component {


try {
const currentLabels = (await (await this.fetch({ path: `boards/${boardId}/labels`, query: { fields: 'name' } })).json())
const currentLabels = (await (await this.fetch({ path: `boards/${boardId}/labels`, query: { fields: 'name,color' } })).json())
const createLabelsPromices = TRELLO_LABELS.map(l => this.createLabel(boardId, l, currentLabels))
const removeLabelPromices = COLORS.map(l => this.removeLabel(boardId, l, currentLabels))

await Promise.all(createLabelsPromices)
await Promise.all([...createLabelsPromices, ...removeLabelPromices])
this.setState({
applying: false,
alert: { type: 'success', message: 'Setup completed !' }
Expand Down Expand Up @@ -156,11 +157,15 @@ class Trello extends React.Component {
}))
}

async removeLabel(boardId, { name }) {
await this.fetch(
`https://Trello.com/api/v4/boards/${boardId}/labels?name=${name}`,
'DELETE'
);
async removeLabel(boardId, { name }, currentLabels) {
const cl = currentLabels.filter(cl => cl.color === name && cl.name === "").pop();

if (!cl) {
this.addApplyedLabel(name);
return;
}

await this.fetch({ path: `labels/${cl.id}`, method: 'DELETE' });

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

labelsToAdd={TRELLO_LABELS}
labelsToRemove={COLORS}

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

Expand Down

0 comments on commit aef2664

Please sign in to comment.