diff options
Diffstat (limited to 'app/assets/javascripts/boards/stores')
-rw-r--r-- | app/assets/javascripts/boards/stores/actions.js | 126 | ||||
-rw-r--r-- | app/assets/javascripts/boards/stores/boards_store.js | 82 | ||||
-rw-r--r-- | app/assets/javascripts/boards/stores/getters.js | 9 | ||||
-rw-r--r-- | app/assets/javascripts/boards/stores/mutation_types.js | 1 | ||||
-rw-r--r-- | app/assets/javascripts/boards/stores/mutations.js | 12 | ||||
-rw-r--r-- | app/assets/javascripts/boards/stores/state.js | 3 |
6 files changed, 88 insertions, 145 deletions
diff --git a/app/assets/javascripts/boards/stores/actions.js b/app/assets/javascripts/boards/stores/actions.js index dd950a45076..59b97eba9fe 100644 --- a/app/assets/javascripts/boards/stores/actions.js +++ b/app/assets/javascripts/boards/stores/actions.js @@ -1,9 +1,10 @@ import { pick } from 'lodash'; -import boardListsQuery from 'ee_else_ce/boards/queries/board_lists.query.graphql'; +import boardListsQuery from 'ee_else_ce/boards/graphql/board_lists.query.graphql'; import createGqClient, { fetchPolicies } from '~/lib/graphql'; import { getIdFromGraphQLId } from '~/graphql_shared/utils'; -import { BoardType, ListType, inactiveId, DEFAULT_LABELS } from '~/boards/constants'; +import { convertObjectPropsToCamelCase, urlParamsToObject } from '~/lib/utils/common_utils'; +import { BoardType, ListType, inactiveId } from '~/boards/constants'; import * as types from './mutation_types'; import { formatBoardLists, @@ -12,19 +13,20 @@ import { formatListsPageInfo, formatIssue, } from '../boards_util'; -import boardStore from '~/boards/stores/boards_store'; - -import updateAssignees from '~/vue_shared/components/sidebar/queries/updateAssignees.mutation.graphql'; -import listsIssuesQuery from '../queries/lists_issues.query.graphql'; -import boardLabelsQuery from '../queries/board_labels.query.graphql'; -import createBoardListMutation from '../queries/board_list_create.mutation.graphql'; -import updateBoardListMutation from '../queries/board_list_update.mutation.graphql'; -import issueMoveListMutation from '../queries/issue_move_list.mutation.graphql'; -import destroyBoardListMutation from '../queries/board_list_destroy.mutation.graphql'; -import issueCreateMutation from '../queries/issue_create.mutation.graphql'; -import issueSetLabels from '../queries/issue_set_labels.mutation.graphql'; -import issueSetDueDate from '../queries/issue_set_due_date.mutation.graphql'; -import issueSetSubscriptionMutation from '../graphql/mutations/issue_set_subscription.mutation.graphql'; +import createFlash from '~/flash'; +import { __ } from '~/locale'; +import updateAssigneesMutation from '~/vue_shared/components/sidebar/queries/updateAssignees.mutation.graphql'; +import listsIssuesQuery from '../graphql/lists_issues.query.graphql'; +import boardLabelsQuery from '../graphql/board_labels.query.graphql'; +import createBoardListMutation from '../graphql/board_list_create.mutation.graphql'; +import updateBoardListMutation from '../graphql/board_list_update.mutation.graphql'; +import issueMoveListMutation from '../graphql/issue_move_list.mutation.graphql'; +import destroyBoardListMutation from '../graphql/board_list_destroy.mutation.graphql'; +import issueCreateMutation from '../graphql/issue_create.mutation.graphql'; +import issueSetLabelsMutation from '../graphql/issue_set_labels.mutation.graphql'; +import issueSetDueDateMutation from '../graphql/issue_set_due_date.mutation.graphql'; +import issueSetSubscriptionMutation from '../graphql/issue_set_subscription.mutation.graphql'; +import issueSetMilestoneMutation from '../graphql/issue_set_milestone.mutation.graphql'; const notImplemented = () => { /* eslint-disable-next-line @gitlab/require-i18n-strings */ @@ -63,6 +65,18 @@ export default { commit(types.SET_FILTERS, filterParams); }, + performSearch({ dispatch }) { + dispatch( + 'setFilters', + convertObjectPropsToCamelCase(urlParamsToObject(window.location.search)), + ); + + if (gon.features.graphqlBoardLists) { + dispatch('fetchLists'); + dispatch('resetIssues'); + } + }, + fetchLists: ({ commit, state, dispatch }) => { const { endpoints, boardType, filterParams } = state; const { fullPath, boardId } = endpoints; @@ -87,7 +101,6 @@ export default { if (!lists.nodes.find(l => l.listType === ListType.backlog) && !hideBacklogList) { dispatch('createList', { backlog: true }); } - dispatch('generateDefaultLists'); }) .catch(() => commit(types.RECEIVE_BOARD_LISTS_FAILURE)); }, @@ -118,15 +131,9 @@ export default { }, addList: ({ commit }, list) => { - // Temporarily using positioning logic from boardStore - commit( - types.RECEIVE_ADD_LIST_SUCCESS, - boardStore.updateListPosition({ ...list, doNotFetchIssues: true }), - ); + commit(types.RECEIVE_ADD_LIST_SUCCESS, list); }, - showPromotionList: () => {}, - fetchLabels: ({ state, commit }, searchTerm) => { const { endpoints, boardType } = state; const { fullPath } = endpoints; @@ -150,35 +157,14 @@ export default { .catch(() => commit(types.RECEIVE_LABELS_FAILURE)); }, - generateDefaultLists: async ({ state, commit, dispatch }) => { - if (state.disabled) { - return; - } - if ( - Object.entries(state.boardLists).find( - ([, list]) => list.type !== ListType.backlog && list.type !== ListType.closed, - ) - ) { - return; - } - - const fetchLabelsAndCreateList = label => { - return dispatch('fetchLabels', label) - .then(res => { - if (res.length > 0) { - dispatch('createList', { labelId: res[0].id }); - } - }) - .catch(() => commit(types.GENERATE_DEFAULT_LISTS_FAILURE)); - }; - - await Promise.all(DEFAULT_LABELS.map(fetchLabelsAndCreateList)); - }, - moveList: ( { state, commit, dispatch }, { listId, replacedListId, newIndex, adjustmentValue }, ) => { + if (listId === replacedListId) { + return; + } + const { boardLists } = state; const backupList = { ...boardLists }; const movedList = boardLists[listId]; @@ -315,9 +301,11 @@ export default { }, setAssignees: ({ commit, getters }, assigneeUsernames) => { + commit(types.SET_ASSIGNEE_LOADING, true); + return gqlClient .mutate({ - mutation: updateAssignees, + mutation: updateAssigneesMutation, variables: { iid: getters.activeIssue.iid, projectPath: getters.activeIssue.referencePath.split('#')[0], @@ -325,14 +313,48 @@ export default { }, }) .then(({ data }) => { + const { nodes } = data.issueSetAssignees?.issue?.assignees || []; + commit('UPDATE_ISSUE_BY_ID', { issueId: getters.activeIssue.id, prop: 'assignees', - value: data.issueSetAssignees.issue.assignees.nodes, + value: nodes, }); + + return nodes; + }) + .catch(() => { + createFlash({ message: __('An error occurred while updating assignees.') }); + }) + .finally(() => { + commit(types.SET_ASSIGNEE_LOADING, false); }); }, + setActiveIssueMilestone: async ({ commit, getters }, input) => { + const { activeIssue } = getters; + const { data } = await gqlClient.mutate({ + mutation: issueSetMilestoneMutation, + variables: { + input: { + iid: String(activeIssue.iid), + milestoneId: getIdFromGraphQLId(input.milestoneId), + projectPath: input.projectPath, + }, + }, + }); + + if (data.updateIssue.errors?.length > 0) { + throw new Error(data.updateIssue.errors); + } + + commit(types.UPDATE_ISSUE_BY_ID, { + issueId: activeIssue.id, + prop: 'milestone', + value: data.updateIssue.issue.milestone, + }); + }, + createNewIssue: ({ commit, state }, issueInput) => { const input = issueInput; const { boardType, endpoints } = state; @@ -378,7 +400,7 @@ export default { setActiveIssueLabels: async ({ commit, getters }, input) => { const { activeIssue } = getters; const { data } = await gqlClient.mutate({ - mutation: issueSetLabels, + mutation: issueSetLabelsMutation, variables: { input: { iid: String(activeIssue.iid), @@ -403,7 +425,7 @@ export default { setActiveIssueDueDate: async ({ commit, getters }, input) => { const { activeIssue } = getters; const { data } = await gqlClient.mutate({ - mutation: issueSetDueDate, + mutation: issueSetDueDateMutation, variables: { input: { iid: String(activeIssue.iid), diff --git a/app/assets/javascripts/boards/stores/boards_store.js b/app/assets/javascripts/boards/stores/boards_store.js index 337b2897fe9..36702b6ca5f 100644 --- a/app/assets/javascripts/boards/stores/boards_store.js +++ b/app/assets/javascripts/boards/stores/boards_store.js @@ -1,9 +1,8 @@ /* eslint-disable no-shadow, no-param-reassign,consistent-return */ /* global List */ /* global ListIssue */ -import { sortBy, pick } from 'lodash'; +import { sortBy } from 'lodash'; import Vue from 'vue'; -import Cookies from 'js-cookie'; import BoardsStoreEE from 'ee_else_ce/boards/stores/boards_store_ee'; import { urlParamsToObject, @@ -22,8 +21,6 @@ import ListLabel from '../models/label'; import ListAssignee from '../models/assignee'; import ListMilestone from '../models/milestone'; -import createBoardMutation from '../queries/board.mutation.graphql'; - const PER_PAGE = 20; export const gqlClient = createDefaultClient(); @@ -125,20 +122,6 @@ const boardsStore = { .querySelector(`.js-board-list-${getIdFromGraphQLId(listId)}`) ?.classList.remove('is-active'); }, - shouldAddBlankState() { - // Decide whether to add the blank state - return !this.state.lists.filter(list => list.type !== 'backlog' && list.type !== 'closed')[0]; - }, - addBlankState() { - if (!this.shouldAddBlankState() || this.welcomeIsHidden()) return; - - this.generateDefaultLists() - .then(res => res.data) - .then(data => Promise.all(data.map(list => this.addList(list)))) - .catch(() => { - this.removeList(undefined, 'label'); - }); - }, findIssueLabel(issue, findLabel) { return issue.labels.find(label => label.id === findLabel.id); @@ -202,9 +185,6 @@ const boardsStore = { return list.issues.find(issue => issue.id === id); }, - welcomeIsHidden() { - return parseBoolean(Cookies.get('issue_board_welcome_hidden')); - }, removeList(id, type = 'blank') { const list = this.findList('id', id, type); @@ -302,11 +282,7 @@ const boardsStore = { onNewListIssueResponse(list, issue, data) { issue.refreshData(data); - if ( - !gon.features.boardsWithSwimlanes && - !gon.features.graphqlBoardLists && - list.issues.length > 1 - ) { + if (list.issues.length > 1) { const moveBeforeId = list.issues[1].id; this.moveIssue(issue.id, null, null, null, moveBeforeId); } @@ -516,10 +492,6 @@ const boardsStore = { eventHub.$emit('updateTokens'); }, - performSearch() { - eventHub.$emit('performSearch'); - }, - setListDetail(newList) { this.detail.list = newList; }, @@ -566,10 +538,6 @@ const boardsStore = { return axios.get(this.state.endpoints.listsEndpoint); }, - generateDefaultLists() { - return axios.post(this.state.endpoints.listsEndpointGenerate, {}); - }, - createList(entityId, entityType) { const list = { [entityType]: entityId, @@ -785,52 +753,6 @@ const boardsStore = { return axios.get(this.state.endpoints.recentBoardsEndpoint); }, - createBoard(board) { - const boardPayload = { ...board }; - boardPayload.label_ids = (board.labels || []).map(b => b.id); - - if (boardPayload.label_ids.length === 0) { - boardPayload.label_ids = ['']; - } - - if (boardPayload.assignee) { - boardPayload.assignee_id = boardPayload.assignee.id; - } - - if (boardPayload.milestone) { - boardPayload.milestone_id = boardPayload.milestone.id; - } - - if (boardPayload.id) { - const input = { - ...pick(boardPayload, ['hideClosedList', 'hideBacklogList']), - id: this.generateBoardGid(boardPayload.id), - }; - - return Promise.all([ - axios.put(this.generateBoardsPath(boardPayload.id), { board: boardPayload }), - gqlClient.mutate({ - mutation: createBoardMutation, - variables: input, - }), - ]); - } - - return axios - .post(this.generateBoardsPath(), { board: boardPayload }) - .then(resp => resp.data) - .then(data => { - gqlClient.mutate({ - mutation: createBoardMutation, - variables: { - ...pick(boardPayload, ['hideClosedList', 'hideBacklogList']), - id: this.generateBoardGid(data.id), - }, - }); - return data; - }); - }, - deleteBoard({ id }) { return axios.delete(this.generateBoardsPath(id)); }, diff --git a/app/assets/javascripts/boards/stores/getters.js b/app/assets/javascripts/boards/stores/getters.js index cd28b4a0ff7..ca6887b6f45 100644 --- a/app/assets/javascripts/boards/stores/getters.js +++ b/app/assets/javascripts/boards/stores/getters.js @@ -2,15 +2,8 @@ import { find } from 'lodash'; import { inactiveId } from '../constants'; export default { - labelToggleState: state => (state.isShowingLabels ? 'on' : 'off'), isSidebarOpen: state => state.activeId !== inactiveId, - isSwimlanesOn: state => { - if (!gon?.features?.boardsWithSwimlanes && !gon?.features?.swimlanes) { - return false; - } - - return state.isShowingEpicsSwimlanes; - }, + isSwimlanesOn: () => false, getIssueById: state => id => { return state.issues[id] || {}; }, diff --git a/app/assets/javascripts/boards/stores/mutation_types.js b/app/assets/javascripts/boards/stores/mutation_types.js index 3a57cb9b5e1..2b2c2bee51c 100644 --- a/app/assets/javascripts/boards/stores/mutation_types.js +++ b/app/assets/javascripts/boards/stores/mutation_types.js @@ -34,4 +34,5 @@ export const SET_CURRENT_PAGE = 'SET_CURRENT_PAGE'; export const TOGGLE_EMPTY_STATE = 'TOGGLE_EMPTY_STATE'; export const SET_ACTIVE_ID = 'SET_ACTIVE_ID'; export const UPDATE_ISSUE_BY_ID = 'UPDATE_ISSUE_BY_ID'; +export const SET_ASSIGNEE_LOADING = 'SET_ASSIGNEE_LOADING'; export const RESET_ISSUES = 'RESET_ISSUES'; diff --git a/app/assets/javascripts/boards/stores/mutations.js b/app/assets/javascripts/boards/stores/mutations.js index bb083158c8f..8c4e514710f 100644 --- a/app/assets/javascripts/boards/stores/mutations.js +++ b/app/assets/javascripts/boards/stores/mutations.js @@ -13,7 +13,7 @@ const notImplemented = () => { export const removeIssueFromList = ({ state, listId, issueId }) => { Vue.set(state.issuesByListId, listId, pull(state.issuesByListId[listId], issueId)); const list = state.boardLists[listId]; - Vue.set(state.boardLists, listId, { ...list, issuesSize: list.issuesSize - 1 }); + Vue.set(state.boardLists, listId, { ...list, issuesCount: list.issuesCount - 1 }); }; export const addIssueToList = ({ state, listId, issueId, moveBeforeId, moveAfterId, atIndex }) => { @@ -27,16 +27,16 @@ export const addIssueToList = ({ state, listId, issueId, moveBeforeId, moveAfter listIssues.splice(newIndex, 0, issueId); Vue.set(state.issuesByListId, listId, listIssues); const list = state.boardLists[listId]; - Vue.set(state.boardLists, listId, { ...list, issuesSize: list.issuesSize + 1 }); + Vue.set(state.boardLists, listId, { ...list, issuesCount: list.issuesCount + 1 }); }; export default { [mutationTypes.SET_INITIAL_BOARD_DATA](state, data) { - const { boardType, disabled, showPromotion, ...endpoints } = data; + const { boardType, disabled, boardConfig, ...endpoints } = data; state.endpoints = endpoints; state.boardType = boardType; state.disabled = disabled; - state.showPromotion = showPromotion; + state.boardConfig = boardConfig; }, [mutationTypes.RECEIVE_BOARD_LISTS_SUCCESS]: (state, lists) => { @@ -143,6 +143,10 @@ export default { Vue.set(state.issues[issueId], prop, value); }, + [mutationTypes.SET_ASSIGNEE_LOADING](state, isLoading) { + state.isSettingAssignees = isLoading; + }, + [mutationTypes.REQUEST_ADD_ISSUE]: () => { notImplemented(); }, diff --git a/app/assets/javascripts/boards/stores/state.js b/app/assets/javascripts/boards/stores/state.js index b91c09f8051..573e98e56e0 100644 --- a/app/assets/javascripts/boards/stores/state.js +++ b/app/assets/javascripts/boards/stores/state.js @@ -4,16 +4,17 @@ export default () => ({ endpoints: {}, boardType: null, disabled: false, - showPromotion: false, isShowingLabels: true, activeId: inactiveId, sidebarType: '', boardLists: {}, listsFlags: {}, issuesByListId: {}, + isSettingAssignees: false, pageInfoByListId: {}, issues: {}, filterParams: {}, + boardConfig: {}, error: undefined, // TODO: remove after ce/ee split of board_content.vue isShowingEpicsSwimlanes: false, |