diff options
Diffstat (limited to 'app/assets/javascripts/boards/stores')
-rw-r--r-- | app/assets/javascripts/boards/stores/actions.js | 41 | ||||
-rw-r--r-- | app/assets/javascripts/boards/stores/boards_store.js | 45 | ||||
-rw-r--r-- | app/assets/javascripts/boards/stores/mutation_types.js | 6 | ||||
-rw-r--r-- | app/assets/javascripts/boards/stores/mutations.js | 22 | ||||
-rw-r--r-- | app/assets/javascripts/boards/stores/state.js | 8 |
5 files changed, 101 insertions, 21 deletions
diff --git a/app/assets/javascripts/boards/stores/actions.js b/app/assets/javascripts/boards/stores/actions.js index 08fedb14dff..b4be7546252 100644 --- a/app/assets/javascripts/boards/stores/actions.js +++ b/app/assets/javascripts/boards/stores/actions.js @@ -1,4 +1,11 @@ import * as types from './mutation_types'; +import createDefaultClient from '~/lib/graphql'; +import { BoardType } from '~/boards/constants'; +import { formatListIssues } from '../boards_util'; +import groupListsIssuesQuery from '../queries/group_lists_issues.query.graphql'; +import projectListsIssuesQuery from '../queries/project_lists_issues.query.graphql'; + +const gqlClient = createDefaultClient(); const notImplemented = () => { /* eslint-disable-next-line @gitlab/require-i18n-strings */ @@ -6,8 +13,12 @@ const notImplemented = () => { }; export default { - setEndpoints: ({ commit }, endpoints) => { - commit(types.SET_ENDPOINTS, endpoints); + setInitialBoardData: ({ commit }, data) => { + commit(types.SET_INITIAL_BOARD_DATA, data); + }, + + setActiveId({ commit }, id) { + commit(types.SET_ACTIVE_ID, id); }, fetchLists: () => { @@ -34,6 +45,32 @@ export default { notImplemented(); }, + fetchIssuesForAllLists: ({ state, commit }) => { + commit(types.REQUEST_ISSUES_FOR_ALL_LISTS); + + const { endpoints, boardType } = state; + const { fullPath, boardId } = endpoints; + + const query = boardType === BoardType.group ? groupListsIssuesQuery : projectListsIssuesQuery; + + const variables = { + fullPath, + boardId: `gid://gitlab/Board/${boardId}`, + }; + + return gqlClient + .query({ + query, + variables, + }) + .then(({ data }) => { + const { lists } = data[boardType]?.board; + const listIssues = formatListIssues(lists); + commit(types.RECEIVE_ISSUES_FOR_ALL_LISTS_SUCCESS, listIssues); + }) + .catch(() => commit(types.RECEIVE_ISSUES_FOR_ALL_LISTS_FAILURE)); + }, + moveIssue: () => { notImplemented(); }, diff --git a/app/assets/javascripts/boards/stores/boards_store.js b/app/assets/javascripts/boards/stores/boards_store.js index da7d2e19ec1..30c71d64085 100644 --- a/app/assets/javascripts/boards/stores/boards_store.js +++ b/app/assets/javascripts/boards/stores/boards_store.js @@ -1,6 +1,6 @@ /* eslint-disable no-shadow, no-param-reassign,consistent-return */ /* global List */ - +/* global ListIssue */ import $ from 'jquery'; import { sortBy } from 'lodash'; import Vue from 'vue'; @@ -81,7 +81,7 @@ const boardsStore = { showPage(page) { this.state.currentPage = page; }, - addList(listObj) { + updateListPosition(listObj) { const listType = listObj.listType || listObj.list_type; let { position } = listObj; if (listType === ListType.closed) { @@ -91,6 +91,10 @@ const boardsStore = { } const list = new List({ ...listObj, position }); + return list; + }, + addList(listObj) { + const list = this.updateListPosition(listObj); this.state.lists = sortBy([...this.state.lists, list], 'position'); return list; }, @@ -641,7 +645,9 @@ const boardsStore = { list.issues = []; } - list.createIssues(data.issues); + data.issues.forEach(issueObj => { + list.addIssue(new ListIssue(issueObj)); + }); return data; }); @@ -848,19 +854,28 @@ const boardsStore = { }, refreshIssueData(issue, obj) { - issue.id = obj.id; - issue.iid = obj.iid; - issue.title = obj.title; - issue.confidential = obj.confidential; - issue.dueDate = obj.due_date; - issue.sidebarInfoEndpoint = obj.issue_sidebar_endpoint; - issue.referencePath = obj.reference_path; - issue.path = obj.real_path; - issue.toggleSubscriptionEndpoint = obj.toggle_subscription_endpoint; + // issue.id = obj.id; + // issue.iid = obj.iid; + // issue.title = obj.title; + // issue.confidential = obj.confidential; + // issue.dueDate = obj.due_date || obj.dueDate; + // issue.sidebarInfoEndpoint = obj.issue_sidebar_endpoint; + // issue.referencePath = obj.reference_path || obj.referencePath; + // issue.path = obj.real_path || obj.webUrl; + // issue.toggleSubscriptionEndpoint = obj.toggle_subscription_endpoint; + // issue.project_id = obj.project_id; + // issue.timeEstimate = obj.time_estimate || obj.timeEstimate; + // issue.assignableLabelsEndpoint = obj.assignable_labels_endpoint; + // issue.blocked = obj.blocked; + // issue.epic = obj.epic; + + const convertedObj = convertObjectPropsToCamelCase(obj, { + dropKeys: ['issue_sidebar_endpoint', 'real_path', 'webUrl'], + }); + convertedObj.sidebarInfoEndpoint = obj.issue_sidebar_endpoint; + issue.path = obj.real_path || obj.webUrl; issue.project_id = obj.project_id; - issue.timeEstimate = obj.time_estimate; - issue.assignableLabelsEndpoint = obj.assignable_labels_endpoint; - issue.blocked = obj.blocked; + Object.assign(issue, convertedObj); if (obj.project) { issue.project = new IssueProject(obj.project); diff --git a/app/assets/javascripts/boards/stores/mutation_types.js b/app/assets/javascripts/boards/stores/mutation_types.js index fcdfa6799b6..0f96dc2e287 100644 --- a/app/assets/javascripts/boards/stores/mutation_types.js +++ b/app/assets/javascripts/boards/stores/mutation_types.js @@ -1,4 +1,4 @@ -export const SET_ENDPOINTS = 'SET_ENDPOINTS'; +export const SET_INITIAL_BOARD_DATA = 'SET_INITIAL_BOARD_DATA'; export const REQUEST_ADD_LIST = 'REQUEST_ADD_LIST'; export const RECEIVE_ADD_LIST_SUCCESS = 'RECEIVE_ADD_LIST_SUCCESS'; export const RECEIVE_ADD_LIST_ERROR = 'RECEIVE_ADD_LIST_ERROR'; @@ -8,6 +8,9 @@ export const RECEIVE_UPDATE_LIST_ERROR = 'RECEIVE_UPDATE_LIST_ERROR'; export const REQUEST_REMOVE_LIST = 'REQUEST_REMOVE_LIST'; export const RECEIVE_REMOVE_LIST_SUCCESS = 'RECEIVE_REMOVE_LIST_SUCCESS'; export const RECEIVE_REMOVE_LIST_ERROR = 'RECEIVE_REMOVE_LIST_ERROR'; +export const REQUEST_ISSUES_FOR_ALL_LISTS = 'REQUEST_ISSUES_FOR_ALL_LISTS'; +export const RECEIVE_ISSUES_FOR_ALL_LISTS_SUCCESS = 'RECEIVE_ISSUES_FOR_ALL_LISTS_SUCCESS'; +export const RECEIVE_ISSUES_FOR_ALL_LISTS_FAILURE = 'RECEIVE_ISSUES_FOR_ALL_LISTS_FAILURE'; export const REQUEST_ADD_ISSUE = 'REQUEST_ADD_ISSUE'; export const RECEIVE_ADD_ISSUE_SUCCESS = 'RECEIVE_ADD_ISSUE_SUCCESS'; export const RECEIVE_ADD_ISSUE_ERROR = 'RECEIVE_ADD_ISSUE_ERROR'; @@ -19,3 +22,4 @@ export const RECEIVE_UPDATE_ISSUE_SUCCESS = 'RECEIVE_UPDATE_ISSUE_SUCCESS'; export const RECEIVE_UPDATE_ISSUE_ERROR = 'RECEIVE_UPDATE_ISSUE_ERROR'; export const SET_CURRENT_PAGE = 'SET_CURRENT_PAGE'; export const TOGGLE_EMPTY_STATE = 'TOGGLE_EMPTY_STATE'; +export const SET_ACTIVE_ID = 'SET_ACTIVE_ID'; diff --git a/app/assets/javascripts/boards/stores/mutations.js b/app/assets/javascripts/boards/stores/mutations.js index e4459cdcc07..ca9b911ce5b 100644 --- a/app/assets/javascripts/boards/stores/mutations.js +++ b/app/assets/javascripts/boards/stores/mutations.js @@ -6,8 +6,14 @@ const notImplemented = () => { }; export default { - [mutationTypes.SET_ENDPOINTS]: (state, endpoints) => { + [mutationTypes.SET_INITIAL_BOARD_DATA]: (state, data) => { + const { boardType, ...endpoints } = data; state.endpoints = endpoints; + state.boardType = boardType; + }, + + [mutationTypes.SET_ACTIVE_ID](state, id) { + state.activeId = id; }, [mutationTypes.REQUEST_ADD_LIST]: () => { @@ -46,6 +52,20 @@ export default { notImplemented(); }, + [mutationTypes.REQUEST_ISSUES_FOR_ALL_LISTS]: state => { + state.isLoadingIssues = true; + }, + + [mutationTypes.RECEIVE_ISSUES_FOR_ALL_LISTS_SUCCESS]: (state, listIssues) => { + state.issuesByListId = listIssues; + state.isLoadingIssues = false; + }, + + [mutationTypes.RECEIVE_ISSUES_FOR_ALL_LISTS_FAILURE]: state => { + state.listIssueFetchFailure = true; + state.isLoadingIssues = false; + }, + [mutationTypes.REQUEST_ADD_ISSUE]: () => { notImplemented(); }, diff --git a/app/assets/javascripts/boards/stores/state.js b/app/assets/javascripts/boards/stores/state.js index aca93c4d7c6..cb6930774ed 100644 --- a/app/assets/javascripts/boards/stores/state.js +++ b/app/assets/javascripts/boards/stores/state.js @@ -1,7 +1,11 @@ -import { inactiveListId } from '~/boards/constants'; +import { inactiveId } from '~/boards/constants'; export default () => ({ endpoints: {}, + boardType: null, isShowingLabels: true, - activeListId: inactiveListId, + activeId: inactiveId, + issuesByListId: {}, + isLoadingIssues: false, + listIssueFetchFailure: false, }); |