diff options
Diffstat (limited to 'app/assets/javascripts/issues/list/utils.js')
-rw-r--r-- | app/assets/javascripts/issues/list/utils.js | 82 |
1 files changed, 79 insertions, 3 deletions
diff --git a/app/assets/javascripts/issues/list/utils.js b/app/assets/javascripts/issues/list/utils.js index d053400dd03..37df0c8f9ff 100644 --- a/app/assets/javascripts/issues/list/utils.js +++ b/app/assets/javascripts/issues/list/utils.js @@ -1,3 +1,4 @@ +import produce from 'immer'; import { isPositiveInteger } from '~/lib/utils/number_utils'; import { getParameterByName } from '~/lib/utils/url_utility'; import { __ } from '~/locale'; @@ -5,6 +6,7 @@ import { FILTERED_SEARCH_TERM, OPERATOR_NOT, OPERATOR_OR, + OPERATOR_AFTER, TOKEN_TYPE_ASSIGNEE, TOKEN_TYPE_AUTHOR, TOKEN_TYPE_CONFIDENTIAL, @@ -17,6 +19,15 @@ import { } from '~/vue_shared/components/filtered_search_bar/constants'; import { DEFAULT_PAGE_SIZE } from '~/vue_shared/issuable/list/constants'; import { + WORK_ITEM_TO_ISSUE_MAP, + WIDGET_TYPE_MILESTONE, + WIDGET_TYPE_AWARD_EMOJI, + EMOJI_THUMBSUP, + EMOJI_THUMBSDOWN, + WIDGET_TYPE_ASSIGNEES, + WIDGET_TYPE_LABELS, +} from '~/work_items/constants'; +import { ALTERNATIVE_FILTER, API_PARAM, BLOCKING_ISSUES_ASC, @@ -222,10 +233,10 @@ export const getFilterTokens = (locationSearch) => }; }); -const isNotEmptySearchToken = (token) => +export const isNotEmptySearchToken = (token) => !(token.type === FILTERED_SEARCH_TERM && !token.value.data); -const isSpecialFilter = (type, data) => { +export const isSpecialFilter = (type, data) => { const isAssigneeIdParam = type === TOKEN_TYPE_ASSIGNEE && isPositiveInteger(data) && @@ -236,8 +247,9 @@ const isSpecialFilter = (type, data) => { const getFilterType = ({ type, value: { data, operator } }) => { const isUnionedAuthor = type === TOKEN_TYPE_AUTHOR && operator === OPERATOR_OR; const isUnionedLabel = type === TOKEN_TYPE_LABEL && operator === OPERATOR_OR; + const isAfter = operator === OPERATOR_AFTER; - if (isUnionedAuthor || isUnionedLabel) { + if (isUnionedAuthor || isUnionedLabel || isAfter) { return ALTERNATIVE_FILTER; } if (isSpecialFilter(type, data)) { @@ -318,3 +330,67 @@ export const convertToSearchQuery = (filterTokens) => .filter((token) => token.type === FILTERED_SEARCH_TERM && token.value.data) .map((token) => token.value.data) .join(' ') || undefined; + +function findWidget(type, workItem) { + return workItem?.widgets?.find((widget) => widget.type === type); +} + +export function mapWorkItemWidgetsToIssueFields(issuesList, workItem) { + return produce(issuesList, (draftData) => { + const activeItem = draftData.project.issues.nodes.find((issue) => issue.iid === workItem.iid); + + Object.keys(WORK_ITEM_TO_ISSUE_MAP).forEach((type) => { + const currentWidget = findWidget(type, workItem); + if (!currentWidget) { + return; + } + const property = WORK_ITEM_TO_ISSUE_MAP[type]; + + // handling the case for assignees and labels + if ( + property === WORK_ITEM_TO_ISSUE_MAP[WIDGET_TYPE_ASSIGNEES] || + property === WORK_ITEM_TO_ISSUE_MAP[WIDGET_TYPE_LABELS] + ) { + activeItem[property] = { + ...currentWidget[property], + nodes: currentWidget[property].nodes.map((node) => ({ + __persist: true, + ...node, + })), + }; + return; + } + + // handling the case for milestone + if (property === WORK_ITEM_TO_ISSUE_MAP[WIDGET_TYPE_MILESTONE] && currentWidget[property]) { + activeItem[property] = { __persist: true, ...currentWidget[property] }; + return; + } + activeItem[property] = currentWidget[property]; + }); + + activeItem.title = workItem.title; + activeItem.confidential = workItem.confidential; + }); +} + +export function updateUpvotesCount(issuesList, workItem) { + const type = WIDGET_TYPE_AWARD_EMOJI; + const property = WORK_ITEM_TO_ISSUE_MAP[type]; + + return produce(issuesList, (draftData) => { + const activeItem = draftData.project.issues.nodes.find((issue) => issue.iid === workItem.iid); + + const currentWidget = findWidget(type, workItem); + if (!currentWidget) { + return; + } + + const upvotesCount = + currentWidget[property].nodes.filter((emoji) => emoji.name === EMOJI_THUMBSUP)?.length ?? 0; + const downvotesCount = + currentWidget[property].nodes.filter((emoji) => emoji.name === EMOJI_THUMBSDOWN)?.length ?? 0; + activeItem.upvotes = upvotesCount; + activeItem.downvotes = downvotesCount; + }); +} |