Commit 62b147f1 authored by Simon Knox's avatar Simon Knox

Merge branch 'ss/dont-call-list-items' into 'master'

Only call fetch list items in graphql boards when list is not collapsed

See merge request gitlab-org/gitlab!65381
parents ae94bd46 1f64f651
...@@ -41,7 +41,7 @@ export default { ...@@ -41,7 +41,7 @@ export default {
watch: { watch: {
filterParams: { filterParams: {
handler() { handler() {
if (this.list.id) { if (this.list.id && !this.list.collapsed) {
this.fetchItemsForList({ listId: this.list.id }); this.fetchItemsForList({ listId: this.list.id });
} }
}, },
......
...@@ -240,7 +240,7 @@ export default { ...@@ -240,7 +240,7 @@ export default {
}, },
updateList: ( updateList: (
{ commit, state: { issuableType } }, { commit, state: { issuableType, boardItemsByListId = {} }, dispatch },
{ listId, position, collapsed, backupList }, { listId, position, collapsed, backupList },
) => { ) => {
gqlClient gqlClient
...@@ -255,6 +255,12 @@ export default { ...@@ -255,6 +255,12 @@ export default {
.then(({ data }) => { .then(({ data }) => {
if (data?.updateBoardList?.errors.length) { if (data?.updateBoardList?.errors.length) {
commit(types.UPDATE_LIST_FAILURE, backupList); commit(types.UPDATE_LIST_FAILURE, backupList);
return;
}
// Only fetch when board items havent been fetched on a collapsed list
if (!boardItemsByListId[listId]) {
dispatch('fetchItemsForList', { listId });
} }
}) })
.catch(() => { .catch(() => {
......
...@@ -15,6 +15,10 @@ describe('Board Column Component', () => { ...@@ -15,6 +15,10 @@ describe('Board Column Component', () => {
wrapper = null; wrapper = null;
}); });
const initStore = () => {
store = createStore();
};
const createComponent = ({ listType = ListType.backlog, collapsed = false } = {}) => { const createComponent = ({ listType = ListType.backlog, collapsed = false } = {}) => {
const boardId = '1'; const boardId = '1';
...@@ -29,8 +33,6 @@ describe('Board Column Component', () => { ...@@ -29,8 +33,6 @@ describe('Board Column Component', () => {
listMock.assignee = {}; listMock.assignee = {};
} }
store = createStore();
wrapper = shallowMount(BoardColumn, { wrapper = shallowMount(BoardColumn, {
store, store,
propsData: { propsData: {
...@@ -47,6 +49,10 @@ describe('Board Column Component', () => { ...@@ -47,6 +49,10 @@ describe('Board Column Component', () => {
const isCollapsed = () => wrapper.classes('is-collapsed'); const isCollapsed = () => wrapper.classes('is-collapsed');
describe('Given different list types', () => { describe('Given different list types', () => {
beforeEach(() => {
initStore();
});
it('is expandable when List Type is `backlog`', () => { it('is expandable when List Type is `backlog`', () => {
createComponent({ listType: ListType.backlog }); createComponent({ listType: ListType.backlog });
...@@ -79,4 +85,31 @@ describe('Board Column Component', () => { ...@@ -79,4 +85,31 @@ describe('Board Column Component', () => {
expect(wrapper.element.scrollIntoView).toHaveBeenCalled(); expect(wrapper.element.scrollIntoView).toHaveBeenCalled();
}); });
}); });
describe('on mount', () => {
beforeEach(async () => {
initStore();
jest.spyOn(store, 'dispatch').mockImplementation();
});
describe('when list is collapsed', () => {
it('does not call fetchItemsForList when', async () => {
createComponent({ collapsed: true });
await nextTick();
expect(store.dispatch).toHaveBeenCalledTimes(0);
});
});
describe('when the list is not collapsed', () => {
it('calls fetchItemsForList when', async () => {
createComponent({ collapsed: false });
await nextTick();
expect(store.dispatch).toHaveBeenCalledWith('fetchItemsForList', { listId: 300 });
});
});
});
}); });
...@@ -492,6 +492,63 @@ describe('moveList', () => { ...@@ -492,6 +492,63 @@ describe('moveList', () => {
}); });
describe('updateList', () => { describe('updateList', () => {
const listId = 'gid://gitlab/List/1';
const createState = (boardItemsByListId = {}) => ({
fullPath: 'gitlab-org',
fullBoardId: 'gid://gitlab/Board/1',
boardType: 'group',
disabled: false,
boardLists: [{ type: 'closed' }],
issuableType: issuableTypes.issue,
boardItemsByListId,
});
describe('when state doesnt have list items', () => {
it('calls fetchItemsByList', async () => {
const dispatch = jest.fn();
jest.spyOn(gqlClient, 'mutate').mockResolvedValue({
data: {
updateBoardList: {
errors: [],
list: {
id: listId,
},
},
},
});
await actions.updateList({ commit: () => {}, state: createState(), dispatch }, { listId });
expect(dispatch.mock.calls).toEqual([['fetchItemsForList', { listId }]]);
});
});
describe('when state has list items', () => {
it('doesnt call fetchItemsByList', async () => {
const commit = jest.fn();
const dispatch = jest.fn();
jest.spyOn(gqlClient, 'mutate').mockResolvedValue({
data: {
updateBoardList: {
errors: [],
list: {
id: listId,
},
},
},
});
await actions.updateList(
{ commit, state: createState({ [listId]: [] }), dispatch },
{ listId },
);
expect(dispatch.mock.calls).toEqual([]);
});
});
it('should commit UPDATE_LIST_FAILURE mutation when API returns an error', (done) => { it('should commit UPDATE_LIST_FAILURE mutation when API returns an error', (done) => {
jest.spyOn(gqlClient, 'mutate').mockResolvedValue({ jest.spyOn(gqlClient, 'mutate').mockResolvedValue({
data: { data: {
...@@ -502,19 +559,10 @@ describe('updateList', () => { ...@@ -502,19 +559,10 @@ describe('updateList', () => {
}, },
}); });
const state = {
fullPath: 'gitlab-org',
fullBoardId: 'gid://gitlab/Board/1',
boardType: 'group',
disabled: false,
boardLists: [{ type: 'closed' }],
issuableType: issuableTypes.issue,
};
testAction( testAction(
actions.updateList, actions.updateList,
{ listId: 'gid://gitlab/List/1', position: 1 }, { listId: 'gid://gitlab/List/1', position: 1 },
state, createState(),
[{ type: types.UPDATE_LIST_FAILURE }], [{ type: types.UPDATE_LIST_FAILURE }],
[], [],
done, done,
......
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