2021-04-14 00:10:39 +00:00
|
|
|
import { sortBy, cloneDeep } from 'lodash';
|
2020-08-17 21:09:56 +00:00
|
|
|
import { getIdFromGraphQLId } from '~/graphql_shared/utils';
|
2021-02-04 09:09:30 +00:00
|
|
|
import { ListType, NOT_FILTER } from './constants';
|
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;
|
2021-01-19 09:10:32 +00:00
|
|
|
let { position } = listObj;
|
2020-12-14 21:09:47 +00:00
|
|
|
if (listType === ListType.closed) {
|
|
|
|
position = Infinity;
|
|
|
|
} else if (listType === ListType.backlog) {
|
|
|
|
position = -Infinity;
|
|
|
|
}
|
|
|
|
|
2021-01-19 09:10:32 +00:00
|
|
|
return { ...listObj, position };
|
2020-12-14 21:09:47 +00:00
|
|
|
}
|
|
|
|
|
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) {
|
2021-02-22 09:10:46 +00:00
|
|
|
const boardItems = {};
|
|
|
|
let listItemsCount;
|
2020-09-02 18:10:40 +00:00
|
|
|
|
|
|
|
const listData = listIssues.nodes.reduce((map, list) => {
|
2021-02-22 09:10:46 +00:00
|
|
|
listItemsCount = list.issues.count;
|
2020-12-23 21:10:24 +00:00
|
|
|
let sortedIssues = list.issues.edges.map((issueNode) => ({
|
2020-10-08 15:08:17 +00:00
|
|
|
...issueNode.node,
|
|
|
|
}));
|
|
|
|
sortedIssues = sortBy(sortedIssues, 'relativePosition');
|
|
|
|
|
2020-08-13 09:10:09 +00:00
|
|
|
return {
|
|
|
|
...map,
|
2020-12-23 21:10:24 +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
|
|
|
|
2021-02-22 09:10:46 +00:00
|
|
|
boardItems[id] = listIssue;
|
2020-09-02 18:10:40 +00:00
|
|
|
|
|
|
|
return id;
|
|
|
|
}),
|
2020-08-13 09:10:09 +00:00
|
|
|
};
|
|
|
|
}, {});
|
2020-09-02 18:10:40 +00:00
|
|
|
|
2021-02-22 09:10:46 +00:00
|
|
|
return { listData, boardItems, listItemsCount };
|
2020-10-08 15:08:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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-12-17 06:10:13 +00:00
|
|
|
export function fullIterationId(id) {
|
|
|
|
return `gid://gitlab/Iteration/${id}`;
|
|
|
|
}
|
|
|
|
|
2021-01-18 09:11:05 +00:00
|
|
|
export function fullUserId(id) {
|
|
|
|
return `gid://gitlab/User/${id}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function fullMilestoneId(id) {
|
|
|
|
return `gid://gitlab/Milestone/${id}`;
|
|
|
|
}
|
|
|
|
|
2020-10-14 09:08:46 +00:00
|
|
|
export function fullLabelId(label) {
|
2021-01-18 09:11:05 +00:00
|
|
|
if (label.project_id && label.project_id !== null) {
|
2020-10-14 09:08:46 +00:00
|
|
|
return `gid://gitlab/ProjectLabel/${label.id}`;
|
|
|
|
}
|
|
|
|
return `gid://gitlab/GroupLabel/${label.id}`;
|
|
|
|
}
|
|
|
|
|
2021-01-18 09:11:05 +00:00
|
|
|
export function formatIssueInput(issueInput, boardConfig) {
|
|
|
|
const { labelIds = [], assigneeIds = [] } = issueInput;
|
|
|
|
const { labels, assigneeId, milestoneId } = boardConfig;
|
|
|
|
|
|
|
|
return {
|
|
|
|
milestoneId: milestoneId ? fullMilestoneId(milestoneId) : null,
|
|
|
|
...issueInput,
|
|
|
|
labelIds: [...labelIds, ...(labels?.map((l) => fullLabelId(l)) || [])],
|
|
|
|
assigneeIds: [...assigneeIds, ...(assigneeId ? [fullUserId(assigneeId)] : [])],
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-04-14 00:10:39 +00:00
|
|
|
export function shouldCloneCard(fromListType, toListType) {
|
|
|
|
const involvesClosed = fromListType === ListType.closed || toListType === ListType.closed;
|
|
|
|
const involvesBacklog = fromListType === ListType.backlog || toListType === ListType.backlog;
|
|
|
|
|
|
|
|
if (involvesClosed || involvesBacklog) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fromListType !== toListType) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getMoveData(state, params) {
|
|
|
|
const { boardItems, boardItemsByListId, boardLists } = state;
|
|
|
|
const { itemId, fromListId, toListId } = params;
|
|
|
|
const fromListType = boardLists[fromListId].listType;
|
|
|
|
const toListType = boardLists[toListId].listType;
|
|
|
|
|
|
|
|
return {
|
|
|
|
reordering: fromListId === toListId,
|
|
|
|
shouldClone: shouldCloneCard(fromListType, toListType),
|
|
|
|
itemNotInToList: !boardItemsByListId[toListId].includes(itemId),
|
|
|
|
originalIssue: cloneDeep(boardItems[itemId]),
|
|
|
|
originalIndex: boardItemsByListId[fromListId].indexOf(itemId),
|
|
|
|
...params,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-03-11 09:09:36 +00:00
|
|
|
export function moveItemListHelper(item, fromList, toList) {
|
|
|
|
const updatedItem = item;
|
2020-11-24 06:09:49 +00:00
|
|
|
if (
|
2020-12-14 21:09:47 +00:00
|
|
|
toList.listType === ListType.label &&
|
2021-03-11 09:09:36 +00:00
|
|
|
!updatedItem.labels.find((label) => label.id === toList.label.id)
|
2020-11-24 06:09:49 +00:00
|
|
|
) {
|
2021-03-11 09:09:36 +00:00
|
|
|
updatedItem.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) {
|
2021-03-11 09:09:36 +00:00
|
|
|
updatedItem.labels = updatedItem.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 &&
|
2021-03-11 09:09:36 +00:00
|
|
|
!updatedItem.assignees.find((assignee) => assignee.id === toList.assignee.id)
|
2020-11-24 06:09:49 +00:00
|
|
|
) {
|
2021-03-11 09:09:36 +00:00
|
|
|
updatedItem.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) {
|
2021-03-11 09:09:36 +00:00
|
|
|
updatedItem.assignees = updatedItem.assignees.filter(
|
2020-12-23 21:10:24 +00:00
|
|
|
(assignee) => assignee.id !== fromList.assignee.id,
|
2020-11-24 06:09:49 +00:00
|
|
|
);
|
2020-09-10 09:08:27 +00:00
|
|
|
}
|
|
|
|
|
2021-03-11 09:09:36 +00:00
|
|
|
return updatedItem;
|
2020-09-10 09:08:27 +00:00
|
|
|
}
|
|
|
|
|
2020-12-14 21:09:47 +00:00
|
|
|
export function isListDraggable(list) {
|
|
|
|
return list.listType !== ListType.backlog && list.listType !== ListType.closed;
|
|
|
|
}
|
|
|
|
|
2021-02-02 09:09:24 +00:00
|
|
|
export function transformNotFilters(filters) {
|
|
|
|
return Object.keys(filters)
|
|
|
|
.filter((key) => key.startsWith(NOT_FILTER))
|
|
|
|
.reduce((obj, key) => {
|
|
|
|
return {
|
|
|
|
...obj,
|
|
|
|
[key.substring(4, key.length - 1)]: filters[key],
|
|
|
|
};
|
|
|
|
}, {});
|
|
|
|
}
|
|
|
|
|
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-17 06:10:13 +00:00
|
|
|
fullIterationId,
|
2020-12-14 21:09:47 +00:00
|
|
|
isListDraggable,
|
2021-02-02 09:09:24 +00:00
|
|
|
transformNotFilters,
|
2019-04-29 11:06:13 +00:00
|
|
|
};
|