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

cache_updates.js « graphql « boards « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 084809e4e602e06d82cadf48fc97d736457300a6 (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import produce from 'immer';
import listQuery from 'ee_else_ce/boards/graphql/board_lists_deferred.query.graphql';
import { listsDeferredQuery } from 'ee_else_ce/boards/constants';

export function removeItemFromList({ query, variables, boardType, id, issuableType, cache }) {
  cache.updateQuery({ query, variables }, (sourceData) =>
    produce(sourceData, (draftData) => {
      const { nodes: items } = draftData[boardType].board.lists.nodes[0][`${issuableType}s`];
      items.splice(
        items.findIndex((item) => item.id === id),
        1,
      );
    }),
  );
}

export function addItemToList({
  query,
  variables,
  boardType,
  issuable,
  newIndex,
  issuableType,
  cache,
}) {
  cache.updateQuery({ query, variables }, (sourceData) =>
    produce(sourceData, (draftData) => {
      const { nodes: items } = draftData[boardType].board.lists.nodes[0][`${issuableType}s`];
      items.splice(newIndex, 0, issuable);
    }),
  );
}

export function updateIssueCountAndWeight({
  fromListId,
  toListId,
  filterParams,
  issuable: issue,
  shouldClone,
  cache,
}) {
  if (!shouldClone) {
    cache.updateQuery(
      {
        query: listQuery,
        variables: { id: fromListId, filters: filterParams },
      },
      ({ boardList }) => ({
        boardList: {
          ...boardList,
          issuesCount: boardList.issuesCount - 1,
          totalWeight: boardList.totalWeight - issue.weight,
        },
      }),
    );
  }

  cache.updateQuery(
    {
      query: listQuery,
      variables: { id: toListId, filters: filterParams },
    },
    ({ boardList }) => ({
      boardList: {
        ...boardList,
        issuesCount: boardList.issuesCount + 1,
        totalWeight: boardList.totalWeight + issue.weight,
      },
    }),
  );
}

export function updateEpicsCount({
  issuableType,
  filterParams,
  fromListId,
  toListId,
  issuable: epic,
  shouldClone,
  cache,
}) {
  const epicWeight = epic.descendantWeightSum.openedIssues + epic.descendantWeightSum.closedIssues;
  if (!shouldClone) {
    cache.updateQuery(
      {
        query: listsDeferredQuery[issuableType].query,
        variables: { id: fromListId, filters: filterParams },
      },
      ({ epicBoardList }) => ({
        epicBoardList: {
          ...epicBoardList,
          metadata: {
            epicsCount: epicBoardList.metadata.epicsCount - 1,
            totalWeight: epicBoardList.metadata.totalWeight - epicWeight,
            ...epicBoardList.metadata,
          },
        },
      }),
    );
  }

  cache.updateQuery(
    {
      query: listsDeferredQuery[issuableType].query,
      variables: { id: toListId, filters: filterParams },
    },
    ({ epicBoardList }) => ({
      epicBoardList: {
        ...epicBoardList,
        metadata: {
          epicsCount: epicBoardList.metadata.epicsCount + 1,
          totalWeight: epicBoardList.metadata.totalWeight + epicWeight,
          ...epicBoardList.metadata,
        },
      },
    }),
  );
}