2020-09-10 05:08:27 -04:00
|
|
|
import { sortBy } from 'lodash';
|
2020-12-11 10:10:04 -05:00
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2020-09-10 05:08:27 -04:00
|
|
|
import { ListType } from './constants';
|
2020-08-17 17:09:56 -04:00
|
|
|
import { getIdFromGraphQLId } from '~/graphql_shared/utils';
|
2020-10-14 05:08:46 -04:00
|
|
|
import boardsStore from '~/boards/stores/boards_store';
|
2020-08-13 05:10:09 -04:00
|
|
|
|
2019-04-29 07:06:13 -04:00
|
|
|
export function getMilestone() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-10-14 05:08:46 -04:00
|
|
|
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-09-10 05:08:27 -04:00
|
|
|
export function formatIssue(issue) {
|
2020-11-24 01:09:49 -05:00
|
|
|
return {
|
2020-09-10 05:08:27 -04:00
|
|
|
...issue,
|
|
|
|
labels: issue.labels?.nodes || [],
|
|
|
|
assignees: issue.assignees?.nodes || [],
|
2020-11-24 01:09:49 -05:00
|
|
|
};
|
2020-09-10 05:08:27 -04:00
|
|
|
}
|
|
|
|
|
2020-08-13 05:10:09 -04:00
|
|
|
export function formatListIssues(listIssues) {
|
2020-09-02 14:10:40 -04:00
|
|
|
const issues = {};
|
2020-10-08 11:08:17 -04:00
|
|
|
let listIssuesCount;
|
2020-09-02 14:10:40 -04:00
|
|
|
|
|
|
|
const listData = listIssues.nodes.reduce((map, list) => {
|
2020-10-08 11:08:17 -04:00
|
|
|
listIssuesCount = list.issues.count;
|
|
|
|
let sortedIssues = list.issues.edges.map(issueNode => ({
|
|
|
|
...issueNode.node,
|
|
|
|
}));
|
|
|
|
sortedIssues = sortBy(sortedIssues, 'relativePosition');
|
|
|
|
|
2020-08-13 05:10:09 -04:00
|
|
|
return {
|
|
|
|
...map,
|
2020-09-10 05:08:27 -04:00
|
|
|
[list.id]: sortedIssues.map(i => {
|
2020-09-02 14:10:40 -04:00
|
|
|
const id = getIdFromGraphQLId(i.id);
|
|
|
|
|
2020-11-24 01:09:49 -05:00
|
|
|
const listIssue = {
|
2020-09-02 14:10:40 -04:00
|
|
|
...i,
|
|
|
|
id,
|
|
|
|
labels: i.labels?.nodes || [],
|
|
|
|
assignees: i.assignees?.nodes || [],
|
2020-11-24 01:09:49 -05:00
|
|
|
};
|
2020-09-02 14:10:40 -04:00
|
|
|
|
|
|
|
issues[id] = listIssue;
|
|
|
|
|
|
|
|
return id;
|
|
|
|
}),
|
2020-08-13 05:10:09 -04:00
|
|
|
};
|
|
|
|
}, {});
|
2020-09-02 14:10:40 -04:00
|
|
|
|
2020-10-08 11:08:17 -04: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 05:10:09 -04:00
|
|
|
}
|
|
|
|
|
2020-08-24 08:10:17 -04:00
|
|
|
export function fullBoardId(boardId) {
|
|
|
|
return `gid://gitlab/Board/${boardId}`;
|
|
|
|
}
|
|
|
|
|
2020-10-14 05:08:46 -04: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 05:08:27 -04:00
|
|
|
export function moveIssueListHelper(issue, fromList, toList) {
|
2020-11-24 01:09:49 -05:00
|
|
|
const updatedIssue = issue;
|
|
|
|
if (
|
|
|
|
toList.type === ListType.label &&
|
|
|
|
!updatedIssue.labels.find(label => label.id === toList.label.id)
|
|
|
|
) {
|
|
|
|
updatedIssue.labels.push(toList.label);
|
2020-09-10 05:08:27 -04:00
|
|
|
}
|
2020-11-24 01:09:49 -05:00
|
|
|
if (fromList?.label && fromList.type === ListType.label) {
|
|
|
|
updatedIssue.labels = updatedIssue.labels.filter(label => fromList.label.id !== label.id);
|
2020-09-10 05:08:27 -04:00
|
|
|
}
|
|
|
|
|
2020-11-24 01:09:49 -05:00
|
|
|
if (
|
|
|
|
toList.type === ListType.assignee &&
|
|
|
|
!updatedIssue.assignees.find(assignee => assignee.id === toList.assignee.id)
|
|
|
|
) {
|
|
|
|
updatedIssue.assignees.push(toList.assignee);
|
2020-09-10 05:08:27 -04:00
|
|
|
}
|
2020-11-24 01:09:49 -05:00
|
|
|
if (fromList?.assignee && fromList.type === ListType.assignee) {
|
|
|
|
updatedIssue.assignees = updatedIssue.assignees.filter(
|
|
|
|
assignee => assignee.id !== fromList.assignee.id,
|
|
|
|
);
|
2020-09-10 05:08:27 -04:00
|
|
|
}
|
|
|
|
|
2020-11-24 01:09:49 -05:00
|
|
|
return updatedIssue;
|
2020-09-10 05:08:27 -04:00
|
|
|
}
|
|
|
|
|
2020-12-11 10:10:04 -05: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 });
|
|
|
|
}
|
|
|
|
|
2019-04-29 07:06:13 -04:00
|
|
|
export default {
|
|
|
|
getMilestone,
|
2020-09-10 05:08:27 -04:00
|
|
|
formatIssue,
|
2020-08-13 05:10:09 -04:00
|
|
|
formatListIssues,
|
2020-09-10 05:08:27 -04:00
|
|
|
fullBoardId,
|
2020-10-14 05:08:46 -04:00
|
|
|
fullLabelId,
|
2020-12-11 10:10:04 -05:00
|
|
|
getBoardsPath,
|
2019-04-29 07:06:13 -04:00
|
|
|
};
|