summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/boards/stores/getters.js
blob: e1891a4d954bcd89c915c7327fe0213f354ab559 (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
import { find } from 'lodash';
import { BoardType, inactiveId, issuableTypes } from '../constants';

export default {
  isGroupBoard: (state) => state.boardType === BoardType.group,
  isProjectBoard: (state) => state.boardType === BoardType.project,
  isSidebarOpen: (state) => state.activeId !== inactiveId,
  isSwimlanesOn: () => false,
  getBoardItemById: (state) => (id) => {
    return state.boardItems[id] || {};
  },

  getBoardItemsByList: (state, getters) => (listId) => {
    const listItemsIds = state.boardItemsByListId[listId] || [];
    return listItemsIds.map((id) => getters.getBoardItemById(id));
  },

  activeBoardItem: (state) => {
    return state.boardItems[state.activeId] || { iid: '', id: '' };
  },

  groupPathForActiveIssue: (_, getters) => {
    const { referencePath = '' } = getters.activeBoardItem;
    return referencePath.slice(0, referencePath.lastIndexOf('/'));
  },

  projectPathForActiveIssue: (_, getters) => {
    const { referencePath = '' } = getters.activeBoardItem;
    return referencePath.slice(0, referencePath.indexOf('#'));
  },

  activeGroupProjects: (state) => {
    return state.groupProjects.filter((p) => !p.archived);
  },

  getListByLabelId: (state) => (labelId) => {
    if (!labelId) {
      return null;
    }
    return find(state.boardLists, (l) => l.label?.id === labelId);
  },

  getListByTitle: (state) => (title) => {
    return find(state.boardLists, (l) => l.title === title);
  },

  isIssueBoard: (state) => {
    return state.issuableType === issuableTypes.issue;
  },

  isEpicBoard: () => {
    return false;
  },

  hasScope: (state) => {
    const { boardConfig } = state;
    if (boardConfig.labels?.length > 0) {
      return true;
    }
    let hasScope = false;
    ['assigneeId', 'iterationCadenceId', 'iterationId', 'milestoneId', 'weight'].forEach((attr) => {
      if (boardConfig[attr] !== null && boardConfig[attr] !== undefined) {
        hasScope = true;
      }
    });
    return hasScope;
  },
};