Skip to content

Commit

Permalink
UIPFU-96 - refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Terala-Priyanka committed Sep 6, 2024
1 parent ef08291 commit 3ee0a8a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion src/UserSearchContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
UNASSIGNED_FILTER_KEY,
UAS,
ASSIGNED,
UNASSIGNED,
} from './constants';

const INITIAL_RESULT_COUNT = 30;
Expand Down Expand Up @@ -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', []);
Expand Down
21 changes: 12 additions & 9 deletions src/UserSearchView.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?? '';
Expand Down Expand Up @@ -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() {
Expand Down
1 change: 1 addition & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

0 comments on commit 3ee0a8a

Please sign in to comment.