From 33e91a7fe78d08dd04a942ee277d835b787a8a45 Mon Sep 17 00:00:00 2001 From: Priyanka Date: Wed, 29 Nov 2023 16:30:51 +0530 Subject: [PATCH] UIU-2988-poppy-dcb - User - Open Loans: UI changes for supporting DCB circulation --- CHANGELOG.md | 1 + .../ActionsDropdown/ActionsDropdown.js | 114 +++++++++++------- .../ActionsDropdown/ActionsDropdown.test.js | 58 ++++++++- .../OpenLoansSubHeader/OpenLoansSubHeader.js | 82 +++++++------ .../OpenLoansSubHeader.test.js | 64 ++++++++++ src/components/util/util.js | 4 + src/components/util/util.test.js | 41 ++++++- src/constants.js | 14 ++- 8 files changed, 294 insertions(+), 84 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c6901568..ef7df4e15 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * Disable open loan actions for virtual patron. Refs UIU-2964. * Hide all actionalble buttons on user details pane for DCB Virtual user. Refs UIU-2987. +* Open loan page modifications for a virtual patron. Refs UIU-2988. ## [10.0.5](https://github.com/folio-org/ui-users/tree/v10.0.5) (2023-11-21) [Full Changelog](https://github.com/folio-org/ui-users/compare/v10.0.4...v10.0.5) diff --git a/src/components/Loans/OpenLoans/components/ActionsDropdown/ActionsDropdown.js b/src/components/Loans/OpenLoans/components/ActionsDropdown/ActionsDropdown.js index 7b522d457..aa4cdcf6e 100644 --- a/src/components/Loans/OpenLoans/components/ActionsDropdown/ActionsDropdown.js +++ b/src/components/Loans/OpenLoans/components/ActionsDropdown/ActionsDropdown.js @@ -18,6 +18,8 @@ import { getChargeFineToLoanPath, getOpenRequestsPath, checkUserActive, + isDcbUser, + isDCBItem, } from '../../../../util'; import { itemStatuses } from '../../../../../constants'; @@ -54,20 +56,26 @@ class ActionsDropdown extends React.Component { const loanPolicyLink = `/settings/circulation/loan-policies/${loan.loanPolicyId}`; const buttonDisabled = !stripes.hasPerm('ui-users.feesfines.actions.all'); const isUserActive = checkUserActive(user); + const isVirtualUser = isDcbUser(user); + const isVirtualItem = isDCBItem(loan?.item); return ( - + { + !isVirtualItem && ( + + ) + } - { isUserActive && itemStatusName !== itemStatuses.CLAIMED_RETURNED && + { isUserActive && !isVirtualUser && itemStatusName !== itemStatuses.CLAIMED_RETURNED && + { + !isVirtualUser && ( + + ) + } - + { + !isVirtualUser && ( + + ) + } - + { + !isVirtualUser && ( + + ) + } - {requestQueue && stripes.hasPerm('ui-requests.all') && + {requestQueue && stripes.hasPerm('ui-requests.all') && !isVirtualUser && - - - - - - - - - + !isVirtualUser && ( + + + + + + + + + + + + + ) } /> ); diff --git a/src/components/Loans/OpenLoans/components/OpenLoansSubHeader/OpenLoansSubHeader.test.js b/src/components/Loans/OpenLoans/components/OpenLoansSubHeader/OpenLoansSubHeader.test.js index 0425a4be8..de35ddc6d 100644 --- a/src/components/Loans/OpenLoans/components/OpenLoansSubHeader/OpenLoansSubHeader.test.js +++ b/src/components/Loans/OpenLoans/components/OpenLoansSubHeader/OpenLoansSubHeader.test.js @@ -7,6 +7,11 @@ import { import renderWithRouter from 'helpers/renderWithRouter'; import loans from 'fixtures/openLoans'; +import { + DCB, + DCB_VIRTUAL_USER, +} from '../../../../../constants'; + import OpenLoansSubHeader from './OpenLoansSubHeader'; jest.unmock('@folio/stripes/components'); @@ -270,4 +275,63 @@ describe('Given OpenLoansSubHeader', () => { expect(showChangeDueDateDialog).toHaveBeenCalled(); }); }); + + describe('when dcb virtual user', () => { + it('should hide "Renew" button', () => { + const alteredProps = { + ...props, + user: { + ...okapiCurrentUser, + lastName: DCB_VIRTUAL_USER.personal.lastName, + type: DCB, + } + }; + + renderOpenLoansSubHeader(alteredProps); + + expect(screen.queryByRole('button', { name: 'ui-users.renew' })).toBeNull(); + }); + it('should hide "Claim returned" button', () => { + const alteredProps = { + ...props, + user: { + ...okapiCurrentUser, + lastName: DCB_VIRTUAL_USER.personal.lastName, + type: DCB, + } + }; + + renderOpenLoansSubHeader(alteredProps); + + expect(screen.queryByRole('button', { name: 'ui-users.loans.claimReturned' })).toBeNull(); + }); + it('should hide "Change due date" button', () => { + const alteredProps = { + ...props, + user: { + ...okapiCurrentUser, + lastName: DCB_VIRTUAL_USER.personal.lastName, + type: DCB, + } + }; + + renderOpenLoansSubHeader(alteredProps); + + expect(screen.queryByRole('button', { name: 'stripes-smart-components.cddd.changeDueDate' })).toBeNull(); + }); + it('should hide "Export to CSV button', () => { + const alteredProps = { + ...props, + user: { + ...okapiCurrentUser, + lastName: DCB_VIRTUAL_USER.personal.lastName, + type: DCB, + } + }; + + renderOpenLoansSubHeader(alteredProps); + + expect(screen.queryByRole('button', { name: 'stripes-components.exportToCsv' })).toBeNull(); + }); + }); }); diff --git a/src/components/util/util.js b/src/components/util/util.js index 64bcf990c..fe98017aa 100644 --- a/src/components/util/util.js +++ b/src/components/util/util.js @@ -9,6 +9,8 @@ import { USER_TYPES, requestStatuses, sortTypes, + DCB_INSTANCE_ID, + DCB_HOLDINGS_RECORD_ID, } from '../../constants'; /** @@ -208,3 +210,5 @@ export const isStaffUser = (user) => user?.type === USER_TYPES.STAFF; export const isAffiliationsEnabled = (user) => { return !isPatronUser(user) && !isDcbUser(user); }; + +export const isDCBItem = (item) => item.instanceId === DCB_INSTANCE_ID && item.holdingsRecordId === DCB_HOLDINGS_RECORD_ID; diff --git a/src/components/util/util.test.js b/src/components/util/util.test.js index cec1dd32b..64ef8977c 100644 --- a/src/components/util/util.test.js +++ b/src/components/util/util.test.js @@ -1,6 +1,10 @@ import '__mock__'; import okapiUser from 'fixtures/okapiCurrentUser'; -import { USER_TYPES } from '../../constants'; +import { + USER_TYPES, + DCB_INSTANCE_ID, + DCB_HOLDINGS_RECORD_ID, +} from '../../constants'; import { accountsMatchStatus, checkUserActive, @@ -23,6 +27,7 @@ import { isConsortiumEnabled, getRequestUrl, isAffiliationsEnabled, + isDCBItem, } from './util'; const STRIPES = { @@ -435,3 +440,37 @@ describe('isAffiliationsEnabled', () => { expect(isAffiliationsEnabled({ type: USER_TYPES.SYSTEM })).toBeTruthy(); }); }); + +describe('isDCBItem ', () => { + it('should return true when both item instance id and item holdings record id are DCB_INSTANCE_ID and DCB_HOLDINGS_RECORD_ID respectively', () => { + const item = { + instanceId: DCB_INSTANCE_ID, + holdingsRecordId: DCB_HOLDINGS_RECORD_ID, + }; + expect(isDCBItem(item)).toBeTruthy(); + }); + + it('should return false when item instance id is DCB_INSTANCE_ID and item holdings record id is not DCB_HOLDINGS_RECORD_ID', () => { + const item = { + instanceId: DCB_INSTANCE_ID, + holdingsRecordId: 'test', + }; + expect(isDCBItem(item)).toBeFalsy(); + }); + + it('should return false when item instance id is not DCB_INSTANCE_ID and item holdings record id is DCB_HOLDINGS_RECORD_ID', () => { + const item = { + instanceId: 'test', + holdingsRecordId: DCB_HOLDINGS_RECORD_ID, + }; + expect(isDCBItem(item)).toBeFalsy(); + }); + + it('should return false when item instance id is not DCB_INSTANCE_ID and item holdings record id is not DCB_HOLDINGS_RECORD_ID', () => { + const item = { + instanceId: 'test', + holdingsRecordId: 'test', + }; + expect(isDCBItem(item)).toBeFalsy(); + }); +}); diff --git a/src/constants.js b/src/constants.js index d3571eb59..314df3230 100644 --- a/src/constants.js +++ b/src/constants.js @@ -340,11 +340,23 @@ export const RECORD_SOURCE = { CONSORTIUM: 'consortium', }; +export const DCB = 'dcb'; + export const USER_TYPE_FIELD = 'type'; export const USER_TYPES = { PATRON: 'patron', SHADOW: 'shadow', STAFF: 'staff', SYSTEM: 'system', - DCB: 'dcb', + DCB, +}; + +export const DCB_INSTANCE_ID = '9d1b77e4-f02e-4b7f-b296-3f2042ddac54'; +export const DCB_HOLDINGS_RECORD_ID = '10cd3a5a-d36f-4c7a-bc4f-e1ae3cf820c9'; + +export const DCB_VIRTUAL_USER = { + personal: { + lastName: 'DcbSystem', + }, + type: DCB, };