-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EPMRPP-96415 || Default number of items per page is displayed when us… #4065
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ import { | |
import { ALL } from 'common/constants/reservedFilterIds'; | ||
import { ADMINISTRATOR } from 'common/constants/accountRoles'; | ||
import { MANAGER } from 'common/constants/projectRoles'; | ||
import { getAlternativePaginationAndSortParams } from 'controllers/pagination'; | ||
import { pageNames, NO_PAGE } from './constants'; | ||
import { stringToArray } from './utils'; | ||
|
||
|
@@ -105,6 +106,7 @@ export const prevPagePropertiesSelector = ( | |
|
||
export const createQueryParametersSelector = ({ | ||
namespace: staticNamespace, | ||
alternativeNamespace, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why the existing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When everyone switches to the same pagination format, then you can leave one option. |
||
defaultPagination, | ||
defaultSorting, | ||
sortingKey = SORTING_KEY, | ||
|
@@ -124,14 +126,35 @@ export const createQueryParametersSelector = ({ | |
if (Number(queryParameters[PAGE_KEY]) < 0) { | ||
queryParameters[PAGE_KEY] = calculatedPagination[PAGE_KEY]; | ||
} | ||
if ((!query[SIZE_KEY] || Number(query[SIZE_KEY]) < 0) && calculatedNamespace) { | ||
|
||
const currentNamespace = calculatedNamespace || alternativeNamespace; | ||
|
||
if ((!query[SIZE_KEY] || Number(query[SIZE_KEY]) < 0) && currentNamespace) { | ||
const userId = userIdSelector(state); | ||
const userSettings = getStorageItem(`${userId}_settings`) || {}; | ||
queryParameters[SIZE_KEY] = userSettings[`${calculatedNamespace}PageSize`] || defaultPageSize; | ||
queryParameters[SIZE_KEY] = userSettings[`${currentNamespace}PageSize`] || defaultPageSize; | ||
} | ||
return queryParameters; | ||
}; | ||
|
||
export const createAlternativeQueryParametersSelector = ({ | ||
defaultPagination, | ||
defaultSorting, | ||
sortingKey, | ||
alternativeNamespace, | ||
} = {}) => | ||
createSelector( | ||
createQueryParametersSelector({ | ||
defaultPagination, | ||
defaultSorting, | ||
sortingKey, | ||
alternativeNamespace, | ||
}), | ||
({ [SIZE_KEY]: limit, [SORTING_KEY]: sort, [PAGE_KEY]: pageNumber, ...rest }) => { | ||
return { ...getAlternativePaginationAndSortParams(sort, limit, pageNumber), ...rest }; | ||
}, | ||
); | ||
|
||
export const launchIdSelector = (state) => { | ||
const testItemIds = testItemIdsArraySelector(state); | ||
return testItemIds?.[0]; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ export const withPagination = ({ | |
paginationSelector = defaultPaginationSelector, | ||
namespace, | ||
namespaceSelector, | ||
alternativeNamespace, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When everyone switches to the same pagination format, then you can leave one option. |
||
offset, | ||
} = {}) => (WrappedComponent) => { | ||
const getTotalElements = totalElementsSelector(paginationSelector); | ||
|
@@ -47,6 +48,7 @@ export const withPagination = ({ | |
totalElements: getTotalElements(state), | ||
totalPages: getTotalPages(state), | ||
namespace: namespaceSelector ? namespaceSelector(state) : namespace, | ||
alternativeNamespace, | ||
userId: userIdSelector(state), | ||
})) | ||
class PaginationWrapper extends Component { | ||
|
@@ -61,6 +63,7 @@ export const withPagination = ({ | |
totalElements: PropTypes.number, | ||
totalPages: PropTypes.number, | ||
namespace: PropTypes.string, | ||
alternativeNamespace: PropTypes.string, | ||
userId: PropTypes.string.isRequired, | ||
}; | ||
|
||
|
@@ -84,7 +87,7 @@ export const withPagination = ({ | |
|
||
getPageSize = () => { | ||
const { size, userId } = this.props; | ||
if (size === undefined && this.props.namespace) { | ||
if (size === undefined && this.getNamespace()) { | ||
const userSettings = getStorageItem(`${userId}_settings`) || {}; | ||
return userSettings[this.calculateFieldName()] || size; | ||
} | ||
|
@@ -97,7 +100,7 @@ export const withPagination = ({ | |
|
||
changeSizeHandler = (size) => { | ||
const { userId } = this.props; | ||
if (this.props.namespace) { | ||
if (this.getNamespace()) { | ||
updateStorageItem(`${userId}_settings`, { | ||
[this.calculateFieldName()]: size, | ||
}); | ||
|
@@ -110,7 +113,9 @@ export const withPagination = ({ | |
this.props.updatePagination(options.page || page, options.size || this.getPageSize()); | ||
}; | ||
|
||
calculateFieldName = () => `${this.props.namespace}PageSize`; | ||
calculateFieldName = () => `${this.getNamespace()}PageSize`; | ||
|
||
getNamespace = () => this.props.namespace || this.props.alternativeNamespace; | ||
|
||
render() { | ||
const { page, size, totalElements, totalPages, updatePagination, ...restProps } = this.props; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should it be replaced by
createAlternativeQueryParametersSelector
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an old pagination and can work via namespace:
But then there will be such parameters:
with an alternative namespace: