summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/boards/stores/boards_store.js
diff options
context:
space:
mode:
Diffstat (limited to 'app/assets/javascripts/boards/stores/boards_store.js')
-rw-r--r--app/assets/javascripts/boards/stores/boards_store.js145
1 files changed, 67 insertions, 78 deletions
diff --git a/app/assets/javascripts/boards/stores/boards_store.js b/app/assets/javascripts/boards/stores/boards_store.js
index 36702b6ca5f..f59530ddf8f 100644
--- a/app/assets/javascripts/boards/stores/boards_store.js
+++ b/app/assets/javascripts/boards/stores/boards_store.js
@@ -101,7 +101,7 @@ const boardsStore = {
},
new(listObj) {
const list = this.addList(listObj);
- const backlogList = this.findList('type', 'backlog', 'backlog');
+ const backlogList = this.findList('type', 'backlog');
list
.save()
@@ -124,7 +124,7 @@ const boardsStore = {
},
findIssueLabel(issue, findLabel) {
- return issue.labels.find(label => label.id === findLabel.id);
+ return issue.labels.find((label) => label.id === findLabel.id);
},
goToNextPage(list) {
@@ -182,15 +182,15 @@ const boardsStore = {
}
},
findListIssue(list, id) {
- return list.issues.find(issue => issue.id === id);
+ return list.issues.find((issue) => issue.id === id);
},
- removeList(id, type = 'blank') {
- const list = this.findList('id', id, type);
+ removeList(id) {
+ const list = this.findList('id', id);
if (!list) return;
- this.state.lists = this.state.lists.filter(list => list.id !== id);
+ this.state.lists = this.state.lists.filter((list) => list.id !== id);
},
moveList(listFrom, orderLists) {
orderLists.forEach((id, i) => {
@@ -205,7 +205,7 @@ const boardsStore = {
let moveBeforeId = null;
let moveAfterId = null;
- const listHasIssues = issues.every(issue => list.findIssue(issue.id));
+ const listHasIssues = issues.every((issue) => list.findIssue(issue.id));
if (!listHasIssues) {
if (newIndex !== undefined) {
@@ -223,21 +223,21 @@ const boardsStore = {
}
if (list.label) {
- issues.forEach(issue => issue.addLabel(list.label));
+ issues.forEach((issue) => issue.addLabel(list.label));
}
if (list.assignee) {
if (listFrom && listFrom.type === 'assignee') {
- issues.forEach(issue => issue.removeAssignee(listFrom.assignee));
+ issues.forEach((issue) => issue.removeAssignee(listFrom.assignee));
}
- issues.forEach(issue => issue.addAssignee(list.assignee));
+ issues.forEach((issue) => issue.addAssignee(list.assignee));
}
if (IS_EE && list.milestone) {
if (listFrom && listFrom.type === 'milestone') {
- issues.forEach(issue => issue.removeMilestone(listFrom.milestone));
+ issues.forEach((issue) => issue.removeMilestone(listFrom.milestone));
}
- issues.forEach(issue => issue.addMilestone(list.milestone));
+ issues.forEach((issue) => issue.addMilestone(list.milestone));
}
if (listFrom) {
@@ -249,7 +249,7 @@ const boardsStore = {
},
removeListIssues(list, removeIssue) {
- list.issues = list.issues.filter(issue => {
+ list.issues = list.issues.filter((issue) => {
const matchesRemove = removeIssue.id === issue.id;
if (matchesRemove) {
@@ -261,9 +261,9 @@ const boardsStore = {
});
},
removeListMultipleIssues(list, removeIssues) {
- const ids = removeIssues.map(issue => issue.id);
+ const ids = removeIssues.map((issue) => issue.id);
- list.issues = list.issues.filter(issue => {
+ list.issues = list.issues.filter((issue) => {
const matchesRemove = ids.includes(issue.id);
if (matchesRemove) {
@@ -289,9 +289,9 @@ const boardsStore = {
},
moveMultipleIssuesToList({ listFrom, listTo, issues, newIndex }) {
- const issueTo = issues.map(issue => listTo.findIssue(issue.id));
- const issueLists = issues.map(issue => issue.getLists()).flat();
- const listLabels = issueLists.map(list => list.label);
+ const issueTo = issues.map((issue) => listTo.findIssue(issue.id));
+ const issueLists = issues.map((issue) => issue.getLists()).flat();
+ const listLabels = issueLists.map((list) => list.label);
const hasMoveableIssues = issueTo.filter(Boolean).length > 0;
if (!hasMoveableIssues) {
@@ -299,30 +299,30 @@ const boardsStore = {
if (
listTo.type === ListType.assignee &&
listFrom.type === ListType.assignee &&
- issues.some(issue => issue.findAssignee(listTo.assignee))
+ issues.some((issue) => issue.findAssignee(listTo.assignee))
) {
- const targetIssues = issues.map(issue => listTo.findIssue(issue.id));
- targetIssues.forEach(targetIssue => targetIssue.removeAssignee(listFrom.assignee));
+ const targetIssues = issues.map((issue) => listTo.findIssue(issue.id));
+ targetIssues.forEach((targetIssue) => targetIssue.removeAssignee(listFrom.assignee));
} else if (listTo.type === 'milestone') {
- const currentMilestones = issues.map(issue => issue.milestone);
+ const currentMilestones = issues.map((issue) => issue.milestone);
const currentLists = this.state.lists
- .filter(list => list.type === 'milestone' && list.id !== listTo.id)
- .filter(list =>
- list.issues.some(listIssue => issues.some(issue => listIssue.id === issue.id)),
+ .filter((list) => list.type === 'milestone' && list.id !== listTo.id)
+ .filter((list) =>
+ list.issues.some((listIssue) => issues.some((issue) => listIssue.id === issue.id)),
);
- issues.forEach(issue => {
- currentMilestones.forEach(milestone => {
+ issues.forEach((issue) => {
+ currentMilestones.forEach((milestone) => {
issue.removeMilestone(milestone);
});
});
- issues.forEach(issue => {
+ issues.forEach((issue) => {
issue.addMilestone(listTo.milestone);
});
- currentLists.forEach(currentList => {
- issues.forEach(issue => {
+ currentLists.forEach((currentList) => {
+ issues.forEach((issue) => {
currentList.removeIssue(issue);
});
});
@@ -334,36 +334,36 @@ const boardsStore = {
}
} else {
listTo.updateMultipleIssues(issues, listFrom);
- issues.forEach(issue => {
+ issues.forEach((issue) => {
issue.removeLabel(listFrom.label);
});
}
if (listTo.type === ListType.closed && listFrom.type !== ListType.backlog) {
- issueLists.forEach(list => {
- issues.forEach(issue => {
+ issueLists.forEach((list) => {
+ issues.forEach((issue) => {
list.removeIssue(issue);
});
});
- issues.forEach(issue => {
+ issues.forEach((issue) => {
issue.removeLabels(listLabels);
});
} else if (listTo.type === ListType.backlog && listFrom.type === ListType.assignee) {
- issues.forEach(issue => {
+ issues.forEach((issue) => {
issue.removeAssignee(listFrom.assignee);
});
- issueLists.forEach(list => {
- issues.forEach(issue => {
+ issueLists.forEach((list) => {
+ issues.forEach((issue) => {
list.removeIssue(issue);
});
});
} else if (listTo.type === ListType.backlog && listFrom.type === ListType.milestone) {
- issues.forEach(issue => {
+ issues.forEach((issue) => {
issue.removeMilestone(listFrom.milestone);
});
- issueLists.forEach(list => {
- issues.forEach(issue => {
+ issueLists.forEach((list) => {
+ issues.forEach((issue) => {
list.removeIssue(issue);
});
});
@@ -380,8 +380,8 @@ const boardsStore = {
if (issues.length === 1) return true;
// Create list of ids for issues involved.
- const listIssueIds = list.issues.map(issue => issue.id);
- const movedIssueIds = issues.map(issue => issue.id);
+ const listIssueIds = list.issues.map((issue) => issue.id);
+ const movedIssueIds = issues.map((issue) => issue.id);
// Check if moved issue IDs is sub-array
// of source list issue IDs (i.e. contiguous selection).
@@ -391,7 +391,7 @@ const boardsStore = {
moveIssueToList(listFrom, listTo, issue, newIndex) {
const issueTo = listTo.findIssue(issue.id);
const issueLists = issue.getLists();
- const listLabels = issueLists.map(listIssue => listIssue.label);
+ const listLabels = issueLists.map((listIssue) => listIssue.label);
if (!issueTo) {
// Check if target list assignee is already present in this issue
@@ -405,12 +405,12 @@ const boardsStore = {
} else if (listTo.type === 'milestone') {
const currentMilestone = issue.milestone;
const currentLists = this.state.lists
- .filter(list => list.type === 'milestone' && list.id !== listTo.id)
- .filter(list => list.issues.some(listIssue => issue.id === listIssue.id));
+ .filter((list) => list.type === 'milestone' && list.id !== listTo.id)
+ .filter((list) => list.issues.some((listIssue) => issue.id === listIssue.id));
issue.removeMilestone(currentMilestone);
issue.addMilestone(listTo.milestone);
- currentLists.forEach(currentList => currentList.removeIssue(issue));
+ currentLists.forEach((currentList) => currentList.removeIssue(issue));
listTo.addIssue(issue, listFrom, newIndex);
} else {
// Add to new lists issues if it doesn't already exist
@@ -422,7 +422,7 @@ const boardsStore = {
}
if (listTo.type === 'closed' && listFrom.type !== 'backlog') {
- issueLists.forEach(list => {
+ issueLists.forEach((list) => {
list.removeIssue(issue);
});
issue.removeLabels(listLabels);
@@ -461,18 +461,11 @@ const boardsStore = {
moveAfterId: afterId,
});
},
- findList(key, val, type = 'label') {
- const filteredList = this.state.lists.filter(list => {
- const byType = type
- ? list.type === type || list.type === 'assignee' || list.type === 'milestone'
- : true;
-
- return list[key] === val && byType;
- });
- return filteredList[0];
+ findList(key, val) {
+ return this.state.lists.find((list) => list[key] === val);
},
findListByLabelId(id) {
- return this.state.lists.find(list => list.type === 'label' && list.label.id === id);
+ return this.state.lists.find((list) => list.type === 'label' && list.label.id === id);
},
toggleFilter(filter) {
@@ -589,8 +582,8 @@ const boardsStore = {
}
return this.createList(entity.id, entityType)
- .then(res => res.data)
- .then(data => {
+ .then((res) => res.data)
+ .then((data) => {
list.id = data.id;
list.type = data.list_type;
list.position = data.position;
@@ -607,7 +600,7 @@ const boardsStore = {
};
if (list.label && data.label_name) {
- data.label_name = data.label_name.filter(label => label !== list.label.title);
+ data.label_name = data.label_name.filter((label) => label !== list.label.title);
}
if (emptyIssues) {
@@ -615,8 +608,8 @@ const boardsStore = {
}
return this.getIssuesForList(list.id, data)
- .then(res => res.data)
- .then(data => {
+ .then((res) => res.data)
+ .then((data) => {
list.loading = false;
list.issuesSize = data.size;
@@ -624,7 +617,7 @@ const boardsStore = {
list.issues = [];
}
- data.issues.forEach(issueObj => {
+ data.issues.forEach((issueObj) => {
list.addIssue(new ListIssue(issueObj));
});
@@ -634,7 +627,7 @@ const boardsStore = {
getIssuesForList(id, filter = {}) {
const data = { id };
- Object.keys(filter).forEach(key => {
+ Object.keys(filter).forEach((key) => {
data[key] = filter[key];
});
@@ -670,13 +663,13 @@ const boardsStore = {
},
moveListMultipleIssues({ list, issues, oldIndicies, newIndex, moveBeforeId, moveAfterId }) {
- oldIndicies.reverse().forEach(index => {
+ oldIndicies.reverse().forEach((index) => {
list.issues.splice(index, 1);
});
list.issues.splice(newIndex, 0, ...issues);
return this.moveMultipleIssues({
- ids: issues.map(issue => issue.id),
+ ids: issues.map((issue) => issue.id),
fromListId: null,
toListId: null,
moveBeforeId,
@@ -703,8 +696,8 @@ const boardsStore = {
}
return this.newIssue(list.id, issue)
- .then(res => res.data)
- .then(data => list.onNewIssueResponse(issue, data));
+ .then((res) => res.data)
+ .then((data) => list.onNewIssueResponse(issue, data));
},
getBacklog(data) {
@@ -717,7 +710,7 @@ const boardsStore = {
},
removeIssueLabel(issue, removeLabel) {
if (removeLabel) {
- issue.labels = issue.labels.filter(label => removeLabel.id !== label.id);
+ issue.labels = issue.labels.filter((label) => removeLabel.id !== label.id);
}
},
@@ -753,16 +746,12 @@ const boardsStore = {
return axios.get(this.state.endpoints.recentBoardsEndpoint);
},
- deleteBoard({ id }) {
- return axios.delete(this.generateBoardsPath(id));
- },
-
setCurrentBoard(board) {
this.state.currentBoard = board;
},
toggleMultiSelect(issue) {
- const selectedIssueIds = this.multiSelect.list.map(issue => issue.id);
+ const selectedIssueIds = this.multiSelect.list.map((issue) => issue.id);
const index = selectedIssueIds.indexOf(issue.id);
if (index === -1) {
@@ -777,12 +766,12 @@ const boardsStore = {
},
removeIssueAssignee(issue, removeAssignee) {
if (removeAssignee) {
- issue.assignees = issue.assignees.filter(assignee => assignee.id !== removeAssignee.id);
+ issue.assignees = issue.assignees.filter((assignee) => assignee.id !== removeAssignee.id);
}
},
findIssueAssignee(issue, findAssignee) {
- return issue.assignees.find(assignee => assignee.id === findAssignee.id);
+ return issue.assignees.find((assignee) => assignee.id === findAssignee.id);
},
clearMultiSelect() {
@@ -837,11 +826,11 @@ const boardsStore = {
}
if (obj.labels) {
- issue.labels = obj.labels.map(label => new ListLabel(label));
+ issue.labels = obj.labels.map((label) => new ListLabel(label));
}
if (obj.assignees) {
- issue.assignees = obj.assignees.map(a => new ListAssignee(a));
+ issue.assignees = obj.assignees.map((a) => new ListAssignee(a));
}
},
addIssueLabel(issue, label) {