Commit b6bbb9c1 authored by Jose Ivan Vargas's avatar Jose Ivan Vargas

Merge branch...

Merge branch '356422-bug-compliance-violations-clicking-prev-always-returns-to-first-page' into 'master'

Fix compliance report prev button always returning to first page

See merge request gitlab-org/gitlab!83315
parents cc1af393 29e78dbc
...@@ -10,7 +10,7 @@ import { helpPagePath } from '~/helpers/help_page_helper'; ...@@ -10,7 +10,7 @@ import { helpPagePath } from '~/helpers/help_page_helper';
import SeverityBadge from 'ee/vue_shared/security_reports/components/severity_badge.vue'; import SeverityBadge from 'ee/vue_shared/security_reports/components/severity_badge.vue';
import getComplianceViolationsQuery from '../graphql/compliance_violations.query.graphql'; import getComplianceViolationsQuery from '../graphql/compliance_violations.query.graphql';
import { mapViolations } from '../graphql/mappers'; import { mapViolations } from '../graphql/mappers';
import { DEFAULT_SORT, GRAPHQL_PAGE_SIZE } from '../constants'; import { DEFAULT_SORT, GRAPHQL_PAGE_SIZE, DEFAULT_PAGINATION_CURSORS } from '../constants';
import { parseViolationsQueryFilter } from '../utils'; import { parseViolationsQueryFilter } from '../utils';
import MergeCommitsExportButton from './merge_requests/merge_commits_export_button.vue'; import MergeCommitsExportButton from './merge_requests/merge_commits_export_button.vue';
import MergeRequestDrawer from './drawer.vue'; import MergeRequestDrawer from './drawer.vue';
...@@ -67,8 +67,7 @@ export default { ...@@ -67,8 +67,7 @@ export default {
sortDesc, sortDesc,
sortParam, sortParam,
paginationCursors: { paginationCursors: {
before: null, ...DEFAULT_PAGINATION_CURSORS,
after: null,
}, },
}; };
}, },
...@@ -80,7 +79,6 @@ export default { ...@@ -80,7 +79,6 @@ export default {
fullPath: this.groupPath, fullPath: this.groupPath,
filters: parseViolationsQueryFilter(this.urlQuery), filters: parseViolationsQueryFilter(this.urlQuery),
sort: this.sortParam, sort: this.sortParam,
first: GRAPHQL_PAGE_SIZE,
...this.paginationCursors, ...this.paginationCursors,
}; };
}, },
...@@ -149,20 +147,21 @@ export default { ...@@ -149,20 +147,21 @@ export default {
}, },
resetPagination() { resetPagination() {
this.paginationCursors = { this.paginationCursors = {
before: null, ...DEFAULT_PAGINATION_CURSORS,
after: null,
}; };
}, },
loadPrevPage(startCursor) { loadPrevPage(startCursor) {
this.paginationCursors = { this.paginationCursors = {
before: startCursor, before: startCursor,
after: null, after: null,
last: GRAPHQL_PAGE_SIZE,
}; };
}, },
loadNextPage(endCursor) { loadNextPage(endCursor) {
this.paginationCursors = { this.paginationCursors = {
before: null, before: null,
after: endCursor, after: endCursor,
first: GRAPHQL_PAGE_SIZE,
}; };
}, },
}, },
......
...@@ -27,3 +27,9 @@ export const MERGE_REQUEST_VIOLATION_MESSAGES = { ...@@ -27,3 +27,9 @@ export const MERGE_REQUEST_VIOLATION_MESSAGES = {
}; };
export const DEFAULT_SORT = 'SEVERITY_LEVEL_DESC'; export const DEFAULT_SORT = 'SEVERITY_LEVEL_DESC';
export const DEFAULT_PAGINATION_CURSORS = {
before: null,
after: null,
first: GRAPHQL_PAGE_SIZE,
};
...@@ -7,6 +7,7 @@ query getComplianceViolations( ...@@ -7,6 +7,7 @@ query getComplianceViolations(
$after: String $after: String
$before: String $before: String
$first: Int $first: Int
$last: Int
) { ) {
group(fullPath: $fullPath) { group(fullPath: $fullPath) {
id id
...@@ -16,6 +17,7 @@ query getComplianceViolations( ...@@ -16,6 +17,7 @@ query getComplianceViolations(
after: $after after: $after
before: $before before: $before
first: $first first: $first
last: $last
) { ) {
nodes { nodes {
id id
......
...@@ -20,7 +20,11 @@ import UrlSync from '~/vue_shared/components/url_sync.vue'; ...@@ -20,7 +20,11 @@ import UrlSync from '~/vue_shared/components/url_sync.vue';
import { stubComponent } from 'helpers/stub_component'; import { stubComponent } from 'helpers/stub_component';
import { sortObjectToString } from '~/lib/utils/table_utility'; import { sortObjectToString } from '~/lib/utils/table_utility';
import { parseViolationsQueryFilter } from 'ee/compliance_dashboard/utils'; import { parseViolationsQueryFilter } from 'ee/compliance_dashboard/utils';
import { DEFAULT_SORT, GRAPHQL_PAGE_SIZE } from 'ee/compliance_dashboard/constants'; import {
DEFAULT_SORT,
GRAPHQL_PAGE_SIZE,
DEFAULT_PAGINATION_CURSORS,
} from 'ee/compliance_dashboard/constants';
import { createComplianceViolationsResponse } from '../mock_data'; import { createComplianceViolationsResponse } from '../mock_data';
Vue.use(VueApollo); Vue.use(VueApollo);
...@@ -158,9 +162,7 @@ describe('ComplianceReport component', () => { ...@@ -158,9 +162,7 @@ describe('ComplianceReport component', () => {
fullPath: groupPath, fullPath: groupPath,
filters: parseViolationsQueryFilter(defaultFilterParams), filters: parseViolationsQueryFilter(defaultFilterParams),
sort: DEFAULT_SORT, sort: DEFAULT_SORT,
first: GRAPHQL_PAGE_SIZE, ...DEFAULT_PAGINATION_CURSORS,
after: null,
before: null,
}); });
}); });
}); });
...@@ -182,9 +184,7 @@ describe('ComplianceReport component', () => { ...@@ -182,9 +184,7 @@ describe('ComplianceReport component', () => {
fullPath: groupPath, fullPath: groupPath,
filters: parseViolationsQueryFilter(defaultFilterParams), filters: parseViolationsQueryFilter(defaultFilterParams),
sort, sort,
first: GRAPHQL_PAGE_SIZE, ...DEFAULT_PAGINATION_CURSORS,
after: null,
before: null,
}); });
}); });
}); });
...@@ -354,9 +354,7 @@ describe('ComplianceReport component', () => { ...@@ -354,9 +354,7 @@ describe('ComplianceReport component', () => {
fullPath: groupPath, fullPath: groupPath,
filters: parseViolationsQueryFilter(query), filters: parseViolationsQueryFilter(query),
sort: DEFAULT_SORT, sort: DEFAULT_SORT,
first: GRAPHQL_PAGE_SIZE, ...DEFAULT_PAGINATION_CURSORS,
after: null,
before: null,
}); });
}); });
}); });
...@@ -384,9 +382,7 @@ describe('ComplianceReport component', () => { ...@@ -384,9 +382,7 @@ describe('ComplianceReport component', () => {
fullPath: groupPath, fullPath: groupPath,
filters: parseViolationsQueryFilter(defaultFilterParams), filters: parseViolationsQueryFilter(defaultFilterParams),
sort: sortObjectToString(sortState), sort: sortObjectToString(sortState),
first: GRAPHQL_PAGE_SIZE, ...DEFAULT_PAGINATION_CURSORS,
after: null,
before: null,
}); });
}); });
}); });
...@@ -404,12 +400,12 @@ describe('ComplianceReport component', () => { ...@@ -404,12 +400,12 @@ describe('ComplianceReport component', () => {
}); });
it.each` it.each`
event | after | before event | after | before | first | last
${'next'} | ${'foo'} | ${null} ${'next'} | ${'foo'} | ${null} | ${GRAPHQL_PAGE_SIZE} | ${undefined}
${'prev'} | ${null} | ${'foo'} ${'prev'} | ${null} | ${'foo'} | ${undefined} | ${GRAPHQL_PAGE_SIZE}
`( `(
'fetches the $event page when the pagination emits "$event"', 'fetches the $event page when the pagination emits "$event"',
async ({ event, after, before }) => { async ({ event, after, before, first, last }) => {
await findPagination().vm.$emit(event, after ?? before); await findPagination().vm.$emit(event, after ?? before);
await waitForPromises(); await waitForPromises();
...@@ -417,10 +413,11 @@ describe('ComplianceReport component', () => { ...@@ -417,10 +413,11 @@ describe('ComplianceReport component', () => {
expect(mockGraphQlSuccess).toHaveBeenNthCalledWith(2, { expect(mockGraphQlSuccess).toHaveBeenNthCalledWith(2, {
fullPath: groupPath, fullPath: groupPath,
filters: parseViolationsQueryFilter(defaultFilterParams), filters: parseViolationsQueryFilter(defaultFilterParams),
first: GRAPHQL_PAGE_SIZE,
sort: DEFAULT_SORT, sort: DEFAULT_SORT,
after, after,
before, before,
first,
last,
}); });
}, },
); );
...@@ -459,10 +456,8 @@ describe('ComplianceReport component', () => { ...@@ -459,10 +456,8 @@ describe('ComplianceReport component', () => {
expect(mockGraphQlSuccess).toHaveBeenNthCalledWith(3, { expect(mockGraphQlSuccess).toHaveBeenNthCalledWith(3, {
fullPath: groupPath, fullPath: groupPath,
filters: parseViolationsQueryFilter(query), filters: parseViolationsQueryFilter(query),
first: GRAPHQL_PAGE_SIZE,
sort: DEFAULT_SORT, sort: DEFAULT_SORT,
after: null, ...DEFAULT_PAGINATION_CURSORS,
before: null,
}); });
}); });
}); });
......
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