From 3ee0a8a45b578639909df165a95033ed33fe26ca Mon Sep 17 00:00:00 2001 From: Priyanka Terala Date: Fri, 6 Sep 2024 13:36:09 +0530 Subject: [PATCH] UIPFU-96 - refactor --- CHANGELOG.md | 2 +- src/UserSearchContainer.js | 3 ++- src/UserSearchView.js | 21 ++++++++++++--------- src/constants.js | 1 + 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 27f1d62..be626a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ * Apply Prev/Next Pagination. Refs UIPFU-49. * Use keywords CQL field for keyword user search. Ref UIPFU-95. * Add Jest unit tests for ui-plugin-find-user/src/Filters.js. Refs UIPFU-81. -* Fix pagination issues. Refs UIPFU-96 +* Fix pagination issues with `Unassigned` filter. Refs UIPFU-96. ## [7.1.1](https://github.com/folio-org/ui-plugin-find-user/tree/v7.1.1) (2024-05-03) [Full Changelog](https://github.com/folio-org/ui-plugin-find-user/compare/v7.1.0...v7.1.1) diff --git a/src/UserSearchContainer.js b/src/UserSearchContainer.js index 61e438d..70a8f8a 100644 --- a/src/UserSearchContainer.js +++ b/src/UserSearchContainer.js @@ -15,6 +15,7 @@ import { UNASSIGNED_FILTER_KEY, UAS, ASSIGNED, + UNASSIGNED, } from './constants'; const INITIAL_RESULT_COUNT = 30; @@ -161,7 +162,7 @@ class UserSearchContainer extends React.Component { this.source.update(this.props); } - onNeedMoreData = (askAmount, index, firstINdex, direction) => { + onNeedMoreData = (askAmount, index, firstIndex, direction) => { const { resultOffset } = this.props.mutator; const fetchedUsers = get(this.props.resources, 'records.records', []); diff --git a/src/UserSearchView.js b/src/UserSearchView.js index 1b018c3..94cbd2a 100644 --- a/src/UserSearchView.js +++ b/src/UserSearchView.js @@ -29,6 +29,7 @@ import filterConfig, { filterConfigWithUserAssignedStatus } from './filterConfig import Filters from './Filters'; import css from './UserSearch.css'; +import { UNASSIGNED } from './constants'; function getFullName(user) { let firstName = user?.personal?.firstName ?? ''; @@ -182,22 +183,24 @@ class UserSearchView extends React.Component { } getPagingType = (activeFilters) => { - const { data, source } = this.props; - const { users } = data; - let pagingType = MCLPagingTypes.PREV_NEXT; + const { data: { users }, source } = this.props; + const { state } = activeFilters; + const { uas } = state || {}; /** * if active filter contain "Unassigned", switch to "LOAD_MORE" paging type. * at the page, mark the pagination as "NONE" */ - if (activeFilters.state?.uas?.length === 1) { - if (activeFilters.state.uas[0] === 'Unassigned') { - if (source?.resources?.records?.records.length >= users.count) pagingType = MCLPagingTypes.NONE; - else pagingType = MCLPagingTypes.LOAD_MORE; - } else pagingType = MCLPagingTypes.NONE; + if (!uas || uas.length !== 1) { + return MCLPagingTypes.PREV_NEXT; } - return pagingType; + if (uas[0] !== UNASSIGNED) { + return MCLPagingTypes.NONE; + } + + const recordsCount = source?.resources?.records?.records.length || 0; + return recordsCount >= users.count ? MCLPagingTypes.NONE : MCLPagingTypes.LOAD_MORE; }; render() { diff --git a/src/constants.js b/src/constants.js index 39e2339..338758c 100644 --- a/src/constants.js +++ b/src/constants.js @@ -3,3 +3,4 @@ export const UAS = 'uas'; export const ASSIGNED_FILTER_KEY = 'uas.Assigned'; export const UNASSIGNED_FILTER_KEY = 'uas.Unassigned'; export const ASSIGNED = 'Assigned'; +export const UNASSIGNED = 'Unassigned';