Skip to content

Commit

Permalink
Merge branch 'master' into UIIN-2697
Browse files Browse the repository at this point in the history
  • Loading branch information
OleksandrHladchenko1 authored Nov 28, 2023
2 parents 29e929d + b6a3b3b commit 081b2c0
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* Ignored hot key command on edit fields. Refs UIIN-2604.
* Don't render Fast Add record modal in a `<Paneset>` to re-calculate other `<Pane>`'s widths after closing. Fixes UIIN-2690.
* "Saving instance failed" modal does not show error message. Fixes UIIN-2686.
* Make browse result items that are not anchors and have no records not clickable, and show 0 in number of titles. Fixes UIIN-2699.
* Inactive permanent location for Holdings/items when user open details. Fixes UIIN-2697.

## [10.0.6](https://github.com/folio-org/ui-inventory/tree/v10.0.6) (2023-11-24)
Expand Down
32 changes: 17 additions & 15 deletions src/components/BrowseResultsList/getBrowseResultsFormatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,16 @@ const getBrowseResultsFormatter = ({
return {
title: r => getFullMatchRecord(r.instance?.title, r.isAnchor),
subject: r => {
if (r?.totalRecords) {
const subject = getTargetRecord(r?.value, r, browseOption, filters);
if (browseOption === browseModeOptions.SUBJECTS && r.authorityId) {
return renderMarcAuthoritiesLink(r.authorityId, subject);
}
if (!r?.totalRecords && r?.isAnchor) {
return <MissedMatchItem query={r?.value} />;
}

return subject;
const subject = getTargetRecord(r?.value, r, browseOption, filters);
if (browseOption === browseModeOptions.SUBJECTS && r.authorityId) {
return renderMarcAuthoritiesLink(r.authorityId, subject);
}
return <MissedMatchItem query={r?.value} />;

return subject;
},
callNumber: r => {
if (r?.instance || r?.totalRecords) {
Expand All @@ -121,16 +122,17 @@ const getBrowseResultsFormatter = ({
return <MissedMatchItem query={r.fullCallNumber} />;
},
contributor: r => {
if (r?.totalRecords) {
const fullMatchRecord = getTargetRecord(r.name, r, browseOption, filters);
if (!r?.totalRecords && r?.isAnchor) {
return <MissedMatchItem query={r.name} />;
}

if (browseOption === browseModeOptions.CONTRIBUTORS && r.authorityId) {
return renderMarcAuthoritiesLink(r.authorityId, fullMatchRecord);
}
const fullMatchRecord = getTargetRecord(r.name, r, browseOption, filters);

return fullMatchRecord;
if (browseOption === browseModeOptions.CONTRIBUTORS && r.authorityId) {
return renderMarcAuthoritiesLink(r.authorityId, fullMatchRecord);
}
return <MissedMatchItem query={r.name} />;

return fullMatchRecord;
},
contributorType: r => data.contributorNameTypes.find(nameType => nameType.id === r.contributorNameTypeId)?.name || '',
relatorTerm: r => {
Expand All @@ -142,7 +144,7 @@ const getBrowseResultsFormatter = ({
return [...acc, data.contributorTypes.find(type => type.id === contributorTypeId)?.name || ''];
}, []).filter(name => !!name).join(', ');
},
numberOfTitles: r => ((r?.instance || r?.totalRecords) || (r?.value && r?.totalRecords > 0)) && getFullMatchRecord(r?.totalRecords, r.isAnchor),
numberOfTitles: r => ((r?.instance || r?.totalRecords) || (r?.value && !r?.isAnchor) || (r?.name && !r?.isAnchor)) && getFullMatchRecord(r?.totalRecords, r.isAnchor),
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,16 @@ describe('getBrowseResultsFormatter', () => {
contributorTypeId: ['contributorTypeId'],
contributorNameTypeId: 'contributorNameTypeId',
totalRecords: 1,
},
{
name: 'Antoniou, Grigoris 2',
contributorTypeId: ['contributorTypeId'],
contributorNameTypeId: 'contributorNameTypeId',
totalRecords: 0,
isAnchor: false,
}
];
const [anchorRecord, nonAnchorRecord] = contentData;
const [anchorRecord, nonAnchorRecord, notClickableRecord] = contentData;

const renderContributorsList = (params = {}) => renderComponent({
contentData,
Expand All @@ -171,6 +178,9 @@ describe('getBrowseResultsFormatter', () => {
// Default row
expect(screen.getByText(nonAnchorRecord.name).tagName.toLowerCase()).not.toBe('strong');
expect(screen.getByText(nonAnchorRecord.totalRecords).tagName.toLowerCase()).not.toBe('strong');
// Non clickable row
expect(screen.getByText(notClickableRecord.name).tagName.toLowerCase()).not.toBe('strong');
expect(screen.getByText(notClickableRecord.totalRecords).tagName.toLowerCase()).not.toBe('strong');
});

it('should render \'Missed match item\' rows', () => {
Expand All @@ -190,6 +200,16 @@ describe('getBrowseResultsFormatter', () => {
expect(history.location.pathname).toEqual(INVENTORY_ROUTE);
});

it('should not navigate to instance "Search" page when not clickable target column was clicked', async () => {
renderContributorsList();

expect(history.location.pathname).toEqual(BROWSE_INVENTORY_ROUTE);

await act(async () => fireEvent.click(screen.getByText(notClickableRecord.name)));

expect(history.location.pathname).toEqual(BROWSE_INVENTORY_ROUTE);
});

it('should open the record in MARC authority app in new tab when "authority" icon was clicked', async () => {
renderContributorsList();

Expand Down
12 changes: 10 additions & 2 deletions src/components/BrowseResultsList/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,17 @@ import {
} from '../../constants';

export const isRowPreventsClick = (row, browseOption) => {
const isMissedMatchItemRow = !!row.isAnchor && row.totalRecords === 0;
/**
* there is a special case when contributors and subject search can return shared records even with "Shared - No" in facets
* in this case there will be a non-anchor item with 0 total results. we need to show it as item with 0 results
* and make it not clickable
*
* items with isAnchor=false and totalRecords=0 should not appear in any other case,
* so we can safely just check for totalRecords here
*/
const isItemHasNoRecords = row.totalRecords === 0;

return isMissedMatchItemRow || (
return isItemHasNoRecords || (
(browseOption === browseModeOptions.CALL_NUMBERS && !row.shelfKey) ||
(browseOption === browseModeOptions.CONTRIBUTORS && !row.contributorNameTypeId) ||
(browseOption === browseModeOptions.SUBJECTS && !row.totalRecords)
Expand Down

0 comments on commit 081b2c0

Please sign in to comment.