Commit 8e98a446 authored by Daniel Tian's avatar Daniel Tian

Reset paging when sort is changed on vulnerability report

Changelog: fixed
MR: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/81870
EE: true
parent d97d58c1
......@@ -268,6 +268,7 @@ export default {
:thead-class="theadClass"
:sort-desc="sort.sortDesc"
:sort-by="sort.sortBy"
sort-direction="last"
sort-icon-left
no-local-sorting
stacked="sm"
......
......@@ -164,9 +164,14 @@ export default {
this.vulnerabilities = [];
}
},
sort() {
sort(newSort, oldSort) {
// Clear out the vulnerabilities so that the skeleton loader is shown.
this.vulnerabilities = [];
// Anything that changes the querystring will also trigger this watcher (because sort is
// recomputed), so we need to check that the sort has changed before we reset the paging.
if (newSort.sortBy !== oldSort.sortBy || newSort.sortDesc !== oldSort.sortDesc) {
this.resetPaging();
}
},
},
methods: {
......
......@@ -237,6 +237,24 @@ describe('Vulnerability list GraphQL component', () => {
expect.objectContaining({ sort: 'state_desc' }),
);
});
it('will reset paging if the sort has changed', async () => {
createWrapper();
router.push({ query: { after: 'abc' } });
findVulnerabilityList().vm.$emit('update:sort', SORT_OBJECT);
await nextTick();
expect(router.currentRoute.query.after).toBeUndefined();
});
it('will not reset paging when the page changes but sorting has not', async () => {
router.push({ query: SORT_OBJECT });
createWrapper();
router.push({ query: { ...router.currentRoute.query, after: 'abc' } });
await nextTick();
expect(router.currentRoute.query.after).toBe('abc');
});
});
describe('intersection observer', () => {
......
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