debian-mirror-gitlab/app/assets/javascripts/boards/boards_util.js

147 lines
3.4 KiB
JavaScript
Raw Normal View History

2020-11-24 15:15:51 +05:30
import { sortBy } from 'lodash';
2021-02-22 17:27:13 +05:30
import axios from '~/lib/utils/axios_utils';
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';
2019-07-31 22:56:46 +05:30
export function getMilestone() {
return null;
}
2021-02-22 17:27:13 +05:30
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 };
}
2021-01-03 14:25:43 +05:30
export function formatBoardLists(lists) {
2021-02-22 17:27:13 +05:30
return lists.nodes.reduce((map, list) => {
2021-01-03 14:25:43 +05:30
return {
...map,
2021-02-22 17:27:13 +05:30
[list.id]: updateListPosition(list),
2021-01-03 14:25:43 +05:30
};
}, {});
}
2020-11-24 15:15:51 +05:30
export function formatIssue(issue) {
2021-02-22 17:27:13 +05:30
return {
2020-11-24 15:15:51 +05:30
...issue,
labels: issue.labels?.nodes || [],
assignees: issue.assignees?.nodes || [],
2021-02-22 17:27:13 +05:30
};
2020-11-24 15:15:51 +05:30
}
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);
2021-02-22 17:27:13 +05:30
const listIssue = {
2020-11-24 15:15:51 +05:30
...i,
id,
labels: i.labels?.nodes || [],
assignees: i.assignees?.nodes || [],
2021-02-22 17:27:13 +05:30
};
2020-11-24 15:15:51 +05:30
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) {
2021-02-22 17:27:13 +05:30
const updatedIssue = issue;
if (
toList.listType === ListType.label &&
!updatedIssue.labels.find(label => label.id === toList.label.id)
) {
updatedIssue.labels.push(toList.label);
2020-11-24 15:15:51 +05:30
}
2021-02-22 17:27:13 +05:30
if (fromList?.label && fromList.listType === ListType.label) {
updatedIssue.labels = updatedIssue.labels.filter(label => fromList.label.id !== label.id);
2020-11-24 15:15:51 +05:30
}
2021-02-22 17:27:13 +05:30
if (
toList.listType === ListType.assignee &&
!updatedIssue.assignees.find(assignee => assignee.id === toList.assignee.id)
) {
updatedIssue.assignees.push(toList.assignee);
}
if (fromList?.assignee && fromList.listType === ListType.assignee) {
updatedIssue.assignees = updatedIssue.assignees.filter(
assignee => assignee.id !== fromList.assignee.id,
);
2020-11-24 15:15:51 +05:30
}
2021-02-22 17:27:13 +05:30
return updatedIssue;
}
export function getBoardsPath(endpoint, board) {
const path = `${endpoint}${board.id ? `/${board.id}` : ''}.json`;
if (board.id) {
return axios.put(path, { board });
2020-11-24 15:15:51 +05:30
}
2021-02-22 17:27:13 +05:30
return axios.post(path, { board });
}
export function isListDraggable(list) {
return list.listType !== ListType.backlog && list.listType !== ListType.closed;
}
2020-11-24 15:15:51 +05:30
2021-02-22 17:27:13 +05:30
// EE-specific feature. Find the implementation in the `ee/`-folder
export function transformBoardConfig() {
return '';
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,
2021-02-22 17:27:13 +05:30
getBoardsPath,
isListDraggable,
2019-07-31 22:56:46 +05:30
};