Commit a08485ee authored by Florie Guibert's avatar Florie Guibert

Boards - Update Open column when adding list

Reloads items from Open column when adding or removing a list to avoid
inaccurate list of issues.
parent 43ebce85
...@@ -36,6 +36,7 @@ export const ListTypeTitles = { ...@@ -36,6 +36,7 @@ export const ListTypeTitles = {
milestone: __('Milestone'), milestone: __('Milestone'),
iteration: __('Iteration'), iteration: __('Iteration'),
label: __('Label'), label: __('Label'),
backlog: __('Open'),
}; };
export const formType = { export const formType = {
......
...@@ -12,6 +12,7 @@ import { ...@@ -12,6 +12,7 @@ import {
updateListQueries, updateListQueries,
issuableTypes, issuableTypes,
FilterFields, FilterFields,
ListTypeTitles,
} from 'ee_else_ce/boards/constants'; } from 'ee_else_ce/boards/constants';
import createBoardListMutation from 'ee_else_ce/boards/graphql/board_list_create.mutation.graphql'; import createBoardListMutation from 'ee_else_ce/boards/graphql/board_list_create.mutation.graphql';
import issueMoveListMutation from 'ee_else_ce/boards/graphql/issue_move_list.mutation.graphql'; import issueMoveListMutation from 'ee_else_ce/boards/graphql/issue_move_list.mutation.graphql';
...@@ -169,8 +170,11 @@ export default { ...@@ -169,8 +170,11 @@ export default {
}); });
}, },
addList: ({ commit }, list) => { addList: ({ commit, dispatch, getters }, list) => {
commit(types.RECEIVE_ADD_LIST_SUCCESS, updateListPosition(list)); commit(types.RECEIVE_ADD_LIST_SUCCESS, updateListPosition(list));
dispatch('fetchItemsForList', {
listId: getters.getListByTitle(ListTypeTitles.backlog).id,
});
}, },
fetchLabels: ({ state, commit, getters }, searchTerm) => { fetchLabels: ({ state, commit, getters }, searchTerm) => {
...@@ -261,7 +265,7 @@ export default { ...@@ -261,7 +265,7 @@ export default {
commit(types.TOGGLE_LIST_COLLAPSED, { listId, collapsed }); commit(types.TOGGLE_LIST_COLLAPSED, { listId, collapsed });
}, },
removeList: ({ state: { issuableType, boardLists }, commit }, listId) => { removeList: ({ state: { issuableType, boardLists }, commit, dispatch, getters }, listId) => {
const listsBackup = { ...boardLists }; const listsBackup = { ...boardLists };
commit(types.REMOVE_LIST, listId); commit(types.REMOVE_LIST, listId);
...@@ -281,6 +285,10 @@ export default { ...@@ -281,6 +285,10 @@ export default {
}) => { }) => {
if (errors.length > 0) { if (errors.length > 0) {
commit(types.REMOVE_LIST_FAILURE, listsBackup); commit(types.REMOVE_LIST_FAILURE, listsBackup);
} else {
dispatch('fetchItemsForList', {
listId: getters.getListByTitle(ListTypeTitles.backlog).id,
});
} }
}, },
) )
......
...@@ -118,6 +118,9 @@ export default { ...@@ -118,6 +118,9 @@ export default {
}, },
[mutationTypes.REQUEST_ITEMS_FOR_LIST]: (state, { listId, fetchNext }) => { [mutationTypes.REQUEST_ITEMS_FOR_LIST]: (state, { listId, fetchNext }) => {
if (!fetchNext && !state.isShowingEpicsSwimlanes) {
Vue.set(state.boardItemsByListId, listId, []);
}
Vue.set(state.listsFlags, listId, { [fetchNext ? 'isLoadingMore' : 'isLoading']: true }); Vue.set(state.listsFlags, listId, { [fetchNext ? 'isLoadingMore' : 'isLoading']: true });
}, },
......
...@@ -15,6 +15,7 @@ import { ...@@ -15,6 +15,7 @@ import {
formatIssueInput, formatIssueInput,
formatIssue, formatIssue,
getMoveData, getMoveData,
updateListPosition,
} from '~/boards/boards_util'; } from '~/boards/boards_util';
import destroyBoardListMutation from '~/boards/graphql/board_list_destroy.mutation.graphql'; import destroyBoardListMutation from '~/boards/graphql/board_list_destroy.mutation.graphql';
import issueCreateMutation from '~/boards/graphql/issue_create.mutation.graphql'; import issueCreateMutation from '~/boards/graphql/issue_create.mutation.graphql';
...@@ -36,6 +37,7 @@ import { ...@@ -36,6 +37,7 @@ import {
mockMoveIssueParams, mockMoveIssueParams,
mockMoveState, mockMoveState,
mockMoveData, mockMoveData,
mockList,
} from '../mock_data'; } from '../mock_data';
jest.mock('~/flash'); jest.mock('~/flash');
...@@ -374,6 +376,24 @@ describe('createIssueList', () => { ...@@ -374,6 +376,24 @@ describe('createIssueList', () => {
}); });
}); });
describe('addList', () => {
const getters = {
getListByTitle: jest.fn().mockReturnValue(mockList),
};
it('should commit RECEIVE_ADD_LIST_SUCCESS mutation and dispatch fetchItemsForList action', () => {
testAction({
action: actions.addList,
payload: mockLists[1],
state: { ...getters },
expectedMutations: [
{ type: types.RECEIVE_ADD_LIST_SUCCESS, payload: updateListPosition(mockLists[1]) },
],
expectedActions: [{ type: 'fetchItemsForList', payload: { listId: mockList.id } }],
});
});
});
describe('fetchLabels', () => { describe('fetchLabels', () => {
it('should commit mutation RECEIVE_LABELS_SUCCESS on success', async () => { it('should commit mutation RECEIVE_LABELS_SUCCESS on success', async () => {
const queryResponse = { const queryResponse = {
...@@ -521,7 +541,8 @@ describe('toggleListCollapsed', () => { ...@@ -521,7 +541,8 @@ describe('toggleListCollapsed', () => {
describe('removeList', () => { describe('removeList', () => {
let state; let state;
const list = mockLists[0]; let getters;
const list = mockLists[1];
const listId = list.id; const listId = list.id;
const mutationVariables = { const mutationVariables = {
mutation: destroyBoardListMutation, mutation: destroyBoardListMutation,
...@@ -535,6 +556,9 @@ describe('removeList', () => { ...@@ -535,6 +556,9 @@ describe('removeList', () => {
boardLists: mockListsById, boardLists: mockListsById,
issuableType: issuableTypes.issue, issuableType: issuableTypes.issue,
}; };
getters = {
getListByTitle: jest.fn().mockReturnValue(mockList),
};
}); });
afterEach(() => { afterEach(() => {
...@@ -544,13 +568,15 @@ describe('removeList', () => { ...@@ -544,13 +568,15 @@ describe('removeList', () => {
it('optimistically deletes the list', () => { it('optimistically deletes the list', () => {
const commit = jest.fn(); const commit = jest.fn();
actions.removeList({ commit, state }, listId); actions.removeList({ commit, state, getters, dispatch: () => {} }, listId);
expect(commit.mock.calls).toEqual([[types.REMOVE_LIST, listId]]); expect(commit.mock.calls).toEqual([[types.REMOVE_LIST, listId]]);
}); });
it('keeps the updated list if remove succeeds', async () => { it('keeps the updated list if remove succeeds', async () => {
const commit = jest.fn(); const commit = jest.fn();
const dispatch = jest.fn();
jest.spyOn(gqlClient, 'mutate').mockResolvedValue({ jest.spyOn(gqlClient, 'mutate').mockResolvedValue({
data: { data: {
destroyBoardList: { destroyBoardList: {
...@@ -559,17 +585,18 @@ describe('removeList', () => { ...@@ -559,17 +585,18 @@ describe('removeList', () => {
}, },
}); });
await actions.removeList({ commit, state }, listId); await actions.removeList({ commit, state, getters, dispatch }, listId);
expect(gqlClient.mutate).toHaveBeenCalledWith(mutationVariables); expect(gqlClient.mutate).toHaveBeenCalledWith(mutationVariables);
expect(commit.mock.calls).toEqual([[types.REMOVE_LIST, listId]]); expect(commit.mock.calls).toEqual([[types.REMOVE_LIST, listId]]);
expect(dispatch.mock.calls).toEqual([['fetchItemsForList', { listId: mockList.id }]]);
}); });
it('restores the list if update fails', async () => { it('restores the list if update fails', async () => {
const commit = jest.fn(); const commit = jest.fn();
jest.spyOn(gqlClient, 'mutate').mockResolvedValue(Promise.reject()); jest.spyOn(gqlClient, 'mutate').mockResolvedValue(Promise.reject());
await actions.removeList({ commit, state }, listId); await actions.removeList({ commit, state, getters, dispatch: () => {} }, listId);
expect(gqlClient.mutate).toHaveBeenCalledWith(mutationVariables); expect(gqlClient.mutate).toHaveBeenCalledWith(mutationVariables);
expect(commit.mock.calls).toEqual([ expect(commit.mock.calls).toEqual([
...@@ -588,7 +615,7 @@ describe('removeList', () => { ...@@ -588,7 +615,7 @@ describe('removeList', () => {
}, },
}); });
await actions.removeList({ commit, state }, listId); await actions.removeList({ commit, state, getters, dispatch: () => {} }, listId);
expect(gqlClient.mutate).toHaveBeenCalledWith(mutationVariables); expect(gqlClient.mutate).toHaveBeenCalledWith(mutationVariables);
expect(commit.mock.calls).toEqual([ expect(commit.mock.calls).toEqual([
......
...@@ -273,6 +273,36 @@ describe('Board Store Mutations', () => { ...@@ -273,6 +273,36 @@ describe('Board Store Mutations', () => {
}); });
}); });
describe('REQUEST_ITEMS_FOR_LIST', () => {
const listId = 'gid://gitlab/List/1';
const boardItemsByListId = {
[listId]: [mockIssue.id],
};
it.each`
fetchNext | isLoading | isLoadingMore | listItems
${true} | ${undefined} | ${true} | ${boardItemsByListId[listId]}
${false} | ${true} | ${undefined} | ${[]}
`(
'sets isLoading to $isLoading and isLoadingMore to $isLoadingMore when fetchNext is $fetchNext',
({ fetchNext, isLoading, isLoadingMore, listItems }) => {
state = {
...state,
boardItemsByListId,
listsFlags: {
[listId]: {},
},
};
mutations[types.REQUEST_ITEMS_FOR_LIST](state, { listId, fetchNext });
expect(state.listsFlags[listId].isLoading).toBe(isLoading);
expect(state.listsFlags[listId].isLoadingMore).toBe(isLoadingMore);
expect(state.boardItemsByListId[listId]).toEqual(listItems);
},
);
});
describe('RECEIVE_ITEMS_FOR_LIST_SUCCESS', () => { describe('RECEIVE_ITEMS_FOR_LIST_SUCCESS', () => {
it('updates boardItemsByListId and issues on state', () => { it('updates boardItemsByListId and issues on state', () => {
const listIssues = { const listIssues = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment