Skip to content

Commit

Permalink
UIREQ-11447 - refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
manvendra-s-rathore committed Sep 23, 2024
1 parent 5907197 commit 28b996b
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions src/routes/RequestsRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ class RequestsRoute extends React.Component {
this.setCurrentServicePointId();
}

componentDidUpdate(prevProps, prevState) {
componentDidUpdate(prevProps) {
const patronBlocks = get(this.props.resources, ['patronBlocks', 'records'], []);
const prevBlocks = get(prevProps.resources, ['patronBlocks', 'records'], []);
const { submitting, isViewPrintDetailsEnabled } = this.state;
Expand Down Expand Up @@ -730,25 +730,35 @@ class RequestsRoute extends React.Component {
this.onSearchComplete(resources.records);
}

if (isViewPrintDetailsEnabled !== prevState.isViewPrintDetailsEnabled && !isViewPrintDetailsEnabled) {
this.columnHeadersMap = getFilteredColumnHeadersMap(this.columnHeadersMap);
if (!isViewPrintDetailsEnabled) {
this.handlePrintDetailsDisabled();
}

if (!isViewPrintDetailsEnabled) {
const printStatusFilterInQuery = this.getActiveFilters()[requestFilterTypes.PRINT_STATUS];
this.columnHeadersMap = isViewPrintDetailsEnabled ? this.columnHeadersMap :
getFilteredColumnHeadersMap(this.columnHeadersMap);
}

// If `isViewPrintDetailsEnabled` is false and `filters` in query includes 'PRINT STATUS' filter :-
// it clears the 'PRINT STATUS' filter from query filters by invoking `handleFilterChange`.
if (printStatusFilterInQuery?.length) {
this.handleFilterChange({ name: requestFilterTypes.PRINT_STATUS, values: [] });
}
handlePrintDetailsDisabled() {
/**
* The function handles the following actions when `isViewPrintDetailsEnabled` is false:
*
* 1. If `filters` in query includes 'PRINT STATUS' filter:
* - it clears the 'PRINT STATUS' filter from query by invoking `handleFilterChange`.
*
* 2. If `sort` in query includes sort by 'printed' or 'copies' column:
* - it removes sorting by 'printed' or 'copies' from the sort query. If both are being sorted,
* the sorting is updated to 'requestDate' instead.
*/
const { resources: { query }, mutator } = this.props;
const printStatusFilterInQuery = this.getActiveFilters()[requestFilterTypes.PRINT_STATUS];

if (printStatusFilterInQuery?.length) {
this.handleFilterChange({ name: requestFilterTypes.PRINT_STATUS, values: [] });
}

// Remove 'copies' and 'printed' from query sorting when the user disables
// 'Enable view print details (Pick slips)' in settings and returns to the Requests App.
if (query.sort?.includes('printed') || query.sort?.includes('copies')) {
const sort = updateQuerySortString(query.sort);
mutator.query.update({ sort });
}
if (query.sort?.includes('printed') || query.sort?.includes('copies')) {
const sort = updateQuerySortString(query.sort);
mutator.query.update({ sort });
}
}

Expand Down

0 comments on commit 28b996b

Please sign in to comment.