diff --git a/CHANGELOG.md b/CHANGELOG.md index c050b4a7a..c3a2ccd02 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ * Ignored hot key command on edit fields. Refs UIIN-2604. * Don't render Fast Add record modal in a `` to re-calculate other ``'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) diff --git a/src/components/BrowseResultsList/getBrowseResultsFormatter.js b/src/components/BrowseResultsList/getBrowseResultsFormatter.js index 723a3975d..1c8bc9b65 100644 --- a/src/components/BrowseResultsList/getBrowseResultsFormatter.js +++ b/src/components/BrowseResultsList/getBrowseResultsFormatter.js @@ -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 ; + } - return subject; + const subject = getTargetRecord(r?.value, r, browseOption, filters); + if (browseOption === browseModeOptions.SUBJECTS && r.authorityId) { + return renderMarcAuthoritiesLink(r.authorityId, subject); } - return ; + + return subject; }, callNumber: r => { if (r?.instance || r?.totalRecords) { @@ -121,16 +122,17 @@ const getBrowseResultsFormatter = ({ return ; }, contributor: r => { - if (r?.totalRecords) { - const fullMatchRecord = getTargetRecord(r.name, r, browseOption, filters); + if (!r?.totalRecords && r?.isAnchor) { + return ; + } - 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 ; + + return fullMatchRecord; }, contributorType: r => data.contributorNameTypes.find(nameType => nameType.id === r.contributorNameTypeId)?.name || '', relatorTerm: r => { @@ -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), }; }; diff --git a/src/components/BrowseResultsList/getBrowseResultsFormatter.test.js b/src/components/BrowseResultsList/getBrowseResultsFormatter.test.js index e8eafc387..3cc172be3 100644 --- a/src/components/BrowseResultsList/getBrowseResultsFormatter.test.js +++ b/src/components/BrowseResultsList/getBrowseResultsFormatter.test.js @@ -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, @@ -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', () => { @@ -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(); diff --git a/src/components/BrowseResultsList/utils.js b/src/components/BrowseResultsList/utils.js index 6a38054ee..2ed52afb6 100644 --- a/src/components/BrowseResultsList/utils.js +++ b/src/components/BrowseResultsList/utils.js @@ -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)