From b94de4bae085ba62682f3257aba29cc0ac6799e4 Mon Sep 17 00:00:00 2001 From: Priyanka Terala Date: Tue, 3 Sep 2024 15:14:42 +0530 Subject: [PATCH] UIPFU-96 - Switch between pagination types based on filter selection --- src/UserSearchContainer.js | 22 +++++++++++----------- src/UserSearchView.js | 21 ++++++++++++++++++++- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/UserSearchContainer.js b/src/UserSearchContainer.js index ca8790b..61e438d 100644 --- a/src/UserSearchContainer.js +++ b/src/UserSearchContainer.js @@ -161,19 +161,19 @@ class UserSearchContainer extends React.Component { this.source.update(this.props); } - onNeedMoreData = (askAmount, index) => { + onNeedMoreData = (askAmount, index, firstINdex, direction) => { const { resultOffset } = this.props.mutator; - let offset = index; - if (offset < askAmount) { - /* - This condition sets offset to 100 when there are less than 100 records in the current - paginated result in order to skip the first 100 records and make an API call to fetch next 100. - */ - offset = 100; - } + + const fetchedUsers = get(this.props.resources, 'records.records', []); + const totalUserRecords = this.source.totalCount(); + if (this.source) { - if (resultOffset && offset >= 0) { - this.source.fetchOffset(offset); + if (!direction) { + if (fetchedUsers.length < totalUserRecords) { + this.source.fetchOffset(fetchedUsers.length); + } + } else if (resultOffset && index >= 0) { + this.source.fetchOffset(index); } else { this.source.fetchMore(RESULT_COUNT_INCREMENT); } diff --git a/src/UserSearchView.js b/src/UserSearchView.js index 546f79c..1b018c3 100644 --- a/src/UserSearchView.js +++ b/src/UserSearchView.js @@ -181,6 +181,25 @@ class UserSearchView extends React.Component { return filterConfig; } + getPagingType = (activeFilters) => { + const { data, source } = this.props; + const { users } = data; + let pagingType = MCLPagingTypes.PREV_NEXT; + + /** + * 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; + } + + return pagingType; + }; + render() { const { onSelectRow, @@ -389,7 +408,7 @@ class UserSearchView extends React.Component { isEmptyMessage={resultsStatusMessage} autosize pageAmount={100} - pagingType={MCLPagingTypes.PREV_NEXT} + pagingType={this.getPagingType(activeFilters)} />