debian-mirror-gitlab/app/assets/javascripts/boards/stores/actions.js

759 lines
21 KiB
JavaScript
Raw Normal View History

2021-04-29 21:17:54 +05:30
import * as Sentry from '@sentry/browser';
2021-01-03 14:25:43 +05:30
import { pick } from 'lodash';
2021-04-17 20:07:23 +05:30
import createBoardListMutation from 'ee_else_ce/boards/graphql/board_list_create.mutation.graphql';
2021-02-22 17:27:13 +05:30
import boardListsQuery from 'ee_else_ce/boards/graphql/board_lists.query.graphql';
2021-04-29 21:17:54 +05:30
import issueMoveListMutation from 'ee_else_ce/boards/graphql/issue_move_list.mutation.graphql';
2021-04-17 20:07:23 +05:30
import {
BoardType,
ListType,
inactiveId,
flashAnimationDuration,
ISSUABLE,
2021-04-29 21:17:54 +05:30
titleQueries,
subscriptionQueries,
2021-04-17 20:07:23 +05:30
} from '~/boards/constants';
2020-11-24 15:15:51 +05:30
import { getIdFromGraphQLId } from '~/graphql_shared/utils';
2021-03-11 19:13:27 +05:30
import createGqClient, { fetchPolicies } from '~/lib/graphql';
2021-02-22 17:27:13 +05:30
import { convertObjectPropsToCamelCase, urlParamsToObject } from '~/lib/utils/common_utils';
2021-04-29 21:17:54 +05:30
import { s__ } from '~/locale';
2021-01-03 14:25:43 +05:30
import {
formatBoardLists,
formatListIssues,
fullBoardId,
formatListsPageInfo,
2021-01-29 00:20:46 +05:30
formatIssue,
2021-03-08 18:12:59 +05:30
formatIssueInput,
updateListPosition,
2021-03-11 19:13:27 +05:30
transformNotFilters,
2021-04-29 21:17:54 +05:30
moveItemListHelper,
getMoveData,
2021-01-03 14:25:43 +05:30
} from '../boards_util';
2021-02-22 17:27:13 +05:30
import boardLabelsQuery from '../graphql/board_labels.query.graphql';
import destroyBoardListMutation from '../graphql/board_list_destroy.mutation.graphql';
2021-03-11 19:13:27 +05:30
import updateBoardListMutation from '../graphql/board_list_update.mutation.graphql';
import groupProjectsQuery from '../graphql/group_projects.query.graphql';
2021-02-22 17:27:13 +05:30
import issueCreateMutation from '../graphql/issue_create.mutation.graphql';
import issueSetDueDateMutation from '../graphql/issue_set_due_date.mutation.graphql';
2021-03-11 19:13:27 +05:30
import issueSetLabelsMutation from '../graphql/issue_set_labels.mutation.graphql';
2021-02-22 17:27:13 +05:30
import issueSetMilestoneMutation from '../graphql/issue_set_milestone.mutation.graphql';
2021-03-11 19:13:27 +05:30
import listsIssuesQuery from '../graphql/lists_issues.query.graphql';
import * as types from './mutation_types';
2020-06-23 00:09:42 +05:30
2019-09-04 21:01:54 +05:30
const notImplemented = () => {
2020-04-22 19:07:51 +05:30
/* eslint-disable-next-line @gitlab/require-i18n-strings */
2019-09-04 21:01:54 +05:30
throw new Error('Not implemented!');
};
2021-01-03 14:25:43 +05:30
export const gqlClient = createGqClient(
{},
{
fetchPolicy: fetchPolicies.NO_CACHE,
},
);
2020-11-24 15:15:51 +05:30
2019-09-04 21:01:54 +05:30
export default {
2020-10-24 23:57:45 +05:30
setInitialBoardData: ({ commit }, data) => {
commit(types.SET_INITIAL_BOARD_DATA, data);
},
2020-11-24 15:15:51 +05:30
setActiveId({ commit }, { id, sidebarType }) {
commit(types.SET_ACTIVE_ID, { id, sidebarType });
2019-09-04 21:01:54 +05:30
},
2020-11-24 15:15:51 +05:30
unsetActiveId({ dispatch }) {
dispatch('setActiveId', { id: inactiveId, sidebarType: '' });
2019-09-04 21:01:54 +05:30
},
2020-11-24 15:15:51 +05:30
setFilters: ({ commit }, filters) => {
const filterParams = pick(filters, [
'assigneeUsername',
'authorUsername',
'labelName',
'milestoneTitle',
'releaseTag',
'search',
2021-04-29 21:17:54 +05:30
'myReactionEmoji',
2020-11-24 15:15:51 +05:30
]);
2021-03-11 19:13:27 +05:30
filterParams.not = transformNotFilters(filters);
2020-11-24 15:15:51 +05:30
commit(types.SET_FILTERS, filterParams);
},
2021-02-22 17:27:13 +05:30
performSearch({ dispatch }) {
dispatch(
'setFilters',
convertObjectPropsToCamelCase(urlParamsToObject(window.location.search)),
);
if (gon.features.graphqlBoardLists) {
dispatch('fetchLists');
dispatch('resetIssues');
}
},
2021-04-17 20:07:23 +05:30
fetchLists: ({ dispatch }) => {
dispatch('fetchIssueLists');
},
fetchIssueLists: ({ commit, state, dispatch }) => {
2021-03-08 18:12:59 +05:30
const { boardType, filterParams, fullPath, boardId } = state;
2020-11-24 15:15:51 +05:30
const variables = {
fullPath,
boardId: fullBoardId(boardId),
2021-01-03 14:25:43 +05:30
filters: filterParams,
isGroup: boardType === BoardType.group,
isProject: boardType === BoardType.project,
2020-11-24 15:15:51 +05:30
};
return gqlClient
.query({
2021-01-03 14:25:43 +05:30
query: boardListsQuery,
2020-11-24 15:15:51 +05:30
variables,
})
.then(({ data }) => {
2021-01-03 14:25:43 +05:30
const { lists, hideBacklogList } = data[boardType]?.board;
commit(types.RECEIVE_BOARD_LISTS_SUCCESS, formatBoardLists(lists));
// Backlog list needs to be created if it doesn't exist and it's not hidden
2021-03-08 18:12:59 +05:30
if (!lists.nodes.find((l) => l.listType === ListType.backlog) && !hideBacklogList) {
2020-11-24 15:15:51 +05:30
dispatch('createList', { backlog: true });
}
})
2021-01-03 14:25:43 +05:30
.catch(() => commit(types.RECEIVE_BOARD_LISTS_FAILURE));
2020-11-24 15:15:51 +05:30
},
2021-03-11 19:13:27 +05:30
highlightList: ({ commit, state }, listId) => {
if ([ListType.backlog, ListType.closed].includes(state.boardLists[listId].listType)) {
return;
}
commit(types.ADD_LIST_TO_HIGHLIGHTED_LISTS, listId);
setTimeout(() => {
commit(types.REMOVE_LIST_FROM_HIGHLIGHTED_LISTS, listId);
}, flashAnimationDuration);
},
2021-04-17 20:07:23 +05:30
createList: ({ dispatch }, { backlog, labelId, milestoneId, assigneeId }) => {
dispatch('createIssueList', { backlog, labelId, milestoneId, assigneeId });
},
createIssueList: (
2021-03-11 19:13:27 +05:30
{ state, commit, dispatch, getters },
2021-04-17 20:07:23 +05:30
{ backlog, labelId, milestoneId, assigneeId, iterationId },
2021-03-11 19:13:27 +05:30
) => {
2021-03-08 18:12:59 +05:30
const { boardId } = state;
2021-01-03 14:25:43 +05:30
2021-03-11 19:13:27 +05:30
const existingList = getters.getListByLabelId(labelId);
if (existingList) {
dispatch('highlightList', existingList.id);
return;
}
2020-11-24 15:15:51 +05:30
gqlClient
.mutate({
mutation: createBoardListMutation,
variables: {
boardId: fullBoardId(boardId),
backlog,
2021-01-03 14:25:43 +05:30
labelId,
milestoneId,
assigneeId,
2021-04-17 20:07:23 +05:30
iterationId,
2020-11-24 15:15:51 +05:30
},
})
.then(({ data }) => {
2021-04-17 20:07:23 +05:30
if (data.boardListCreate?.errors.length) {
commit(types.CREATE_LIST_FAILURE, data.boardListCreate.errors[0]);
2020-11-24 15:15:51 +05:30
} else {
const list = data.boardListCreate?.list;
dispatch('addList', list);
2021-03-11 19:13:27 +05:30
dispatch('highlightList', list.id);
2020-11-24 15:15:51 +05:30
}
})
2021-04-17 20:07:23 +05:30
.catch((e) => {
commit(types.CREATE_LIST_FAILURE);
throw e;
});
2020-11-24 15:15:51 +05:30
},
2021-01-03 14:25:43 +05:30
addList: ({ commit }, list) => {
2021-03-08 18:12:59 +05:30
commit(types.RECEIVE_ADD_LIST_SUCCESS, updateListPosition(list));
2020-11-24 15:15:51 +05:30
},
2021-04-17 20:07:23 +05:30
fetchLabels: ({ state, commit, getters }, searchTerm) => {
2021-03-08 18:12:59 +05:30
const { fullPath, boardType } = state;
2021-01-29 00:20:46 +05:30
const variables = {
fullPath,
searchTerm,
isGroup: boardType === BoardType.group,
isProject: boardType === BoardType.project,
};
2021-04-17 20:07:23 +05:30
commit(types.RECEIVE_LABELS_REQUEST);
2021-01-29 00:20:46 +05:30
return gqlClient
.query({
query: boardLabelsQuery,
variables,
})
.then(({ data }) => {
2021-04-17 20:07:23 +05:30
let labels = data[boardType]?.labels.nodes;
if (!getters.shouldUseGraphQL && !getters.isEpicBoard) {
labels = labels.map((label) => ({
...label,
id: getIdFromGraphQLId(label.id),
}));
}
2021-03-11 19:13:27 +05:30
commit(types.RECEIVE_LABELS_SUCCESS, labels);
return labels;
2021-04-17 20:07:23 +05:30
})
.catch((e) => {
commit(types.RECEIVE_LABELS_FAILURE);
throw e;
2021-03-11 19:13:27 +05:30
});
2021-01-29 00:20:46 +05:30
},
2021-01-03 14:25:43 +05:30
moveList: (
{ state, commit, dispatch },
{ listId, replacedListId, newIndex, adjustmentValue },
) => {
2021-02-22 17:27:13 +05:30
if (listId === replacedListId) {
return;
}
2020-11-24 15:15:51 +05:30
const { boardLists } = state;
2021-01-03 14:25:43 +05:30
const backupList = { ...boardLists };
const movedList = boardLists[listId];
2020-11-24 15:15:51 +05:30
const newPosition = newIndex - 1;
2021-01-03 14:25:43 +05:30
const listAtNewIndex = boardLists[replacedListId];
2020-11-24 15:15:51 +05:30
movedList.position = newPosition;
listAtNewIndex.position += adjustmentValue;
commit(types.MOVE_LIST, {
movedList,
listAtNewIndex,
});
dispatch('updateList', { listId, position: newPosition, backupList });
2019-09-04 21:01:54 +05:30
},
2020-11-24 15:15:51 +05:30
updateList: ({ commit }, { listId, position, collapsed, backupList }) => {
gqlClient
.mutate({
mutation: updateBoardListMutation,
variables: {
listId,
position,
collapsed,
},
})
.then(({ data }) => {
if (data?.updateBoardList?.errors.length) {
commit(types.UPDATE_LIST_FAILURE, backupList);
}
})
.catch(() => {
commit(types.UPDATE_LIST_FAILURE, backupList);
});
2019-09-04 21:01:54 +05:30
},
2021-04-17 20:07:23 +05:30
toggleListCollapsed: ({ commit }, { listId, collapsed }) => {
commit(types.TOGGLE_LIST_COLLAPSED, { listId, collapsed });
},
2021-01-29 00:20:46 +05:30
removeList: ({ state, commit }, listId) => {
const listsBackup = { ...state.boardLists };
commit(types.REMOVE_LIST, listId);
return gqlClient
.mutate({
mutation: destroyBoardListMutation,
variables: {
listId,
},
})
2021-03-08 18:12:59 +05:30
.then(
({
data: {
destroyBoardList: { errors },
},
}) => {
if (errors.length > 0) {
commit(types.REMOVE_LIST_FAILURE, listsBackup);
}
},
)
2021-01-29 00:20:46 +05:30
.catch(() => {
commit(types.REMOVE_LIST_FAILURE, listsBackup);
});
2019-09-04 21:01:54 +05:30
},
2021-04-17 20:07:23 +05:30
fetchItemsForList: ({ state, commit }, { listId, fetchNext = false }) => {
commit(types.REQUEST_ITEMS_FOR_LIST, { listId, fetchNext });
2021-01-03 14:25:43 +05:30
2021-03-08 18:12:59 +05:30
const { fullPath, boardId, boardType, filterParams } = state;
2020-11-24 15:15:51 +05:30
const variables = {
fullPath,
boardId: fullBoardId(boardId),
id: listId,
filters: filterParams,
isGroup: boardType === BoardType.group,
isProject: boardType === BoardType.project,
2021-01-03 14:25:43 +05:30
first: 20,
after: fetchNext ? state.pageInfoByListId[listId].endCursor : undefined,
2020-11-24 15:15:51 +05:30
};
return gqlClient
.query({
query: listsIssuesQuery,
context: {
isSingleRequest: true,
},
variables,
})
.then(({ data }) => {
const { lists } = data[boardType]?.board;
2021-04-17 20:07:23 +05:30
const listItems = formatListIssues(lists);
2021-01-03 14:25:43 +05:30
const listPageInfo = formatListsPageInfo(lists);
2021-04-17 20:07:23 +05:30
commit(types.RECEIVE_ITEMS_FOR_LIST_SUCCESS, { listItems, listPageInfo, listId });
2020-11-24 15:15:51 +05:30
})
2021-04-17 20:07:23 +05:30
.catch(() => commit(types.RECEIVE_ITEMS_FOR_LIST_FAILURE, listId));
2019-09-04 21:01:54 +05:30
},
2021-01-03 14:25:43 +05:30
resetIssues: ({ commit }) => {
commit(types.RESET_ISSUES);
2020-10-24 23:57:45 +05:30
},
2021-04-29 21:17:54 +05:30
moveItem: ({ dispatch }, payload) => {
dispatch('moveIssue', payload);
2021-04-17 20:07:23 +05:30
},
2021-04-29 21:17:54 +05:30
moveIssue: ({ dispatch, state }, params) => {
const moveData = getMoveData(state, params);
dispatch('moveIssueCard', moveData);
dispatch('updateMovedIssue', moveData);
dispatch('updateIssueOrder', { moveData });
},
moveIssueCard: ({ commit }, moveData) => {
const {
reordering,
shouldClone,
itemNotInToList,
originalIndex,
itemId,
fromListId,
toListId,
moveBeforeId,
moveAfterId,
} = moveData;
commit(types.REMOVE_BOARD_ITEM_FROM_LIST, { itemId, listId: fromListId });
if (reordering) {
commit(types.ADD_BOARD_ITEM_TO_LIST, {
itemId,
listId: toListId,
moveBeforeId,
moveAfterId,
});
return;
}
if (itemNotInToList) {
commit(types.ADD_BOARD_ITEM_TO_LIST, {
itemId,
listId: toListId,
moveBeforeId,
moveAfterId,
});
}
if (shouldClone) {
commit(types.ADD_BOARD_ITEM_TO_LIST, { itemId, listId: fromListId, atIndex: originalIndex });
}
},
updateMovedIssue: (
{ commit, state: { boardItems, boardLists } },
{ itemId, fromListId, toListId },
2020-11-24 15:15:51 +05:30
) => {
2021-04-29 21:17:54 +05:30
const updatedIssue = moveItemListHelper(
boardItems[itemId],
boardLists[fromListId],
boardLists[toListId],
);
2020-11-24 15:15:51 +05:30
2021-04-29 21:17:54 +05:30
commit(types.UPDATE_BOARD_ITEM, updatedIssue);
},
2020-11-24 15:15:51 +05:30
2021-04-29 21:17:54 +05:30
undoMoveIssueCard: ({ commit }, moveData) => {
const {
reordering,
shouldClone,
itemNotInToList,
itemId,
fromListId,
toListId,
originalIssue,
originalIndex,
} = moveData;
commit(types.UPDATE_BOARD_ITEM, originalIssue);
if (reordering) {
commit(types.REMOVE_BOARD_ITEM_FROM_LIST, { itemId, listId: fromListId });
commit(types.ADD_BOARD_ITEM_TO_LIST, { itemId, listId: fromListId, atIndex: originalIndex });
return;
}
if (shouldClone) {
commit(types.REMOVE_BOARD_ITEM_FROM_LIST, { itemId, listId: fromListId });
}
if (itemNotInToList) {
commit(types.REMOVE_BOARD_ITEM_FROM_LIST, { itemId, listId: toListId });
}
commit(types.ADD_BOARD_ITEM_TO_LIST, { itemId, listId: fromListId, atIndex: originalIndex });
},
updateIssueOrder: async ({ commit, dispatch, state }, { moveData, mutationVariables = {} }) => {
try {
const { itemId, fromListId, toListId, moveBeforeId, moveAfterId } = moveData;
const {
boardId,
boardItems: {
[itemId]: { iid, referencePath },
},
} = state;
const { data } = await gqlClient.mutate({
2020-11-24 15:15:51 +05:30
mutation: issueMoveListMutation,
variables: {
2021-04-29 21:17:54 +05:30
iid,
projectPath: referencePath.split(/[#]/)[0],
2020-11-24 15:15:51 +05:30
boardId: fullBoardId(boardId),
fromListId: getIdFromGraphQLId(fromListId),
toListId: getIdFromGraphQLId(toListId),
moveBeforeId,
moveAfterId,
2021-04-29 21:17:54 +05:30
// 'mutationVariables' allows EE code to pass in extra parameters.
...mutationVariables,
2020-11-24 15:15:51 +05:30
},
2021-04-29 21:17:54 +05:30
});
if (data?.issueMoveList?.errors.length || !data.issueMoveList) {
throw new Error('issueMoveList empty');
}
commit(types.MUTATE_ISSUE_SUCCESS, { issue: data.issueMoveList.issue });
} catch {
commit(
types.SET_ERROR,
s__('Boards|An error occurred while moving the issue. Please try again.'),
2020-11-24 15:15:51 +05:30
);
2021-04-29 21:17:54 +05:30
dispatch('undoMoveIssueCard', moveData);
}
2019-09-04 21:01:54 +05:30
},
2021-01-29 00:20:46 +05:30
setAssignees: ({ commit, getters }, assigneeUsernames) => {
2021-04-29 21:17:54 +05:30
commit('UPDATE_BOARD_ITEM_BY_ID', {
itemId: getters.activeBoardItem.id,
2021-03-11 19:13:27 +05:30
prop: 'assignees',
value: assigneeUsernames,
});
2021-01-29 00:20:46 +05:30
},
2021-02-22 17:27:13 +05:30
setActiveIssueMilestone: async ({ commit, getters }, input) => {
2021-04-29 21:17:54 +05:30
const { activeBoardItem } = getters;
2021-02-22 17:27:13 +05:30
const { data } = await gqlClient.mutate({
mutation: issueSetMilestoneMutation,
variables: {
input: {
2021-04-29 21:17:54 +05:30
iid: String(activeBoardItem.iid),
2021-02-22 17:27:13 +05:30
milestoneId: getIdFromGraphQLId(input.milestoneId),
projectPath: input.projectPath,
},
},
});
if (data.updateIssue.errors?.length > 0) {
throw new Error(data.updateIssue.errors);
}
2021-04-29 21:17:54 +05:30
commit(types.UPDATE_BOARD_ITEM_BY_ID, {
itemId: activeBoardItem.id,
2021-02-22 17:27:13 +05:30
prop: 'milestone',
value: data.updateIssue.issue.milestone,
});
},
2021-04-29 21:17:54 +05:30
addListItem: ({ commit }, { list, item, position }) => {
commit(types.ADD_BOARD_ITEM_TO_LIST, { listId: list.id, itemId: item.id, atIndex: position });
commit(types.UPDATE_BOARD_ITEM, item);
},
removeListItem: ({ commit }, { listId, itemId }) => {
commit(types.REMOVE_BOARD_ITEM_FROM_LIST, { listId, itemId });
commit(types.REMOVE_BOARD_ITEM, itemId);
},
2021-03-08 18:12:59 +05:30
2021-04-29 21:17:54 +05:30
addListNewIssue: (
{ state: { boardConfig, boardType, fullPath }, dispatch, commit },
{ issueInput, list, placeholderId = `tmp-${new Date().getTime()}` },
) => {
2021-03-08 18:12:59 +05:30
const input = formatIssueInput(issueInput, boardConfig);
2021-01-29 00:20:46 +05:30
if (boardType === BoardType.project) {
2021-03-08 18:12:59 +05:30
input.projectPath = fullPath;
2021-01-29 00:20:46 +05:30
}
2021-04-29 21:17:54 +05:30
const placeholderIssue = formatIssue({ ...issueInput, id: placeholderId });
dispatch('addListItem', { list, item: placeholderIssue, position: 0 });
gqlClient
2021-01-29 00:20:46 +05:30
.mutate({
mutation: issueCreateMutation,
variables: { input },
})
.then(({ data }) => {
if (data.createIssue.errors.length) {
2021-04-29 21:17:54 +05:30
throw new Error();
2021-01-29 00:20:46 +05:30
}
2019-09-04 21:01:54 +05:30
2021-04-29 21:17:54 +05:30
const rawIssue = data.createIssue?.issue;
const formattedIssue = formatIssue({ ...rawIssue, id: getIdFromGraphQLId(rawIssue.id) });
dispatch('removeListItem', { listId: list.id, itemId: placeholderId });
dispatch('addListItem', { list, item: formattedIssue, position: 0 });
})
.catch(() => {
dispatch('removeListItem', { listId: list.id, itemId: placeholderId });
commit(
types.SET_ERROR,
s__('Boards|An error occurred while creating the issue. Please try again.'),
);
});
2020-11-24 15:15:51 +05:30
},
2021-04-29 21:17:54 +05:30
setActiveBoardItemLabels: ({ dispatch }, params) => {
dispatch('setActiveIssueLabels', params);
2020-11-24 15:15:51 +05:30
},
2021-01-03 14:25:43 +05:30
setActiveIssueLabels: async ({ commit, getters }, input) => {
2021-04-29 21:17:54 +05:30
const { activeBoardItem } = getters;
2021-01-03 14:25:43 +05:30
const { data } = await gqlClient.mutate({
2021-02-22 17:27:13 +05:30
mutation: issueSetLabelsMutation,
2021-01-03 14:25:43 +05:30
variables: {
input: {
2021-04-29 21:17:54 +05:30
iid: String(activeBoardItem.iid),
2021-01-03 14:25:43 +05:30
addLabelIds: input.addLabelIds ?? [],
removeLabelIds: input.removeLabelIds ?? [],
projectPath: input.projectPath,
},
},
});
if (data.updateIssue?.errors?.length > 0) {
throw new Error(data.updateIssue.errors);
}
2021-04-29 21:17:54 +05:30
commit(types.UPDATE_BOARD_ITEM_BY_ID, {
itemId: activeBoardItem.id,
2021-01-03 14:25:43 +05:30
prop: 'labels',
value: data.updateIssue.issue.labels.nodes,
});
},
2021-01-29 00:20:46 +05:30
setActiveIssueDueDate: async ({ commit, getters }, input) => {
2021-04-29 21:17:54 +05:30
const { activeBoardItem } = getters;
2021-01-29 00:20:46 +05:30
const { data } = await gqlClient.mutate({
2021-02-22 17:27:13 +05:30
mutation: issueSetDueDateMutation,
2021-01-29 00:20:46 +05:30
variables: {
input: {
2021-04-29 21:17:54 +05:30
iid: String(activeBoardItem.iid),
2021-01-29 00:20:46 +05:30
projectPath: input.projectPath,
dueDate: input.dueDate,
},
},
});
if (data.updateIssue?.errors?.length > 0) {
throw new Error(data.updateIssue.errors);
}
2021-04-29 21:17:54 +05:30
commit(types.UPDATE_BOARD_ITEM_BY_ID, {
itemId: activeBoardItem.id,
2021-01-29 00:20:46 +05:30
prop: 'dueDate',
value: data.updateIssue.issue.dueDate,
});
},
2021-04-29 21:17:54 +05:30
setActiveItemSubscribed: async ({ commit, getters, state }, input) => {
const { activeBoardItem, isEpicBoard } = getters;
const { fullPath, issuableType } = state;
const workspacePath = isEpicBoard
? { groupPath: fullPath }
: { projectPath: input.projectPath };
2021-01-29 00:20:46 +05:30
const { data } = await gqlClient.mutate({
2021-04-29 21:17:54 +05:30
mutation: subscriptionQueries[issuableType].mutation,
2021-01-29 00:20:46 +05:30
variables: {
input: {
2021-04-29 21:17:54 +05:30
...workspacePath,
iid: String(activeBoardItem.iid),
2021-01-29 00:20:46 +05:30
subscribedState: input.subscribed,
},
},
});
2021-04-29 21:17:54 +05:30
if (data.updateIssuableSubscription?.errors?.length > 0) {
throw new Error(data.updateIssuableSubscription[issuableType].errors);
2021-01-29 00:20:46 +05:30
}
2021-04-29 21:17:54 +05:30
commit(types.UPDATE_BOARD_ITEM_BY_ID, {
itemId: activeBoardItem.id,
2021-01-29 00:20:46 +05:30
prop: 'subscribed',
2021-04-29 21:17:54 +05:30
value: data.updateIssuableSubscription[issuableType].subscribed,
2021-01-29 00:20:46 +05:30
});
},
2021-04-29 21:17:54 +05:30
setActiveItemTitle: async ({ commit, getters, state }, input) => {
const { activeBoardItem, isEpicBoard } = getters;
const { fullPath, issuableType } = state;
const workspacePath = isEpicBoard
? { groupPath: fullPath }
: { projectPath: input.projectPath };
2021-03-08 18:12:59 +05:30
const { data } = await gqlClient.mutate({
2021-04-29 21:17:54 +05:30
mutation: titleQueries[issuableType].mutation,
2021-03-08 18:12:59 +05:30
variables: {
input: {
2021-04-29 21:17:54 +05:30
...workspacePath,
iid: String(activeBoardItem.iid),
2021-03-08 18:12:59 +05:30
title: input.title,
},
},
});
2021-04-29 21:17:54 +05:30
if (data.updateIssuableTitle?.errors?.length > 0) {
throw new Error(data.updateIssuableTitle.errors);
2021-03-08 18:12:59 +05:30
}
2021-04-29 21:17:54 +05:30
commit(types.UPDATE_BOARD_ITEM_BY_ID, {
itemId: activeBoardItem.id,
2021-03-08 18:12:59 +05:30
prop: 'title',
2021-04-29 21:17:54 +05:30
value: data.updateIssuableTitle[issuableType].title,
2021-03-08 18:12:59 +05:30
});
},
fetchGroupProjects: ({ commit, state }, { search = '', fetchNext = false }) => {
commit(types.REQUEST_GROUP_PROJECTS, fetchNext);
const { fullPath } = state;
const variables = {
fullPath,
search: search !== '' ? search : undefined,
after: fetchNext ? state.groupProjectsFlags.pageInfo.endCursor : undefined,
};
return gqlClient
.query({
query: groupProjectsQuery,
variables,
})
.then(({ data }) => {
const { projects } = data.group;
commit(types.RECEIVE_GROUP_PROJECTS_SUCCESS, {
projects: projects.nodes,
pageInfo: projects.pageInfo,
fetchNext,
});
})
.catch(() => commit(types.RECEIVE_GROUP_PROJECTS_FAILURE));
},
setSelectedProject: ({ commit }, project) => {
commit(types.SET_SELECTED_PROJECT, project);
},
2021-04-17 20:07:23 +05:30
toggleBoardItemMultiSelection: ({ commit, state, dispatch, getters }, boardItem) => {
2021-03-11 19:13:27 +05:30
const { selectedBoardItems } = state;
const index = selectedBoardItems.indexOf(boardItem);
2021-04-29 21:17:54 +05:30
// If user already selected an item (activeBoardItem) without using mult-select,
2021-04-17 20:07:23 +05:30
// include that item in the selection and unset state.ActiveId to hide the sidebar.
2021-04-29 21:17:54 +05:30
if (getters.activeBoardItem) {
commit(types.ADD_BOARD_ITEM_TO_SELECTION, getters.activeBoardItem);
2021-04-17 20:07:23 +05:30
dispatch('unsetActiveId');
}
2021-03-11 19:13:27 +05:30
if (index === -1) {
commit(types.ADD_BOARD_ITEM_TO_SELECTION, boardItem);
} else {
commit(types.REMOVE_BOARD_ITEM_FROM_SELECTION, boardItem);
}
},
setAddColumnFormVisibility: ({ commit }, visible) => {
commit(types.SET_ADD_COLUMN_FORM_VISIBLE, visible);
},
2021-04-17 20:07:23 +05:30
resetBoardItemMultiSelection: ({ commit }) => {
commit(types.RESET_BOARD_ITEM_SELECTION);
},
toggleBoardItem: ({ state, dispatch }, { boardItem, sidebarType = ISSUABLE }) => {
dispatch('resetBoardItemMultiSelection');
if (boardItem.id === state.activeId) {
dispatch('unsetActiveId');
} else {
dispatch('setActiveId', { id: boardItem.id, sidebarType });
}
},
2021-04-29 21:17:54 +05:30
setError: ({ commit }, { message, error, captureError = false }) => {
commit(types.SET_ERROR, message);
if (captureError) {
Sentry.captureException(error);
}
},
unsetError: ({ commit }) => {
commit(types.SET_ERROR, undefined);
},
2019-09-04 21:01:54 +05:30
fetchBacklog: () => {
notImplemented();
},
bulkUpdateIssues: () => {
notImplemented();
},
fetchIssue: () => {
notImplemented();
},
toggleIssueSubscription: () => {
notImplemented();
},
showPage: () => {
notImplemented();
},
toggleEmptyState: () => {
notImplemented();
},
};