Commit ad5a8b2d authored by Florie Guibert's avatar Florie Guibert

Boards - Update Open column when adding list

Review feedback
parent a08485ee
...@@ -298,6 +298,9 @@ export default { ...@@ -298,6 +298,9 @@ export default {
}, },
fetchItemsForList: ({ state, commit }, { listId, fetchNext = false }) => { fetchItemsForList: ({ state, commit }, { listId, fetchNext = false }) => {
if (!fetchNext) {
commit(types.RESET_ITEMS_FOR_LIST, listId);
}
commit(types.REQUEST_ITEMS_FOR_LIST, { listId, fetchNext }); commit(types.REQUEST_ITEMS_FOR_LIST, { listId, fetchNext });
const { fullPath, fullBoardId, boardType, filterParams } = state; const { fullPath, fullBoardId, boardType, filterParams } = state;
......
...@@ -15,6 +15,7 @@ export const UPDATE_LIST_FAILURE = 'UPDATE_LIST_FAILURE'; ...@@ -15,6 +15,7 @@ export const UPDATE_LIST_FAILURE = 'UPDATE_LIST_FAILURE';
export const TOGGLE_LIST_COLLAPSED = 'TOGGLE_LIST_COLLAPSED'; export const TOGGLE_LIST_COLLAPSED = 'TOGGLE_LIST_COLLAPSED';
export const REMOVE_LIST = 'REMOVE_LIST'; export const REMOVE_LIST = 'REMOVE_LIST';
export const REMOVE_LIST_FAILURE = 'REMOVE_LIST_FAILURE'; export const REMOVE_LIST_FAILURE = 'REMOVE_LIST_FAILURE';
export const RESET_ITEMS_FOR_LIST = 'RESET_ITEMS_FOR_LIST';
export const REQUEST_ITEMS_FOR_LIST = 'REQUEST_ITEMS_FOR_LIST'; export const REQUEST_ITEMS_FOR_LIST = 'REQUEST_ITEMS_FOR_LIST';
export const RECEIVE_ITEMS_FOR_LIST_FAILURE = 'RECEIVE_ITEMS_FOR_LIST_FAILURE'; export const RECEIVE_ITEMS_FOR_LIST_FAILURE = 'RECEIVE_ITEMS_FOR_LIST_FAILURE';
export const RECEIVE_ITEMS_FOR_LIST_SUCCESS = 'RECEIVE_ITEMS_FOR_LIST_SUCCESS'; export const RECEIVE_ITEMS_FOR_LIST_SUCCESS = 'RECEIVE_ITEMS_FOR_LIST_SUCCESS';
......
...@@ -117,10 +117,12 @@ export default { ...@@ -117,10 +117,12 @@ export default {
state.boardLists = listsBackup; state.boardLists = listsBackup;
}, },
[mutationTypes.RESET_ITEMS_FOR_LIST]: (state, listId) => {
Vue.set(state, 'backupItemsList', state.boardItemsByListId[listId]);
Vue.set(state.boardItemsByListId, listId, []);
},
[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 });
}, },
...@@ -141,6 +143,7 @@ export default { ...@@ -141,6 +143,7 @@ export default {
'Boards|An error occurred while fetching the board issues. Please reload the page.', 'Boards|An error occurred while fetching the board issues. Please reload the page.',
); );
Vue.set(state.listsFlags, listId, { isLoading: false, isLoadingMore: false }); Vue.set(state.listsFlags, listId, { isLoading: false, isLoadingMore: false });
Vue.set(state.boardItemsByListId, listId, state.backupItemsList);
}, },
[mutationTypes.RESET_ISSUES]: (state) => { [mutationTypes.RESET_ISSUES]: (state) => {
......
...@@ -11,6 +11,7 @@ export default () => ({ ...@@ -11,6 +11,7 @@ export default () => ({
boardLists: {}, boardLists: {},
listsFlags: {}, listsFlags: {},
boardItemsByListId: {}, boardItemsByListId: {},
backupItemsList: [],
isSettingAssignees: false, isSettingAssignees: false,
pageInfoByListId: {}, pageInfoByListId: {},
boardItems: {}, boardItems: {},
......
...@@ -245,6 +245,9 @@ export default { ...@@ -245,6 +245,9 @@ export default {
{ state, commit, getters }, { state, commit, getters },
{ listId, fetchNext = false, noEpicIssues = false, forSwimlanes = false }, { listId, fetchNext = false, noEpicIssues = false, forSwimlanes = false },
) => { ) => {
if (!fetchNext && !state.isShowingEpicsSwimlanes) {
commit(types.RESET_ITEMS_FOR_LIST, listId);
}
commit(types.REQUEST_ITEMS_FOR_LIST, { listId, fetchNext }); commit(types.REQUEST_ITEMS_FOR_LIST, { listId, fetchNext });
const { epicId, ...filterParams } = state.filterParams; const { epicId, ...filterParams } = state.filterParams;
......
...@@ -46,6 +46,7 @@ export default { ...@@ -46,6 +46,7 @@ export default {
? ErrorMessages.fetchEpicsError ? ErrorMessages.fetchEpicsError
: ErrorMessages.fetchIssueError; : ErrorMessages.fetchIssueError;
Vue.set(state.listsFlags, listId, { isLoading: false, isLoadingMore: false }); Vue.set(state.listsFlags, listId, { isLoading: false, isLoadingMore: false });
Vue.set(state.boardItemsByListId, listId, state.backupItemsList);
}, },
[mutationTypes.TOGGLE_EPICS_SWIMLANES]: (state) => { [mutationTypes.TOGGLE_EPICS_SWIMLANES]: (state) => {
......
...@@ -288,7 +288,7 @@ describe('fetchEpicsSwimlanes', () => { ...@@ -288,7 +288,7 @@ describe('fetchEpicsSwimlanes', () => {
describe('fetchItemsForList', () => { describe('fetchItemsForList', () => {
const listId = mockLists[0].id; const listId = mockLists[0].id;
const state = { let state = {
fullPath: 'gitlab-org', fullPath: 'gitlab-org',
boardId: '1', boardId: '1',
filterParams: {}, filterParams: {},
...@@ -329,6 +329,10 @@ describe('fetchItemsForList', () => { ...@@ -329,6 +329,10 @@ describe('fetchItemsForList', () => {
}; };
it('add epicWildcardId with ANY as value when forSwimlanes is true', () => { it('add epicWildcardId with ANY as value when forSwimlanes is true', () => {
state = {
...state,
isShowingEpicsSwimlanes: true,
};
jest.spyOn(gqlClient, 'query').mockResolvedValue(queryResponse); jest.spyOn(gqlClient, 'query').mockResolvedValue(queryResponse);
testAction( testAction(
......
...@@ -676,6 +676,10 @@ describe('fetchItemsForList', () => { ...@@ -676,6 +676,10 @@ describe('fetchItemsForList', () => {
{ listId }, { listId },
state, state,
[ [
{
type: types.RESET_ITEMS_FOR_LIST,
payload: listId,
},
{ {
type: types.REQUEST_ITEMS_FOR_LIST, type: types.REQUEST_ITEMS_FOR_LIST,
payload: { listId, fetchNext: false }, payload: { listId, fetchNext: false },
...@@ -698,6 +702,10 @@ describe('fetchItemsForList', () => { ...@@ -698,6 +702,10 @@ describe('fetchItemsForList', () => {
{ listId }, { listId },
state, state,
[ [
{
type: types.RESET_ITEMS_FOR_LIST,
payload: listId,
},
{ {
type: types.REQUEST_ITEMS_FOR_LIST, type: types.REQUEST_ITEMS_FOR_LIST,
payload: { listId, fetchNext: false }, payload: { listId, fetchNext: false },
......
...@@ -273,6 +273,24 @@ describe('Board Store Mutations', () => { ...@@ -273,6 +273,24 @@ describe('Board Store Mutations', () => {
}); });
}); });
describe('RESET_ITEMS_FOR_LIST', () => {
it('should remove issues from boardItemsByListId state', () => {
const listId = 'gid://gitlab/List/1';
const boardItemsByListId = {
[listId]: [mockIssue.id],
};
state = {
...state,
boardItemsByListId,
};
mutations[types.RESET_ITEMS_FOR_LIST](state, listId);
expect(state.boardItemsByListId[listId]).toEqual([]);
});
});
describe('REQUEST_ITEMS_FOR_LIST', () => { describe('REQUEST_ITEMS_FOR_LIST', () => {
const listId = 'gid://gitlab/List/1'; const listId = 'gid://gitlab/List/1';
const boardItemsByListId = { const boardItemsByListId = {
...@@ -280,12 +298,12 @@ describe('Board Store Mutations', () => { ...@@ -280,12 +298,12 @@ describe('Board Store Mutations', () => {
}; };
it.each` it.each`
fetchNext | isLoading | isLoadingMore | listItems fetchNext | isLoading | isLoadingMore
${true} | ${undefined} | ${true} | ${boardItemsByListId[listId]} ${true} | ${undefined} | ${true}
${false} | ${true} | ${undefined} | ${[]} ${false} | ${true} | ${undefined}
`( `(
'sets isLoading to $isLoading and isLoadingMore to $isLoadingMore when fetchNext is $fetchNext', 'sets isLoading to $isLoading and isLoadingMore to $isLoadingMore when fetchNext is $fetchNext',
({ fetchNext, isLoading, isLoadingMore, listItems }) => { ({ fetchNext, isLoading, isLoadingMore }) => {
state = { state = {
...state, ...state,
boardItemsByListId, boardItemsByListId,
...@@ -298,7 +316,6 @@ describe('Board Store Mutations', () => { ...@@ -298,7 +316,6 @@ describe('Board Store Mutations', () => {
expect(state.listsFlags[listId].isLoading).toBe(isLoading); expect(state.listsFlags[listId].isLoading).toBe(isLoading);
expect(state.listsFlags[listId].isLoadingMore).toBe(isLoadingMore); expect(state.listsFlags[listId].isLoadingMore).toBe(isLoadingMore);
expect(state.boardItemsByListId[listId]).toEqual(listItems);
}, },
); );
}); });
......
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