Commit 7a227261 authored by Coung Ngo's avatar Coung Ngo

Add page params to group/project issues list refactor

Add url params for pagination so the user can go back to the
same paginated position.

Behind feature flag `vue_issues_list` defaulted to off

https://gitlab.com/gitlab-org/gitlab/-/issues/322755
parent 95b17b01
...@@ -42,6 +42,8 @@ import { ...@@ -42,6 +42,8 @@ import {
ISSUE_REFERENCE, ISSUE_REFERENCE,
MAX_LIST_SIZE, MAX_LIST_SIZE,
PAGE_SIZE, PAGE_SIZE,
PARAM_PAGE_AFTER,
PARAM_PAGE_BEFORE,
PARAM_STATE, PARAM_STATE,
RELATIVE_POSITION_ASC, RELATIVE_POSITION_ASC,
TOKEN_TYPE_ASSIGNEE, TOKEN_TYPE_ASSIGNEE,
...@@ -135,6 +137,8 @@ export default { ...@@ -135,6 +137,8 @@ export default {
}, },
}, },
data() { data() {
const pageAfter = getParameterByName(PARAM_PAGE_AFTER);
const pageBefore = getParameterByName(PARAM_PAGE_BEFORE);
const state = getParameterByName(PARAM_STATE); const state = getParameterByName(PARAM_STATE);
const defaultSortKey = state === IssuableStates.Closed ? UPDATED_DESC : CREATED_DESC; const defaultSortKey = state === IssuableStates.Closed ? UPDATED_DESC : CREATED_DESC;
const dashboardSortKey = getSortKey(this.initialSort); const dashboardSortKey = getSortKey(this.initialSort);
...@@ -166,7 +170,7 @@ export default { ...@@ -166,7 +170,7 @@ export default {
issuesCounts: {}, issuesCounts: {},
issuesError: null, issuesError: null,
pageInfo: {}, pageInfo: {},
pageParams: getInitialPageParams(sortKey), pageParams: getInitialPageParams(sortKey, pageAfter, pageBefore),
showBulkEditSidebar: false, showBulkEditSidebar: false,
sortKey, sortKey,
state: state || IssuableStates.Opened, state: state || IssuableStates.Opened,
...@@ -237,7 +241,12 @@ export default { ...@@ -237,7 +241,12 @@ export default {
return this.isProject ? ITEM_TYPE.PROJECT : ITEM_TYPE.GROUP; return this.isProject ? ITEM_TYPE.PROJECT : ITEM_TYPE.GROUP;
}, },
hasSearch() { hasSearch() {
return this.searchQuery || Object.keys(this.urlFilterParams).length; return (
this.searchQuery ||
Object.keys(this.urlFilterParams).length ||
this.pageParams.afterCursor ||
this.pageParams.beforeCursor
);
}, },
isBulkEditButtonDisabled() { isBulkEditButtonDisabled() {
return this.showBulkEditSidebar || !this.issues.length; return this.showBulkEditSidebar || !this.issues.length;
...@@ -394,6 +403,8 @@ export default { ...@@ -394,6 +403,8 @@ export default {
}, },
urlParams() { urlParams() {
return { return {
page_after: this.pageParams.afterCursor,
page_before: this.pageParams.beforeCursor,
search: this.searchQuery, search: this.searchQuery,
sort: urlSortParams[this.sortKey], sort: urlSortParams[this.sortKey],
state: this.state, state: this.state,
......
...@@ -56,17 +56,11 @@ export const ISSUE_REFERENCE = /^#\d+$/; ...@@ -56,17 +56,11 @@ export const ISSUE_REFERENCE = /^#\d+$/;
export const MAX_LIST_SIZE = 10; export const MAX_LIST_SIZE = 10;
export const PAGE_SIZE = 20; export const PAGE_SIZE = 20;
export const PAGE_SIZE_MANUAL = 100; export const PAGE_SIZE_MANUAL = 100;
export const PARAM_PAGE_AFTER = 'page_after';
export const PARAM_PAGE_BEFORE = 'page_before';
export const PARAM_STATE = 'state'; export const PARAM_STATE = 'state';
export const RELATIVE_POSITION = 'relative_position'; export const RELATIVE_POSITION = 'relative_position';
export const defaultPageSizeParams = {
firstPageSize: PAGE_SIZE,
};
export const largePageSizeParams = {
firstPageSize: PAGE_SIZE_MANUAL,
};
export const BLOCKING_ISSUES_ASC = 'BLOCKING_ISSUES_ASC'; export const BLOCKING_ISSUES_ASC = 'BLOCKING_ISSUES_ASC';
export const BLOCKING_ISSUES_DESC = 'BLOCKING_ISSUES_DESC'; export const BLOCKING_ISSUES_DESC = 'BLOCKING_ISSUES_DESC';
export const CREATED_ASC = 'CREATED_ASC'; export const CREATED_ASC = 'CREATED_ASC';
......
...@@ -10,16 +10,16 @@ import { ...@@ -10,16 +10,16 @@ import {
BLOCKING_ISSUES_DESC, BLOCKING_ISSUES_DESC,
CREATED_ASC, CREATED_ASC,
CREATED_DESC, CREATED_DESC,
defaultPageSizeParams,
DUE_DATE_ASC, DUE_DATE_ASC,
DUE_DATE_DESC, DUE_DATE_DESC,
filters, filters,
LABEL_PRIORITY_ASC, LABEL_PRIORITY_ASC,
LABEL_PRIORITY_DESC, LABEL_PRIORITY_DESC,
largePageSizeParams,
MILESTONE_DUE_ASC, MILESTONE_DUE_ASC,
MILESTONE_DUE_DESC, MILESTONE_DUE_DESC,
NORMAL_FILTER, NORMAL_FILTER,
PAGE_SIZE,
PAGE_SIZE_MANUAL,
POPULARITY_ASC, POPULARITY_ASC,
POPULARITY_DESC, POPULARITY_DESC,
PRIORITY_ASC, PRIORITY_ASC,
...@@ -43,8 +43,11 @@ import { ...@@ -43,8 +43,11 @@ import {
WEIGHT_DESC, WEIGHT_DESC,
} from './constants'; } from './constants';
export const getInitialPageParams = (sortKey) => export const getInitialPageParams = (sortKey, afterCursor, beforeCursor) => ({
sortKey === RELATIVE_POSITION_ASC ? largePageSizeParams : defaultPageSizeParams; firstPageSize: sortKey === RELATIVE_POSITION_ASC ? PAGE_SIZE_MANUAL : PAGE_SIZE,
afterCursor,
beforeCursor,
});
export const getSortKey = (sort) => export const getSortKey = (sort) =>
Object.keys(urlSortParams).find((key) => urlSortParams[key] === sort); Object.keys(urlSortParams).find((key) => urlSortParams[key] === sort);
......
...@@ -294,6 +294,28 @@ describe('CE IssuesListApp component', () => { ...@@ -294,6 +294,28 @@ describe('CE IssuesListApp component', () => {
}); });
describe('initial url params', () => { describe('initial url params', () => {
describe('page', () => {
it('page_after is set from the url params', () => {
setWindowLocation('?page_after=randomCursorString');
wrapper = mountComponent();
expect(findIssuableList().props('urlParams')).toMatchObject({
page_after: 'randomCursorString',
});
});
it('page_before is set from the url params', () => {
setWindowLocation('?page_before=anotherRandomCursorString');
wrapper = mountComponent();
expect(findIssuableList().props('urlParams')).toMatchObject({
page_before: 'anotherRandomCursorString',
});
});
});
describe('search', () => { describe('search', () => {
it('is set from the url params', () => { it('is set from the url params', () => {
setWindowLocation(locationSearch); setWindowLocation(locationSearch);
...@@ -881,7 +903,12 @@ describe('CE IssuesListApp component', () => { ...@@ -881,7 +903,12 @@ describe('CE IssuesListApp component', () => {
}); });
it('does not update IssuableList with url params ', async () => { it('does not update IssuableList with url params ', async () => {
const defaultParams = { sort: 'created_date', state: 'opened' }; const defaultParams = {
page_after: null,
page_before: null,
sort: 'created_date',
state: 'opened',
};
expect(findIssuableList().props('urlParams')).toEqual(defaultParams); expect(findIssuableList().props('urlParams')).toEqual(defaultParams);
}); });
......
...@@ -9,8 +9,8 @@ import { ...@@ -9,8 +9,8 @@ import {
urlParamsWithSpecialValues, urlParamsWithSpecialValues,
} from 'jest/issues/list/mock_data'; } from 'jest/issues/list/mock_data';
import { import {
defaultPageSizeParams, PAGE_SIZE,
largePageSizeParams, PAGE_SIZE_MANUAL,
RELATIVE_POSITION_ASC, RELATIVE_POSITION_ASC,
urlSortParams, urlSortParams,
} from '~/issues/list/constants'; } from '~/issues/list/constants';
...@@ -29,10 +29,37 @@ describe('getInitialPageParams', () => { ...@@ -29,10 +29,37 @@ describe('getInitialPageParams', () => {
it.each(Object.keys(urlSortParams))( it.each(Object.keys(urlSortParams))(
'returns the correct page params for sort key %s', 'returns the correct page params for sort key %s',
(sortKey) => { (sortKey) => {
const expectedPageParams = const firstPageSize = sortKey === RELATIVE_POSITION_ASC ? PAGE_SIZE_MANUAL : PAGE_SIZE;
sortKey === RELATIVE_POSITION_ASC ? largePageSizeParams : defaultPageSizeParams;
expect(getInitialPageParams(sortKey)).toBe(expectedPageParams); expect(getInitialPageParams(sortKey)).toEqual({ firstPageSize });
},
);
it.each(Object.keys(urlSortParams))(
'returns the correct page params for sort key %s with afterCursor',
(sortKey) => {
const firstPageSize = sortKey === RELATIVE_POSITION_ASC ? PAGE_SIZE_MANUAL : PAGE_SIZE;
const afterCursor = 'randomCursorString';
const beforeCursor = undefined;
expect(getInitialPageParams(sortKey, afterCursor, beforeCursor)).toEqual({
firstPageSize,
afterCursor,
});
},
);
it.each(Object.keys(urlSortParams))(
'returns the correct page params for sort key %s with beforeCursor',
(sortKey) => {
const firstPageSize = sortKey === RELATIVE_POSITION_ASC ? PAGE_SIZE_MANUAL : PAGE_SIZE;
const afterCursor = undefined;
const beforeCursor = 'anotherRandomCursorString';
expect(getInitialPageParams(sortKey, afterCursor, beforeCursor)).toEqual({
firstPageSize,
beforeCursor,
});
}, },
); );
}); });
......
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