2020-11-24 15:15:51 +05:30
|
|
|
import { sortBy } from 'lodash';
|
2020-10-24 23:57:45 +05:30
|
|
|
import ListIssue from 'ee_else_ce/boards/models/issue';
|
2020-11-24 15:15:51 +05:30
|
|
|
import { ListType } from './constants';
|
2020-10-24 23:57:45 +05:30
|
|
|
import { getIdFromGraphQLId } from '~/graphql_shared/utils';
|
2021-01-03 14:25:43 +05:30
|
|
|
import boardsStore from '~/boards/stores/boards_store';
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
export function getMilestone() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
export function formatBoardLists(lists) {
|
|
|
|
const formattedLists = lists.nodes.map(list =>
|
|
|
|
boardsStore.updateListPosition({ ...list, doNotFetchIssues: true }),
|
|
|
|
);
|
|
|
|
return formattedLists.reduce((map, list) => {
|
|
|
|
return {
|
|
|
|
...map,
|
|
|
|
[list.id]: list,
|
|
|
|
};
|
|
|
|
}, {});
|
|
|
|
}
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
export function formatIssue(issue) {
|
|
|
|
return new ListIssue({
|
|
|
|
...issue,
|
|
|
|
labels: issue.labels?.nodes || [],
|
|
|
|
assignees: issue.assignees?.nodes || [],
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
export function formatListIssues(listIssues) {
|
2020-11-24 15:15:51 +05:30
|
|
|
const issues = {};
|
2021-01-03 14:25:43 +05:30
|
|
|
let listIssuesCount;
|
2020-11-24 15:15:51 +05:30
|
|
|
|
|
|
|
const listData = listIssues.nodes.reduce((map, list) => {
|
2021-01-03 14:25:43 +05:30
|
|
|
listIssuesCount = list.issues.count;
|
|
|
|
let sortedIssues = list.issues.edges.map(issueNode => ({
|
|
|
|
...issueNode.node,
|
|
|
|
}));
|
|
|
|
sortedIssues = sortBy(sortedIssues, 'relativePosition');
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
return {
|
|
|
|
...map,
|
2020-11-24 15:15:51 +05:30
|
|
|
[list.id]: sortedIssues.map(i => {
|
|
|
|
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-10-24 23:57:45 +05:30
|
|
|
};
|
|
|
|
}, {});
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
return { listData, issues, listIssuesCount };
|
|
|
|
}
|
|
|
|
|
|
|
|
export function formatListsPageInfo(lists) {
|
|
|
|
const listData = lists.nodes.reduce((map, list) => {
|
|
|
|
return {
|
|
|
|
...map,
|
|
|
|
[list.id]: list.issues.pageInfo,
|
|
|
|
};
|
|
|
|
}, {});
|
|
|
|
return listData;
|
2020-11-24 15:15:51 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
export function fullBoardId(boardId) {
|
|
|
|
return `gid://gitlab/Board/${boardId}`;
|
|
|
|
}
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
export function fullLabelId(label) {
|
|
|
|
if (label.project_id !== null) {
|
|
|
|
return `gid://gitlab/ProjectLabel/${label.id}`;
|
|
|
|
}
|
|
|
|
return `gid://gitlab/GroupLabel/${label.id}`;
|
|
|
|
}
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
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;
|
2020-10-24 23:57:45 +05:30
|
|
|
}
|
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
export default {
|
|
|
|
getMilestone,
|
2020-11-24 15:15:51 +05:30
|
|
|
formatIssue,
|
2020-10-24 23:57:45 +05:30
|
|
|
formatListIssues,
|
2020-11-24 15:15:51 +05:30
|
|
|
fullBoardId,
|
2021-01-03 14:25:43 +05:30
|
|
|
fullLabelId,
|
2019-07-31 22:56:46 +05:30
|
|
|
};
|