2020-09-10 09:08:27 +00:00
|
|
|
import { sortBy } from 'lodash';
|
2020-08-13 09:10:09 +00:00
|
|
|
import ListIssue from 'ee_else_ce/boards/models/issue';
|
2020-09-10 09:08:27 +00:00
|
|
|
import { ListType } from './constants';
|
2020-08-17 21:09:56 +00:00
|
|
|
import { getIdFromGraphQLId } from '~/graphql_shared/utils';
|
2020-08-13 09:10:09 +00:00
|
|
|
|
2019-04-29 11:06:13 +00:00
|
|
|
export function getMilestone() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-09-10 09:08:27 +00:00
|
|
|
export function formatIssue(issue) {
|
|
|
|
return new ListIssue({
|
|
|
|
...issue,
|
|
|
|
labels: issue.labels?.nodes || [],
|
|
|
|
assignees: issue.assignees?.nodes || [],
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-08-13 09:10:09 +00:00
|
|
|
export function formatListIssues(listIssues) {
|
2020-09-02 18:10:40 +00:00
|
|
|
const issues = {};
|
|
|
|
|
|
|
|
const listData = listIssues.nodes.reduce((map, list) => {
|
2020-09-10 09:08:27 +00:00
|
|
|
const sortedIssues = sortBy(list.issues.nodes, 'relativePosition');
|
2020-08-13 09:10:09 +00:00
|
|
|
return {
|
|
|
|
...map,
|
2020-09-10 09:08:27 +00:00
|
|
|
[list.id]: sortedIssues.map(i => {
|
2020-09-02 18:10:40 +00:00
|
|
|
const id = getIdFromGraphQLId(i.id);
|
|
|
|
|
|
|
|
const listIssue = new ListIssue({
|
|
|
|
...i,
|
|
|
|
id,
|
|
|
|
labels: i.labels?.nodes || [],
|
|
|
|
assignees: i.assignees?.nodes || [],
|
|
|
|
});
|
|
|
|
|
|
|
|
issues[id] = listIssue;
|
|
|
|
|
|
|
|
return id;
|
|
|
|
}),
|
2020-08-13 09:10:09 +00:00
|
|
|
};
|
|
|
|
}, {});
|
2020-09-02 18:10:40 +00:00
|
|
|
|
|
|
|
return { listData, issues };
|
2020-08-13 09:10:09 +00:00
|
|
|
}
|
|
|
|
|
2020-08-24 12:10:17 +00:00
|
|
|
export function fullBoardId(boardId) {
|
|
|
|
return `gid://gitlab/Board/${boardId}`;
|
|
|
|
}
|
|
|
|
|
2020-09-10 09:08:27 +00:00
|
|
|
export function moveIssueListHelper(issue, fromList, toList) {
|
|
|
|
if (toList.type === ListType.label) {
|
|
|
|
issue.addLabel(toList.label);
|
|
|
|
}
|
|
|
|
if (fromList && fromList.type === ListType.label) {
|
|
|
|
issue.removeLabel(fromList.label);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (toList.type === ListType.assignee) {
|
|
|
|
issue.addAssignee(toList.assignee);
|
|
|
|
}
|
|
|
|
if (fromList && fromList.type === ListType.assignee) {
|
|
|
|
issue.removeAssignee(fromList.assignee);
|
|
|
|
}
|
|
|
|
|
|
|
|
return issue;
|
|
|
|
}
|
|
|
|
|
2019-04-29 11:06:13 +00:00
|
|
|
export default {
|
|
|
|
getMilestone,
|
2020-09-10 09:08:27 +00:00
|
|
|
formatIssue,
|
2020-08-13 09:10:09 +00:00
|
|
|
formatListIssues,
|
2020-09-10 09:08:27 +00:00
|
|
|
fullBoardId,
|
2019-04-29 11:06:13 +00:00
|
|
|
};
|