2020-09-10 09:08:27 +00:00
|
|
|
import { sortBy } from 'lodash';
|
2020-12-11 15:10:04 +00:00
|
|
|
import axios from '~/lib/utils/axios_utils';
|
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-12-14 21:09:47 +00:00
|
|
|
export function updateListPosition(listObj) {
|
|
|
|
const { listType } = listObj;
|
|
|
|
let { position } = listObj;
|
|
|
|
if (listType === ListType.closed) {
|
|
|
|
position = Infinity;
|
|
|
|
} else if (listType === ListType.backlog) {
|
|
|
|
position = -Infinity;
|
|
|
|
}
|
|
|
|
|
|
|
|
return { ...listObj, position };
|
|
|
|
}
|
|
|
|
|
2020-10-14 09:08:46 +00:00
|
|
|
export function formatBoardLists(lists) {
|
2020-12-14 21:09:47 +00:00
|
|
|
return lists.nodes.reduce((map, list) => {
|
2020-10-14 09:08:46 +00:00
|
|
|
return {
|
|
|
|
...map,
|
2020-12-14 21:09:47 +00:00
|
|
|
[list.id]: updateListPosition(list),
|
2020-10-14 09:08:46 +00:00
|
|
|
};
|
|
|
|
}, {});
|
|
|
|
}
|
|
|
|
|
2020-09-10 09:08:27 +00:00
|
|
|
export function formatIssue(issue) {
|
2020-11-24 06:09:49 +00:00
|
|
|
return {
|
2020-09-10 09:08:27 +00:00
|
|
|
...issue,
|
|
|
|
labels: issue.labels?.nodes || [],
|
|
|
|
assignees: issue.assignees?.nodes || [],
|
2020-11-24 06:09:49 +00:00
|
|
|
};
|
2020-09-10 09:08:27 +00:00
|
|
|
}
|
|
|
|
|
2020-08-13 09:10:09 +00:00
|
|
|
export function formatListIssues(listIssues) {
|
2020-09-02 18:10:40 +00:00
|
|
|
const issues = {};
|
2020-10-08 15:08:17 +00:00
|
|
|
let listIssuesCount;
|
2020-09-02 18:10:40 +00:00
|
|
|
|
|
|
|
const listData = listIssues.nodes.reduce((map, list) => {
|
2020-10-08 15:08:17 +00:00
|
|
|
listIssuesCount = list.issues.count;
|
|
|
|
let sortedIssues = list.issues.edges.map(issueNode => ({
|
|
|
|
...issueNode.node,
|
|
|
|
}));
|
|
|
|
sortedIssues = sortBy(sortedIssues, '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);
|
|
|
|
|
2020-11-24 06:09:49 +00:00
|
|
|
const listIssue = {
|
2020-09-02 18:10:40 +00:00
|
|
|
...i,
|
|
|
|
id,
|
|
|
|
labels: i.labels?.nodes || [],
|
|
|
|
assignees: i.assignees?.nodes || [],
|
2020-11-24 06:09:49 +00:00
|
|
|
};
|
2020-09-02 18:10:40 +00:00
|
|
|
|
|
|
|
issues[id] = listIssue;
|
|
|
|
|
|
|
|
return id;
|
|
|
|
}),
|
2020-08-13 09:10:09 +00:00
|
|
|
};
|
|
|
|
}, {});
|
2020-09-02 18:10:40 +00:00
|
|
|
|
2020-10-08 15:08:17 +00:00
|
|
|
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-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-10-14 09:08:46 +00:00
|
|
|
export function fullLabelId(label) {
|
|
|
|
if (label.project_id !== null) {
|
|
|
|
return `gid://gitlab/ProjectLabel/${label.id}`;
|
|
|
|
}
|
|
|
|
return `gid://gitlab/GroupLabel/${label.id}`;
|
|
|
|
}
|
|
|
|
|
2020-09-10 09:08:27 +00:00
|
|
|
export function moveIssueListHelper(issue, fromList, toList) {
|
2020-11-24 06:09:49 +00:00
|
|
|
const updatedIssue = issue;
|
|
|
|
if (
|
2020-12-14 21:09:47 +00:00
|
|
|
toList.listType === ListType.label &&
|
2020-11-24 06:09:49 +00:00
|
|
|
!updatedIssue.labels.find(label => label.id === toList.label.id)
|
|
|
|
) {
|
|
|
|
updatedIssue.labels.push(toList.label);
|
2020-09-10 09:08:27 +00:00
|
|
|
}
|
2020-12-14 21:09:47 +00:00
|
|
|
if (fromList?.label && fromList.listType === ListType.label) {
|
2020-11-24 06:09:49 +00:00
|
|
|
updatedIssue.labels = updatedIssue.labels.filter(label => fromList.label.id !== label.id);
|
2020-09-10 09:08:27 +00:00
|
|
|
}
|
|
|
|
|
2020-11-24 06:09:49 +00:00
|
|
|
if (
|
2020-12-14 21:09:47 +00:00
|
|
|
toList.listType === ListType.assignee &&
|
2020-11-24 06:09:49 +00:00
|
|
|
!updatedIssue.assignees.find(assignee => assignee.id === toList.assignee.id)
|
|
|
|
) {
|
|
|
|
updatedIssue.assignees.push(toList.assignee);
|
2020-09-10 09:08:27 +00:00
|
|
|
}
|
2020-12-14 21:09:47 +00:00
|
|
|
if (fromList?.assignee && fromList.listType === ListType.assignee) {
|
2020-11-24 06:09:49 +00:00
|
|
|
updatedIssue.assignees = updatedIssue.assignees.filter(
|
|
|
|
assignee => assignee.id !== fromList.assignee.id,
|
|
|
|
);
|
2020-09-10 09:08:27 +00:00
|
|
|
}
|
|
|
|
|
2020-11-24 06:09:49 +00:00
|
|
|
return updatedIssue;
|
2020-09-10 09:08:27 +00:00
|
|
|
}
|
|
|
|
|
2020-12-11 15:10:04 +00:00
|
|
|
export function getBoardsPath(endpoint, board) {
|
|
|
|
const path = `${endpoint}${board.id ? `/${board.id}` : ''}.json`;
|
|
|
|
|
|
|
|
if (board.id) {
|
|
|
|
return axios.put(path, { board });
|
|
|
|
}
|
|
|
|
return axios.post(path, { board });
|
|
|
|
}
|
|
|
|
|
2020-12-14 21:09:47 +00:00
|
|
|
export function isListDraggable(list) {
|
|
|
|
return list.listType !== ListType.backlog && list.listType !== ListType.closed;
|
|
|
|
}
|
|
|
|
|
2020-12-16 03:09:46 +00:00
|
|
|
// EE-specific feature. Find the implementation in the `ee/`-folder
|
|
|
|
export function transformBoardConfig() {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
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,
|
2020-10-14 09:08:46 +00:00
|
|
|
fullLabelId,
|
2020-12-11 15:10:04 +00:00
|
|
|
getBoardsPath,
|
2020-12-14 21:09:47 +00:00
|
|
|
isListDraggable,
|
2019-04-29 11:06:13 +00:00
|
|
|
};
|