Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UIU-2966 - display item title and barcode as text for dcb virtual item. #2597

Merged
merged 5 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
64 changes: 50 additions & 14 deletions src/views/LoanDetails/LoanDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import {
accountsMatchStatus,
checkUserActive,
isDcbUser,
isDCBItem,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to decide between functions like isDCB... and isDcb.... I know that's not your gaffe, but it's highlighted here by adding the new import.

} from '../../components/util';
import { itemStatuses, loanActions, refundClaimReturned } from '../../constants';
import {
Expand Down Expand Up @@ -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 <KeyValue
const titleTodisplay = (title.length >= titleLengthCheck) ? `${title.substring(0, titleLengthCheck)}...` : title;
const formattedValue = `${titleTodisplay} (${get(this.loan, ['item', 'materialType', 'name'])})`;
return (
<KeyValue
data-testId="item-title"
label={<FormattedMessage id="ui-users.loans.columns.title" />}
value={
isVirtualItem ?
formattedValue :
<Link to={`/inventory/view/${instanceId}`}>
{formattedValue}
</Link>
}
/>
);
}

return (
<KeyValue
label={<FormattedMessage id="ui-users.loans.columns.title" />}
value={(
<Link to={`/inventory/view/${get(this.loan, ['item', 'instanceId'], '')}`}>
{`${titleTodisplay} (${get(this.loan, ['item', 'materialType', 'name'])})`}
</Link>
)}
/>;
value={<NoValue />}
/>
);
}

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 <KeyValue
label={<FormattedMessage id="ui-users.loans.columns.title" />}
value="-"
/>;
return (
<Link
to={`/inventory/view/${instanceId}/${holdingsRecordId}/${itemId}`}
>
{itemBarcode}
</Link>
);
}

renderChangeDueDateDialog() {
Expand Down Expand Up @@ -627,8 +662,9 @@ class LoanDetails extends React.Component {
</Col>
<Col xs={2}>
<KeyValue
data-testId="item-barcode"
label={<FormattedMessage id="ui-users.loans.columns.barcode" />}
value={<Link to={`/inventory/view/${get(loan, ['item', 'instanceId'], '')}/${get(loan, ['item', 'holdingsRecordId'], '')}/${get(loan, ['itemId'], '')}`}>{get(loan, ['item', 'barcode'], '')}</Link>}
value={this.showBarcode(loan)}
/>
</Col>
<Col xs={2}>
Expand Down
40 changes: 39 additions & 1 deletion src/views/LoanDetails/LoanDetails.test.js
Original file line number Diff line number Diff line change
@@ -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', () => ({
Expand Down Expand Up @@ -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();
});
});
});
Loading