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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

319 lines
9.6 KiB
JavaScript
Raw Normal View History

2021-10-27 15:23:28 +05:30
import { cloneDeep, pull, union } from 'lodash';
2021-03-11 19:13:27 +05:30
import Vue from 'vue';
2022-07-23 23:45:48 +05:30
import { getIdFromGraphQLId } from '~/graphql_shared/utils';
2021-10-27 15:23:28 +05:30
import { s__, __ } from '~/locale';
2021-04-29 21:17:54 +05:30
import { formatIssue } from '../boards_util';
2021-04-17 20:07:23 +05:30
import { issuableTypes } from '../constants';
2019-09-04 21:01:54 +05:30
import * as mutationTypes from './mutation_types';
2021-04-17 20:07:23 +05:30
const updateListItemsCount = ({ state, listId, value }) => {
2021-01-03 14:25:43 +05:30
const list = state.boardLists[listId];
2021-04-17 20:07:23 +05:30
if (state.issuableType === issuableTypes.epic) {
Vue.set(state.boardLists, listId, { ...list, epicsCount: list.epicsCount + value });
} else {
2022-08-27 11:52:29 +05:30
Vue.set(state.boardLists, listId, { ...list });
2021-04-17 20:07:23 +05:30
}
};
2023-04-23 21:23:45 +05:30
export const removeItemFromList = ({ state, listId, itemId, reordering = false }) => {
2021-04-17 20:07:23 +05:30
Vue.set(state.boardItemsByListId, listId, pull(state.boardItemsByListId[listId], itemId));
2023-04-23 21:23:45 +05:30
if (!reordering) {
updateListItemsCount({ state, listId, value: -1 });
}
2020-11-24 15:15:51 +05:30
};
2022-10-11 01:57:18 +05:30
export const addItemToList = ({
state,
listId,
itemId,
moveBeforeId,
moveAfterId,
atIndex,
positionInList,
2023-04-23 21:23:45 +05:30
reordering = false,
2022-10-11 01:57:18 +05:30
}) => {
2021-04-17 20:07:23 +05:30
const listIssues = state.boardItemsByListId[listId];
2020-11-24 15:15:51 +05:30
let newIndex = atIndex || 0;
2022-10-11 01:57:18 +05:30
const moveToStartOrLast = positionInList !== undefined;
2020-11-24 15:15:51 +05:30
if (moveBeforeId) {
newIndex = listIssues.indexOf(moveBeforeId) + 1;
} else if (moveAfterId) {
newIndex = listIssues.indexOf(moveAfterId);
2022-10-11 01:57:18 +05:30
} else if (moveToStartOrLast) {
newIndex = positionInList === -1 ? listIssues.length : 0;
2020-11-24 15:15:51 +05:30
}
2021-04-17 20:07:23 +05:30
listIssues.splice(newIndex, 0, itemId);
Vue.set(state.boardItemsByListId, listId, listIssues);
2023-04-23 21:23:45 +05:30
if (!reordering) {
updateListItemsCount({ state, listId, value: moveToStartOrLast ? 0 : 1 });
}
2020-11-24 15:15:51 +05:30
};
2019-09-04 21:01:54 +05:30
export default {
2022-07-23 23:45:48 +05:30
[mutationTypes.REQUEST_CURRENT_BOARD]: (state) => {
state.isBoardLoading = true;
},
2022-05-07 20:08:51 +05:30
[mutationTypes.RECEIVE_BOARD_SUCCESS]: (state, board) => {
state.board = {
...board,
labels: board?.labels?.nodes || [],
};
2022-07-23 23:45:48 +05:30
state.fullBoardId = board.id;
state.boardId = getIdFromGraphQLId(board.id);
state.isBoardLoading = false;
2022-05-07 20:08:51 +05:30
},
[mutationTypes.RECEIVE_BOARD_FAILURE]: (state) => {
state.error = s__('Boards|An error occurred while fetching the board. Please reload the page.');
2022-07-23 23:45:48 +05:30
state.isBoardLoading = false;
2022-05-07 20:08:51 +05:30
},
2020-11-24 15:15:51 +05:30
[mutationTypes.SET_INITIAL_BOARD_DATA](state, data) {
2021-09-30 23:02:18 +05:30
const {
allowSubEpics,
boardId,
boardType,
disabled,
fullBoardId,
fullPath,
issuableType,
} = data;
state.allowSubEpics = allowSubEpics;
2021-03-08 18:12:59 +05:30
state.boardId = boardId;
2020-10-24 23:57:45 +05:30
state.boardType = boardType;
2020-11-24 15:15:51 +05:30
state.disabled = disabled;
2021-09-30 23:02:18 +05:30
state.fullBoardId = fullBoardId;
state.fullPath = fullPath;
2021-04-17 20:07:23 +05:30
state.issuableType = issuableType;
2020-10-24 23:57:45 +05:30
},
2022-05-07 20:08:51 +05:30
[mutationTypes.SET_BOARD_CONFIG](state, boardConfig) {
state.boardConfig = boardConfig;
},
2020-11-24 15:15:51 +05:30
[mutationTypes.RECEIVE_BOARD_LISTS_SUCCESS]: (state, lists) => {
state.boardLists = lists;
},
2021-03-08 18:12:59 +05:30
[mutationTypes.RECEIVE_BOARD_LISTS_FAILURE]: (state) => {
2021-01-03 14:25:43 +05:30
state.error = s__(
'Boards|An error occurred while fetching the board lists. Please reload the page.',
);
},
2020-11-24 15:15:51 +05:30
[mutationTypes.SET_ACTIVE_ID](state, { id, sidebarType }) {
2020-10-24 23:57:45 +05:30
state.activeId = id;
2020-11-24 15:15:51 +05:30
state.sidebarType = sidebarType;
},
[mutationTypes.SET_FILTERS](state, filterParams) {
state.filterParams = filterParams;
},
2021-04-17 20:07:23 +05:30
[mutationTypes.CREATE_LIST_FAILURE]: (
state,
error = s__('Boards|An error occurred while creating the list. Please try again.'),
) => {
state.error = error;
},
[mutationTypes.RECEIVE_LABELS_REQUEST]: (state) => {
state.labelsLoading = true;
2019-09-04 21:01:54 +05:30
},
2021-03-11 19:13:27 +05:30
[mutationTypes.RECEIVE_LABELS_SUCCESS]: (state, labels) => {
state.labels = labels;
2021-04-17 20:07:23 +05:30
state.labelsLoading = false;
},
[mutationTypes.RECEIVE_LABELS_FAILURE]: (state) => {
state.error = s__('Boards|An error occurred while fetching labels. Please reload the page.');
state.labelsLoading = false;
2021-01-29 00:20:46 +05:30
},
2021-03-08 18:12:59 +05:30
[mutationTypes.GENERATE_DEFAULT_LISTS_FAILURE]: (state) => {
2021-01-29 00:20:46 +05:30
state.error = s__('Boards|An error occurred while generating lists. Please reload the page.');
},
2021-01-03 14:25:43 +05:30
[mutationTypes.RECEIVE_ADD_LIST_SUCCESS]: (state, list) => {
Vue.set(state.boardLists, list.id, list);
2019-09-04 21:01:54 +05:30
},
2021-10-27 15:23:28 +05:30
[mutationTypes.MOVE_LISTS]: (state, movedLists) => {
const updatedBoardList = movedLists.reduce((acc, { listId, position }) => {
acc[listId].position = position;
return acc;
}, cloneDeep(state.boardLists));
Vue.set(state, 'boardLists', updatedBoardList);
2019-09-04 21:01:54 +05:30
},
2021-04-17 20:07:23 +05:30
[mutationTypes.TOGGLE_LIST_COLLAPSED]: (state, { listId, collapsed }) => {
Vue.set(state.boardLists[listId], 'collapsed', collapsed);
},
2021-01-29 00:20:46 +05:30
[mutationTypes.REMOVE_LIST]: (state, listId) => {
Vue.delete(state.boardLists, listId);
2019-09-04 21:01:54 +05:30
},
2021-01-29 00:20:46 +05:30
[mutationTypes.REMOVE_LIST_FAILURE](state, listsBackup) {
state.error = s__('Boards|An error occurred while removing the list. Please try again.');
state.boardLists = listsBackup;
2019-09-04 21:01:54 +05:30
},
2021-04-17 20:07:23 +05:30
[mutationTypes.REQUEST_ITEMS_FOR_LIST]: (state, { listId, fetchNext }) => {
2021-01-03 14:25:43 +05:30
Vue.set(state.listsFlags, listId, { [fetchNext ? 'isLoadingMore' : 'isLoading']: true });
},
2021-10-27 15:23:28 +05:30
[mutationTypes.RECEIVE_MILESTONES_SUCCESS](state, milestones) {
state.milestones = milestones;
state.milestonesLoading = false;
},
[mutationTypes.RECEIVE_MILESTONES_REQUEST](state) {
state.milestonesLoading = true;
},
[mutationTypes.RECEIVE_MILESTONES_FAILURE](state) {
state.milestonesLoading = false;
state.error = __('Failed to load milestones.');
},
2021-04-17 20:07:23 +05:30
[mutationTypes.RECEIVE_ITEMS_FOR_LIST_SUCCESS]: (state, { listItems, listPageInfo, listId }) => {
const { listData, boardItems } = listItems;
Vue.set(state, 'boardItems', { ...state.boardItems, ...boardItems });
2021-01-03 14:25:43 +05:30
Vue.set(
2021-04-17 20:07:23 +05:30
state.boardItemsByListId,
2021-01-03 14:25:43 +05:30
listId,
2021-04-17 20:07:23 +05:30
union(state.boardItemsByListId[listId] || [], listData[listId]),
2021-01-03 14:25:43 +05:30
);
Vue.set(state.pageInfoByListId, listId, listPageInfo[listId]);
Vue.set(state.listsFlags, listId, { isLoading: false, isLoadingMore: false });
2020-11-24 15:15:51 +05:30
},
2021-04-17 20:07:23 +05:30
[mutationTypes.RECEIVE_ITEMS_FOR_LIST_FAILURE]: (state, listId) => {
2021-01-03 14:25:43 +05:30
state.error = s__(
'Boards|An error occurred while fetching the board issues. Please reload the page.',
);
Vue.set(state.listsFlags, listId, { isLoading: false, isLoadingMore: false });
2020-10-24 23:57:45 +05:30
},
2021-03-08 18:12:59 +05:30
[mutationTypes.RESET_ISSUES]: (state) => {
2021-04-17 20:07:23 +05:30
Object.keys(state.boardItemsByListId).forEach((listId) => {
Vue.set(state.boardItemsByListId, listId, []);
2021-01-03 14:25:43 +05:30
});
2020-10-24 23:57:45 +05:30
},
2021-04-29 21:17:54 +05:30
[mutationTypes.UPDATE_BOARD_ITEM_BY_ID]: (state, { itemId, prop, value }) => {
if (!state.boardItems[itemId]) {
2020-11-24 15:15:51 +05:30
/* eslint-disable-next-line @gitlab/require-i18n-strings */
throw new Error('No issue found.');
}
2021-04-29 21:17:54 +05:30
Vue.set(state.boardItems[itemId], prop, value);
2020-11-24 15:15:51 +05:30
},
2021-02-22 17:27:13 +05:30
[mutationTypes.SET_ASSIGNEE_LOADING](state, isLoading) {
state.isSettingAssignees = isLoading;
},
2021-04-29 21:17:54 +05:30
[mutationTypes.MUTATE_ISSUE_SUCCESS]: (state, { issue }) => {
2021-11-11 11:23:49 +05:30
Vue.set(state.boardItems, issue.id, formatIssue(issue));
2019-09-04 21:01:54 +05:30
},
2022-10-11 01:57:18 +05:30
[mutationTypes.MUTATE_ISSUE_IN_PROGRESS](state, isLoading) {
state.isUpdateIssueOrderInProgress = isLoading;
},
2021-04-29 21:17:54 +05:30
[mutationTypes.ADD_BOARD_ITEM_TO_LIST]: (
state,
2022-10-11 01:57:18 +05:30
{
itemId,
listId,
moveBeforeId,
moveAfterId,
atIndex,
positionInList,
allItemsLoadedInList,
inProgress = false,
},
2021-04-29 21:17:54 +05:30
) => {
2021-09-04 01:27:46 +05:30
Vue.set(state.listsFlags, listId, { ...state.listsFlags, addItemToListInProgress: inProgress });
2022-10-11 01:57:18 +05:30
addItemToList({
state,
listId,
itemId,
moveBeforeId,
moveAfterId,
atIndex,
positionInList,
allItemsLoadedInList,
});
2021-01-29 00:20:46 +05:30
},
2021-04-29 21:17:54 +05:30
[mutationTypes.REMOVE_BOARD_ITEM_FROM_LIST]: (state, { itemId, listId }) => {
removeItemFromList({ state, listId, itemId });
2020-11-24 15:15:51 +05:30
},
2021-04-29 21:17:54 +05:30
[mutationTypes.UPDATE_BOARD_ITEM]: (state, item) => {
Vue.set(state.boardItems, item.id, item);
2021-01-29 00:20:46 +05:30
},
2021-04-29 21:17:54 +05:30
[mutationTypes.REMOVE_BOARD_ITEM]: (state, itemId) => {
Vue.delete(state.boardItems, itemId);
2020-11-24 15:15:51 +05:30
},
2021-03-08 18:12:59 +05:30
[mutationTypes.REQUEST_GROUP_PROJECTS]: (state, fetchNext) => {
Vue.set(state, 'groupProjectsFlags', {
[fetchNext ? 'isLoadingMore' : 'isLoading']: true,
pageInfo: state.groupProjectsFlags.pageInfo,
});
},
[mutationTypes.RECEIVE_GROUP_PROJECTS_SUCCESS]: (state, { projects, pageInfo, fetchNext }) => {
Vue.set(state, 'groupProjects', fetchNext ? [...state.groupProjects, ...projects] : projects);
Vue.set(state, 'groupProjectsFlags', { isLoading: false, isLoadingMore: false, pageInfo });
},
[mutationTypes.RECEIVE_GROUP_PROJECTS_FAILURE]: (state) => {
state.error = s__('Boards|An error occurred while fetching group projects. Please try again.');
Vue.set(state, 'groupProjectsFlags', { isLoading: false, isLoadingMore: false });
},
[mutationTypes.SET_SELECTED_PROJECT]: (state, project) => {
state.selectedProject = project;
},
2021-03-11 19:13:27 +05:30
[mutationTypes.ADD_BOARD_ITEM_TO_SELECTION]: (state, boardItem) => {
state.selectedBoardItems = [...state.selectedBoardItems, boardItem];
},
[mutationTypes.REMOVE_BOARD_ITEM_FROM_SELECTION]: (state, boardItem) => {
Vue.set(
state,
'selectedBoardItems',
state.selectedBoardItems.filter((obj) => obj !== boardItem),
);
},
[mutationTypes.SET_ADD_COLUMN_FORM_VISIBLE]: (state, visible) => {
2021-04-17 20:07:23 +05:30
Vue.set(state.addColumnForm, 'visible', visible);
2021-03-11 19:13:27 +05:30
},
[mutationTypes.ADD_LIST_TO_HIGHLIGHTED_LISTS]: (state, listId) => {
state.highlightedLists.push(listId);
},
[mutationTypes.REMOVE_LIST_FROM_HIGHLIGHTED_LISTS]: (state, listId) => {
state.highlightedLists = state.highlightedLists.filter((id) => id !== listId);
},
2021-04-17 20:07:23 +05:30
[mutationTypes.RESET_BOARD_ITEM_SELECTION]: (state) => {
state.selectedBoardItems = [];
},
2021-04-29 21:17:54 +05:30
[mutationTypes.SET_ERROR]: (state, error) => {
state.error = error;
},
2019-09-04 21:01:54 +05:30
};