Welcome to mirror list, hosted at ThFree Co, Russian Federation.

boards_util.js « boards « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5c8df94ca90aabe113ab383fdb4dbc41ba937d35 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { sortBy } from 'lodash';
import ListIssue from 'ee_else_ce/boards/models/issue';
import { ListType } from './constants';
import { getIdFromGraphQLId } from '~/graphql_shared/utils';

export function getMilestone() {
  return null;
}

export function formatIssue(issue) {
  return new ListIssue({
    ...issue,
    labels: issue.labels?.nodes || [],
    assignees: issue.assignees?.nodes || [],
  });
}

export function formatListIssues(listIssues) {
  const issues = {};

  const listData = listIssues.nodes.reduce((map, list) => {
    const sortedIssues = sortBy(list.issues.nodes, 'relativePosition');
    return {
      ...map,
      [list.id]: sortedIssues.map(i => {
        const id = getIdFromGraphQLId(i.id);

        const listIssue = new ListIssue({
          ...i,
          id,
          labels: i.labels?.nodes || [],
          assignees: i.assignees?.nodes || [],
        });

        issues[id] = listIssue;

        return id;
      }),
    };
  }, {});

  return { listData, issues };
}

export function fullBoardId(boardId) {
  return `gid://gitlab/Board/${boardId}`;
}

export function moveIssueListHelper(issue, fromList, toList) {
  if (toList.type === ListType.label) {
    issue.addLabel(toList.label);
  }
  if (fromList && fromList.type === ListType.label) {
    issue.removeLabel(fromList.label);
  }

  if (toList.type === ListType.assignee) {
    issue.addAssignee(toList.assignee);
  }
  if (fromList && fromList.type === ListType.assignee) {
    issue.removeAssignee(fromList.assignee);
  }

  return issue;
}

export default {
  getMilestone,
  formatIssue,
  formatListIssues,
  fullBoardId,
};