From cc017a76c5e52f9171d421859b593255c68727bf Mon Sep 17 00:00:00 2001 From: Priyanka Terala <104053200+Terala-Priyanka@users.noreply.github.com> Date: Tue, 5 Dec 2023 15:06:23 +0530 Subject: [PATCH] UIU-2966 - display item title and barcode as text for dcb virtual item. (#2597) * UIU-2966 - initial commit to display item title and barcode as text for dcb virtual item. * UIU-2966 - render item title and barcode as normal text when item is dcb item. * UIU-2966 - fix review comments * UIU-2966 - fix linting errors --- CHANGELOG.md | 1 + src/views/LoanDetails/LoanDetails.js | 64 ++++++++++++++++++----- src/views/LoanDetails/LoanDetails.test.js | 40 +++++++++++++- 3 files changed, 90 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 63b46f3da..ac206677e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ * Fix problem with Date field in User app reports does not populate when a first entry was cleared. Refs UIU-2991. * 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. +* Display item title and barcode as text when the item is dcb virtual item. Refs UIU-2966. ## [10.0.4](https://github.com/folio-org/ui-users/tree/v10.0.4) (2023-11-10) [Full Changelog](https://github.com/folio-org/ui-users/compare/v10.0.3...v10.0.4) diff --git a/src/views/LoanDetails/LoanDetails.js b/src/views/LoanDetails/LoanDetails.js index 2cd2db94b..bf5af455c 100644 --- a/src/views/LoanDetails/LoanDetails.js +++ b/src/views/LoanDetails/LoanDetails.js @@ -43,6 +43,7 @@ import { accountsMatchStatus, checkUserActive, isDcbUser, + isDCBItem, } from '../../components/util'; import { itemStatuses, loanActions, refundClaimReturned } from '../../constants'; import { @@ -298,23 +299,57 @@ class LoanDetails extends React.Component { showTitle(loan) { this.loan = loan; - const title = `${get(this.loan, ['item', 'title'], '')}`; + const title = get(this.loan, ['item', 'title'], ''); + const instanceId = get(this.loan, ['item', 'instanceId'], ''); + const holdingsRecordId = get(this.loan, ['item', 'holdingsRecordId'], ''); + const isVirtualItem = isDCBItem({ instanceId, holdingsRecordId }); + const titleLengthCheck = 77; + if (title) { - const titleTodisplay = (title.length >= 77) ? `${title.substring(0, 77)}...` : title; - return = titleLengthCheck) ? `${title.substring(0, titleLengthCheck)}...` : title; + const formattedValue = `${titleTodisplay} (${get(this.loan, ['item', 'materialType', 'name'])})`; + return ( + } + value={ + isVirtualItem ? + formattedValue : + + {formattedValue} + + } + /> + ); + } + + return ( + } - value={( - - {`${titleTodisplay} (${get(this.loan, ['item', 'materialType', 'name'])})`} - - )} - />; + value={} + /> + ); + } + + showBarcode(loan) { + this.loan = loan; + const instanceId = get(this.loan, ['item', 'instanceId'], ''); + const holdingsRecordId = get(this.loan, ['item', 'holdingsRecordId'], ''); + const itemId = get(this.loan, ['itemId'], ''); + const itemBarcode = get(loan, ['item', 'barcode']); + const isVirtualItem = isDCBItem({ instanceId, holdingsRecordId }); + + if (isVirtualItem) { + return itemBarcode; } - return } - value="-" - />; + return ( + + {itemBarcode} + + ); } renderChangeDueDateDialog() { @@ -627,8 +662,9 @@ class LoanDetails extends React.Component { } - value={{get(loan, ['item', 'barcode'], '')}} + value={this.showBarcode(loan)} /> diff --git a/src/views/LoanDetails/LoanDetails.test.js b/src/views/LoanDetails/LoanDetails.test.js index f9da21733..8f41a6a98 100644 --- a/src/views/LoanDetails/LoanDetails.test.js +++ b/src/views/LoanDetails/LoanDetails.test.js @@ -1,11 +1,15 @@ // eslint-disable-next-line import/no-extraneous-dependencies -import { screen } from '@folio/jest-config-stripes/testing-library/react'; +import { screen, within } from '@folio/jest-config-stripes/testing-library/react'; import userEvent from '@folio/jest-config-stripes/testing-library/user-event'; // eslint-disable-next-line import/no-extraneous-dependencies import okapiOpenLoan from 'fixtures/openLoan'; import okapiCurrentUser from 'fixtures/okapiCurrentUser'; import renderWithRouter from 'helpers/renderWithRouter'; import LoanDetails from './LoanDetails'; +import { + DCB_INSTANCE_ID, + DCB_HOLDINGS_RECORD_ID, +} from '../../constants'; jest.useFakeTimers('legacy'); jest.mock('react-intl', () => ({ @@ -539,4 +543,38 @@ describe('LoanDetails', () => { expect(screen.getByRole('button', { name:'ui-users.loans.newStaffInfo' })).toBeDisabled(); }); }); + + describe('when item is dcb item', () => { + const virtualItemPropsData = { + ...propsData, + loan: { + ...okapiOpenLoan, + item: { + ...okapiOpenLoan.item, + instanceId: DCB_INSTANCE_ID, + holdingsRecordId: DCB_HOLDINGS_RECORD_ID, + title: 'Vitual item', + barcode: 'virtual barcode' + } + } + }; + + it('render item title not as a link but as text', () => { + renderLoanProxyDetails({ + ...virtualItemPropsData, + }); + + expect(screen.queryByRole('link', { name: /Virtual item/i })).toBeNull(); + expect(within(screen.getByTestId('item-title')).queryByText('Virtual Item')).toBeDefined(); + }); + + it('render item barcode as text', () => { + renderLoanProxyDetails({ + ...virtualItemPropsData, + }); + + expect(screen.queryByRole('link', { name: /Virtual barcode/i })).toBeNull(); + expect(within(screen.getByTestId('item-barcode')).queryByText('Virtual barcode')).toBeDefined(); + }); + }); });