2021-04-14 00:10:39 +00:00
|
|
|
import { sortBy, cloneDeep } from 'lodash';
|
2022-03-08 09:17:44 +00:00
|
|
|
import { TYPE_BOARD, TYPE_ITERATION, TYPE_MILESTONE, TYPE_USER } from '~/graphql_shared/constants';
|
|
|
|
import { isGid, convertToGraphQLId } from '~/graphql_shared/utils';
|
2021-11-30 12:10:26 +00:00
|
|
|
import { ListType, MilestoneIDs, AssigneeFilterType, MilestoneFilterType } 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-06-10 15:10:14 +00:00
|
|
|
listItemsCount = list.issuesCount;
|
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,
|
|
|
|
}));
|
2021-10-08 03:11:43 +00:00
|
|
|
if (list.listType !== ListType.closed) {
|
|
|
|
sortedIssues = sortBy(sortedIssues, 'relativePosition');
|
|
|
|
}
|
2020-10-08 15:08:17 +00:00
|
|
|
|
2020-08-13 09:10:09 +00:00
|
|
|
return {
|
|
|
|
...map,
|
2020-12-23 21:10:24 +00:00
|
|
|
[list.id]: sortedIssues.map((i) => {
|
2021-09-15 03:11:01 +00:00
|
|
|
const { id } = i;
|
2020-09-02 18:10:40 +00:00
|
|
|
|
2020-11-24 06:09:49 +00:00
|
|
|
const listIssue = {
|
2020-09-02 18:10:40 +00:00
|
|
|
...i,
|
|
|
|
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) {
|
2022-03-08 09:17:44 +00:00
|
|
|
if (!boardId) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return convertToGraphQLId(TYPE_BOARD, boardId);
|
2020-08-24 12:10:17 +00:00
|
|
|
}
|
|
|
|
|
2020-12-17 06:10:13 +00:00
|
|
|
export function fullIterationId(id) {
|
2022-03-08 09:17:44 +00:00
|
|
|
return convertToGraphQLId(TYPE_ITERATION, id);
|
2020-12-17 06:10:13 +00:00
|
|
|
}
|
|
|
|
|
2021-01-18 09:11:05 +00:00
|
|
|
export function fullUserId(id) {
|
2022-03-08 09:17:44 +00:00
|
|
|
return convertToGraphQLId(TYPE_USER, id);
|
2021-01-18 09:11:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function fullMilestoneId(id) {
|
2022-03-08 09:17:44 +00:00
|
|
|
return convertToGraphQLId(TYPE_MILESTONE, id);
|
2021-01-18 09:11:05 +00:00
|
|
|
}
|
|
|
|
|
2020-10-14 09:08:46 +00:00
|
|
|
export function fullLabelId(label) {
|
2021-11-02 09:09:49 +00:00
|
|
|
if (isGid(label.id)) {
|
|
|
|
return label.id;
|
|
|
|
}
|
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 {
|
|
|
|
...issueInput,
|
2021-09-07 09:11:43 +00:00
|
|
|
milestoneId:
|
|
|
|
milestoneId && milestoneId !== MilestoneIDs.ANY
|
|
|
|
? fullMilestoneId(milestoneId)
|
|
|
|
: issueInput?.milestoneId,
|
2021-01-18 09:11:05 +00:00
|
|
|
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) {
|
2021-09-21 15:12:11 +00:00
|
|
|
const updatedItem = cloneDeep(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-06-02 12:10:05 +00:00
|
|
|
export const FiltersInfo = {
|
|
|
|
assigneeUsername: {
|
|
|
|
negatedSupport: true,
|
2021-11-30 12:10:26 +00:00
|
|
|
remap: (k, v) => (v === AssigneeFilterType.any ? 'assigneeWildcardId' : k),
|
2021-06-02 12:10:05 +00:00
|
|
|
},
|
|
|
|
assigneeId: {
|
|
|
|
// assigneeId should be renamed to assigneeWildcardId.
|
|
|
|
// Classic boards used 'assigneeId'
|
|
|
|
remap: () => 'assigneeWildcardId',
|
|
|
|
},
|
|
|
|
assigneeWildcardId: {
|
|
|
|
negatedSupport: false,
|
|
|
|
transform: (val) => val.toUpperCase(),
|
|
|
|
},
|
|
|
|
authorUsername: {
|
|
|
|
negatedSupport: true,
|
|
|
|
},
|
|
|
|
labelName: {
|
|
|
|
negatedSupport: true,
|
|
|
|
},
|
|
|
|
milestoneTitle: {
|
|
|
|
negatedSupport: true,
|
2021-11-30 12:10:26 +00:00
|
|
|
remap: (k, v) => (Object.values(MilestoneFilterType).includes(v) ? 'milestoneWildcardId' : k),
|
|
|
|
},
|
|
|
|
milestoneWildcardId: {
|
|
|
|
negatedSupport: true,
|
|
|
|
transform: (val) => val.toUpperCase(),
|
2021-06-02 12:10:05 +00:00
|
|
|
},
|
|
|
|
myReactionEmoji: {
|
|
|
|
negatedSupport: true,
|
|
|
|
},
|
|
|
|
releaseTag: {
|
|
|
|
negatedSupport: true,
|
|
|
|
},
|
2021-08-07 03:08:35 +00:00
|
|
|
types: {
|
|
|
|
negatedSupport: true,
|
|
|
|
},
|
2021-12-09 12:15:43 +00:00
|
|
|
confidential: {
|
|
|
|
negatedSupport: false,
|
|
|
|
transform: (val) => val === 'yes',
|
|
|
|
},
|
2021-06-02 12:10:05 +00:00
|
|
|
search: {
|
|
|
|
negatedSupport: false,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {Object} filters - ex. { search: "foobar", "not[authorUsername]": "root", }
|
|
|
|
* @returns {Object} - ex. [ ["search", "foobar", false], ["authorUsername", "root", true], ]
|
|
|
|
*/
|
|
|
|
const parseFilters = (filters) => {
|
|
|
|
/* eslint-disable-next-line @gitlab/require-i18n-strings */
|
|
|
|
const isNegated = (x) => x.startsWith('not[') && x.endsWith(']');
|
|
|
|
|
|
|
|
return Object.entries(filters).map(([k, v]) => {
|
|
|
|
const isNot = isNegated(k);
|
|
|
|
const filterKey = isNot ? k.slice(4, -1) : k;
|
|
|
|
|
|
|
|
return [filterKey, v, isNot];
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an object of filter key/value pairs used as variables in GraphQL requests.
|
|
|
|
* (warning: filter values are not validated)
|
|
|
|
*
|
|
|
|
* @param {Object} objParam.filters - filters extracted from url params. ex. { search: "foobar", "not[authorUsername]": "root", }
|
|
|
|
* @param {string} objParam.issuableType - issuable type e.g., issue.
|
|
|
|
* @param {Object} objParam.filterInfo - data on filters such as how to transform filter value, if filter can be negated, etc.
|
|
|
|
* @param {Object} objParam.filterFields - data on what filters are available for given issuableType (based on GraphQL schema)
|
|
|
|
*/
|
|
|
|
export const filterVariables = ({ filters, issuableType, filterInfo, filterFields }) =>
|
|
|
|
parseFilters(filters)
|
|
|
|
.map(([k, v, negated]) => {
|
|
|
|
// for legacy reasons, some filters need to be renamed to correct GraphQL fields.
|
|
|
|
const remapAvailable = filterInfo[k]?.remap;
|
|
|
|
const remappedKey = remapAvailable ? filterInfo[k].remap(k, v) : k;
|
|
|
|
|
|
|
|
return [remappedKey, v, negated];
|
|
|
|
})
|
|
|
|
.filter(([k, , negated]) => {
|
|
|
|
// remove unsupported filters (+ check if the filters support negation)
|
|
|
|
const supported = filterFields[issuableType].includes(k);
|
|
|
|
if (supported) {
|
|
|
|
return negated ? filterInfo[k].negatedSupport : true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
})
|
|
|
|
.map(([k, v, negated]) => {
|
|
|
|
// if the filter value needs a special transformation, apply it (e.g., capitalization)
|
|
|
|
const transform = filterInfo[k]?.transform;
|
|
|
|
const newVal = transform ? transform(v) : v;
|
|
|
|
|
|
|
|
return [k, newVal, negated];
|
|
|
|
})
|
|
|
|
.reduce(
|
|
|
|
(acc, [k, v, negated]) => {
|
|
|
|
return negated
|
|
|
|
? {
|
|
|
|
...acc,
|
|
|
|
not: {
|
|
|
|
...acc.not,
|
|
|
|
[k]: v,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
: {
|
|
|
|
...acc,
|
|
|
|
[k]: v,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
{ not: {} },
|
|
|
|
);
|
2021-04-21 00:11:06 +00:00
|
|
|
|
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,
|
2019-04-29 11:06:13 +00:00
|
|
|
};
|