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

*DO NOT MERGE* UIIN-3162 *BREAKING* Use browse 1.5 interface that provides new Call Number Browse endpoints. #2698

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 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 @@ -19,6 +19,7 @@

* Display holdings names in `Consortial holdings` accordion for user without inventory permissions in member tenants. Fixes UIIN-3159.
* Remove the ability to share local instance when `Inventory: View, create instances` permission is assigned. Fixes UIIN-3166.
* *BREAKING* Use `browse` `1.5` interface that provides new Call Number Browse endpoints. Refs UIIN-3162.

## [12.0.7](https://github.com/folio-org/ui-inventory/tree/v12.0.7) (2024-12-17)
[Full Changelog](https://github.com/folio-org/ui-inventory/compare/v12.0.6...v12.0.7)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"okapiInterfaces": {
"alternative-title-types": "1.0",
"call-number-types": "1.0",
"browse": "0.6 1.0",
"browse": "1.5",
"circulation": "9.0 10.0 11.0 12.0 13.0 14.0",
"classification-types": "1.1",
"configuration": "2.0",
Expand Down
8 changes: 2 additions & 6 deletions src/components/BrowseResultsList/BrowseResultsList.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,9 @@ import {
MCLPagingTypes,
MultiColumnList,
} from '@folio/stripes/components';
import {
useItemToView,
} from '@folio/stripes-acq-components';
import { useItemToView } from '@folio/stripes-acq-components';

import {
BROWSE_RESULTS_COUNT,
} from '../../constants';
import { BROWSE_RESULTS_COUNT } from '../../constants';
import { DataContext } from '../../contexts';
import {
COLUMNS_MAPPING,
Expand Down
15 changes: 6 additions & 9 deletions src/components/BrowseResultsList/BrowseResultsList.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
import { createMemoryHistory } from 'history';
import { Router } from 'react-router-dom';

import { instance } from '../../../test/fixtures/instance';
import {
renderWithIntl,
translationsProperties,
Expand All @@ -37,21 +36,19 @@ const defaultProps = {
browseData: [
{
fullCallNumber: 'Aaa',
shelfKey: 'Aa 1',
callNumber: 'Aaa',
isAnchor: true,
totalRecords: 0,
},
{
fullCallNumber: 'A 1958 A 8050',
shelfKey: '41958 A 48050',
callNumber: 'A 1958 A 8050',
totalRecords: 1,
instance,
},
{
fullCallNumber: 'ABBA',
shelfKey: '41918 A 64243',
callNumber: 'ABBA',
totalRecords: 2,
instance,
},
],
isEmptyMessage: 'Empty Message',
Expand Down Expand Up @@ -133,13 +130,13 @@ describe('BrowseResultsList', () => {
it('should render browse data', () => {
renderBrowseResultsList();

expect(screen.getByText(defaultProps.browseData[1].fullCallNumber)).toBeInTheDocument();
expect(screen.getByText(defaultProps.browseData[1].callNumber)).toBeInTheDocument();
});

it('should navigate to instance Search page and show related instances', async () => {
renderBrowseResultsList();

await act(async () => fireEvent.click(screen.getByText(defaultProps.browseData[2].fullCallNumber)));
await act(async () => fireEvent.click(screen.getByText(defaultProps.browseData[2].callNumber)));

const { pathname, search } = history.location;

Expand Down Expand Up @@ -180,7 +177,7 @@ describe('BrowseResultsList', () => {
},
});

fireEvent.click(screen.getByText(defaultProps.browseData[2].fullCallNumber));
fireEvent.click(screen.getByText(defaultProps.browseData[2].callNumber));

expect(history.location.search).toContain('?filters=shared.true%2Cshared.false%2CtenantId.college');
});
Expand Down
8 changes: 5 additions & 3 deletions src/components/BrowseResultsList/getBrowseResultsFormatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
INVENTORY_ROUTE,
} from '../../constants';
import {
getFullCallNumber,
getSearchParams,
isRowPreventsClick,
} from './utils';
Expand Down Expand Up @@ -112,7 +113,6 @@ const getBrowseResultsFormatter = ({
const commonTargetRecordArgs = [browseOption, filters, namespace, data];

return {
title: r => getFullMatchRecord(r.instance?.title, r.isAnchor),
subject: r => {
if (!r?.totalRecords && r?.isAnchor) {
return <MissedMatchItem query={r?.value} />;
Expand All @@ -138,8 +138,10 @@ const getBrowseResultsFormatter = ({
return typeName || <NoValue />;
},
callNumber: r => {
if (r?.instance || r?.totalRecords) {
return getTargetRecord(r?.fullCallNumber, r, ...commonTargetRecordArgs);
const fullCallNumber = getFullCallNumber(r);

if (r?.totalRecords) {
return getTargetRecord(fullCallNumber, r, ...commonTargetRecordArgs);
Comment on lines +141 to +144
Copy link
Contributor

Choose a reason for hiding this comment

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

Should <MissedMatchItem query={r.fullCallNumber} /> also be changed?

}
return <MissedMatchItem query={r.fullCallNumber} />;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,21 @@ describe('getBrowseResultsFormatter', () => {
const missedMatchRecord = {
isAnchor: true,
fullCallNumber: 'bla bla',
callNumber: 'bla bla',
totalRecords: 0,
};
const contentData = [
{
fullCallNumber: 'A 1958 A 8050',
callNumber: 'A 1958 A 8050',
shelfKey: '41958 A 48050',
isAnchor: true,
totalRecords: 1,
instance: { id: 'ce9dd893-c812-49d5-8973-d55d018894c4', title: 'Test title' },
},
{
fullCallNumber: 'AAA',
callNumber: 'AAA',
shelfKey: '123456',
totalRecords: 2,
instance: { id: 'ce9dd893-c812-49d5-8973-d55d018894c4', title: 'Test title 2' },
Expand All @@ -117,19 +120,17 @@ describe('getBrowseResultsFormatter', () => {
renderCallNumberList();

// Anchor row
expect(screen.getByText(anchorRecord.fullCallNumber).tagName.toLowerCase()).toBe('strong');
expect(screen.getByText(anchorRecord.callNumber).tagName.toLowerCase()).toBe('strong');
expect(screen.getByText(anchorRecord.totalRecords).tagName.toLowerCase()).toBe('strong');
expect(screen.getByText(anchorRecord.instance.title).tagName.toLowerCase()).toBe('strong');
// Default row
expect(screen.getByText(nonAnchorRecord.fullCallNumber).tagName.toLowerCase()).not.toBe('strong');
expect(screen.getByText(nonAnchorRecord.callNumber).tagName.toLowerCase()).not.toBe('strong');
expect(screen.getByText(nonAnchorRecord.totalRecords).tagName.toLowerCase()).not.toBe('strong');
expect(screen.getByText(nonAnchorRecord.instance.title).tagName.toLowerCase()).not.toBe('strong');
});

it('should render \'Missed match item\' row', () => {
renderCallNumberList({ contentData: [missedMatchRecord] });

expect(screen.getByText(missedMatchRecord.fullCallNumber)).toBeInTheDocument();
expect(screen.getByText(missedMatchRecord.callNumber)).toBeInTheDocument();
expect(screen.getByText(missedMatchText)).toBeInTheDocument();
});

Expand All @@ -138,7 +139,7 @@ describe('getBrowseResultsFormatter', () => {

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

await act(async () => fireEvent.click(screen.getByText(anchorRecord.fullCallNumber)));
await act(async () => fireEvent.click(screen.getByText(anchorRecord.callNumber)));

expect(history.location.pathname).toEqual(INVENTORY_ROUTE);
});
Expand Down
45 changes: 30 additions & 15 deletions src/components/BrowseResultsList/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
browseClassificationIndexToId,
FACETS,
queryIndexes,
segments,
} from '@folio/stripes-inventory-components';

export const isRowPreventsClick = (row, browseOption) => {
Expand All @@ -21,7 +22,6 @@ export const isRowPreventsClick = (row, browseOption) => {
const isItemHasNoRecords = row.totalRecords === 0;

return isItemHasNoRecords || (
(browseOption === browseModeOptions.CALL_NUMBERS && !row.shelfKey) ||
(browseOption === browseModeOptions.CONTRIBUTORS && !row.contributorNameTypeId) ||
(browseOption === browseModeOptions.SUBJECTS && !row.totalRecords)
);
Expand Down Expand Up @@ -97,6 +97,12 @@ const getClassificationQuery = (qindex, data, row) => {
return query;
};

export const getFullCallNumber = (row) => {
const fullCallNumber = [row.callNumberPrefix, row.callNumber, row.callNumberSuffix].filter(Boolean).join(' ');

return fullCallNumber;
};

export const getSearchParams = (row, qindex, allFilters, data) => {
const filters = getExtraFilters(row, qindex, allFilters);
const classificationQuery = getClassificationQuery(qindex, data, row);
Expand All @@ -107,40 +113,49 @@ export const getSearchParams = (row, qindex, allFilters, data) => {
...filters,
};

const fullCallNumber = getFullCallNumber(row);

const optionsMap = {
[browseModeOptions.CALL_NUMBERS]: {
qindex: queryIndexes.CALL_NUMBER,
query: row.shelfKey,
qindex: queryIndexes.ITEM_NORMALIZED_CALL_NUMBERS,
query: fullCallNumber,
segment: segments.items,
Copy link
Contributor

Choose a reason for hiding this comment

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

This is repeating, let's move it to a variable, like classificationOption.

...filters,
},
[browseModeOptions.DEWEY]: {
qindex: queryIndexes.CALL_NUMBER,
query: row.shelfKey,
qindex: queryIndexes.ITEM_NORMALIZED_CALL_NUMBERS,
query: fullCallNumber,
segment: segments.items,
...filters,
},
[browseModeOptions.LIBRARY_OF_CONGRESS]: {
qindex: queryIndexes.CALL_NUMBER,
query: row.shelfKey,
qindex: queryIndexes.ITEM_NORMALIZED_CALL_NUMBERS,
query: fullCallNumber,
segment: segments.items,
...filters,
},
[browseModeOptions.LOCAL]: {
qindex: queryIndexes.CALL_NUMBER,
query: row.shelfKey,
qindex: queryIndexes.ITEM_NORMALIZED_CALL_NUMBERS,
query: fullCallNumber,
segment: segments.items,
...filters,
},
[browseModeOptions.NATIONAL_LIBRARY_OF_MEDICINE]: {
qindex: queryIndexes.CALL_NUMBER,
query: row.shelfKey,
qindex: queryIndexes.ITEM_NORMALIZED_CALL_NUMBERS,
query: fullCallNumber,
segment: segments.items,
...filters,
},
[browseModeOptions.OTHER]: {
qindex: queryIndexes.CALL_NUMBER,
query: row.shelfKey,
qindex: queryIndexes.ITEM_NORMALIZED_CALL_NUMBERS,
query: fullCallNumber,
segment: segments.items,
...filters,
},
[browseModeOptions.SUPERINTENDENT]: {
qindex: queryIndexes.CALL_NUMBER,
query: row.shelfKey,
qindex: queryIndexes.ITEM_NORMALIZED_CALL_NUMBERS,
query: fullCallNumber,
segment: segments.items,
...filters,
},
[browseModeOptions.CLASSIFICATION_ALL]: classificationOption,
Expand Down
2 changes: 2 additions & 0 deletions src/filterConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export const browseInstanceIndexes = [
{ label: 'ui-inventory.browse.dewey', value: browseModeOptions.DEWEY },
{ label: 'ui-inventory.browse.libOfCongress', value: browseModeOptions.LIBRARY_OF_CONGRESS },
{ label: 'ui-inventory.browse.natLibOfMed', value: browseModeOptions.NATIONAL_LIBRARY_OF_MEDICINE },
{ label: 'ui-inventory.browse.superintendent', value: browseModeOptions.SUPERINTENDENT },
{ label: 'ui-inventory.browse.other', value: browseModeOptions.OTHER },
],
},
{
Expand Down
44 changes: 22 additions & 22 deletions src/hooks/useInventoryBrowse/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,49 @@ import { browseModeOptions } from '@folio/stripes-inventory-components';
// [pageNumber, direction, anchor] - E.g. [1, 'prev', 'Fizz Buzz'];
export const INIT_PAGE_CONFIG = [0, null, null];

export const regExp = /^((callNumber|subject|name|itemEffectiveShelvingOrder) [<|>])/i;
export const regExp = /^((callNumber|subject|name|fullCallNumber) [<|>])/i;
export const PRECEDING_RECORDS_COUNT = 5;
export const FIVE_MINUTES = 5 * 60 * 1000;

export const PATH_MAP = {
[browseModeOptions.SUBJECTS]: 'browse/subjects/instances',
[browseModeOptions.CALL_NUMBERS]: 'browse/call-numbers/instances',
[browseModeOptions.DEWEY]: 'browse/call-numbers/instances',
[browseModeOptions.LIBRARY_OF_CONGRESS]: 'browse/call-numbers/instances',
[browseModeOptions.LOCAL]: 'browse/call-numbers/instances',
[browseModeOptions.NATIONAL_LIBRARY_OF_MEDICINE]: 'browse/call-numbers/instances',
[browseModeOptions.OTHER]: 'browse/call-numbers/instances',
[browseModeOptions.CALL_NUMBERS]: 'browse/call-numbers/all/instances',
[browseModeOptions.DEWEY]: 'browse/call-numbers/dewey/instances',
[browseModeOptions.LIBRARY_OF_CONGRESS]: 'browse/call-numbers/lc/instances',
[browseModeOptions.LOCAL]: 'browse/call-numbers/instances', // not supported, option disabled
[browseModeOptions.NATIONAL_LIBRARY_OF_MEDICINE]: 'browse/call-numbers/nlm/instances',
[browseModeOptions.OTHER]: 'browse/call-numbers/other/instances',
[browseModeOptions.SUPERINTENDENT]: 'browse/call-numbers/sudoc/instances',
[browseModeOptions.CLASSIFICATION_ALL]: 'browse/classification-numbers/all/instances',
[browseModeOptions.DEWEY_CLASSIFICATION]: 'browse/classification-numbers/dewey/instances',
[browseModeOptions.LC_CLASSIFICATION]: 'browse/classification-numbers/lc/instances',
[browseModeOptions.SUPERINTENDENT]: 'browse/call-numbers/instances',
[browseModeOptions.CONTRIBUTORS]: 'browse/contributors/instances',
};

export const INITIAL_SEARCH_PARAMS_MAP = {
[browseModeOptions.SUBJECTS]: 'value',
[browseModeOptions.CALL_NUMBERS]: 'callNumber',
[browseModeOptions.DEWEY]: 'typedCallNumber',
[browseModeOptions.LIBRARY_OF_CONGRESS]: 'typedCallNumber',
[browseModeOptions.LOCAL]: 'typedCallNumber',
[browseModeOptions.NATIONAL_LIBRARY_OF_MEDICINE]: 'typedCallNumber',
[browseModeOptions.OTHER]: 'typedCallNumber',
[browseModeOptions.CALL_NUMBERS]: 'fullCallNumber',
[browseModeOptions.DEWEY]: 'fullCallNumber',
[browseModeOptions.LIBRARY_OF_CONGRESS]: 'fullCallNumber',
[browseModeOptions.LOCAL]: 'fullCallNumber',
[browseModeOptions.NATIONAL_LIBRARY_OF_MEDICINE]: 'fullCallNumber',
[browseModeOptions.OTHER]: 'fullCallNumber',
[browseModeOptions.CLASSIFICATION_ALL]: 'number',
[browseModeOptions.DEWEY_CLASSIFICATION]: 'number',
[browseModeOptions.LC_CLASSIFICATION]: 'number',
[browseModeOptions.SUPERINTENDENT]: 'typedCallNumber',
[browseModeOptions.SUPERINTENDENT]: 'fullCallNumber',
[browseModeOptions.CONTRIBUTORS]: 'name',
};

export const PAGINATION_SEARCH_PARAMS_MAP = {
[browseModeOptions.SUBJECTS]: INITIAL_SEARCH_PARAMS_MAP[browseModeOptions.SUBJECTS],
[browseModeOptions.CALL_NUMBERS]: 'itemEffectiveShelvingOrder',
[browseModeOptions.DEWEY]: 'itemEffectiveShelvingOrder',
[browseModeOptions.LIBRARY_OF_CONGRESS]: 'itemEffectiveShelvingOrder',
[browseModeOptions.LOCAL]: 'itemEffectiveShelvingOrder',
[browseModeOptions.NATIONAL_LIBRARY_OF_MEDICINE]: 'itemEffectiveShelvingOrder',
[browseModeOptions.OTHER]: 'itemEffectiveShelvingOrder',
[browseModeOptions.SUPERINTENDENT]: 'itemEffectiveShelvingOrder',
[browseModeOptions.CALL_NUMBERS]: 'fullCallNumber',
[browseModeOptions.DEWEY]: 'fullCallNumber',
[browseModeOptions.LIBRARY_OF_CONGRESS]: 'fullCallNumber',
[browseModeOptions.LOCAL]: 'fullCallNumber',
[browseModeOptions.NATIONAL_LIBRARY_OF_MEDICINE]: 'fullCallNumber',
[browseModeOptions.OTHER]: 'fullCallNumber',
[browseModeOptions.SUPERINTENDENT]: 'fullCallNumber',
[browseModeOptions.CLASSIFICATION_ALL]: INITIAL_SEARCH_PARAMS_MAP[browseModeOptions.CLASSIFICATION_ALL],
[browseModeOptions.DEWEY_CLASSIFICATION]: INITIAL_SEARCH_PARAMS_MAP[browseModeOptions.DEWEY_CLASSIFICATION],
[browseModeOptions.LC_CLASSIFICATION]: INITIAL_SEARCH_PARAMS_MAP[browseModeOptions.LC_CLASSIFICATION],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const useSearchForShadowInstanceTenants = ({ instanceId } = {}) => {

const { isLoading, data = {} } = useQuery({
queryKey: [namespace, consortium, instanceId],
queryFn: () => ky.get('search/instances/facets',
queryFn: () => ky.get('search/call-numbers/facets',
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this necessary for useSearchForShadowInstanceTenants?

{
searchParams: {
facet: 'holdings.tenantId',
Expand Down
Loading