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
|
import groupBoardMembers from '~/boards/graphql/group_board_members.query.graphql';
import projectBoardMembers from '~/boards/graphql/project_board_members.query.graphql';
import { BoardType } from './constants';
import boardLabels from './graphql/board_labels.query.graphql';
export default function issueBoardFilters(apollo, fullPath, boardType) {
const isGroupBoard = boardType === BoardType.group;
const isProjectBoard = boardType === BoardType.project;
const transformLabels = ({ data }) => {
return isGroupBoard ? data.group?.labels.nodes || [] : data.project?.labels.nodes || [];
};
const boardAssigneesQuery = () => {
return isGroupBoard ? groupBoardMembers : projectBoardMembers;
};
const fetchAuthors = (authorsSearchTerm) => {
return apollo
.query({
query: boardAssigneesQuery(),
variables: {
fullPath,
search: authorsSearchTerm,
},
})
.then(({ data }) => data.workspace?.assignees.nodes.map(({ user }) => user));
};
const fetchLabels = (labelSearchTerm) => {
return apollo
.query({
query: boardLabels,
variables: {
fullPath,
searchTerm: labelSearchTerm,
isGroup: isGroupBoard,
isProject: isProjectBoard,
},
})
.then(transformLabels);
};
return {
fetchLabels,
fetchAuthors,
};
}
|