Skip to content

Commit

Permalink
UIIN-3174: Use createVersionHistoryFieldFormatter for holdings and items
Browse files Browse the repository at this point in the history
  • Loading branch information
OleksandrHladchenko1 committed Feb 28, 2025
1 parent 01b296e commit 509ca69
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 18 deletions.
20 changes: 2 additions & 18 deletions src/Holding/HoldingVersionHistory/HoldingVersionHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { AuditLogPane } from '@folio/stripes-acq-components';

import { useHoldingAuditDataQuery } from '../../hooks';
import { DataContext } from '../../contexts';
import { createVersionHistoryFieldFormatter } from '../../utils';

const HoldingVersionHistory = ({ onClose, holdingId }) => {
const { formatMessage } = useIntl();
Expand Down Expand Up @@ -46,24 +47,7 @@ const HoldingVersionHistory = ({ onClose, holdingId }) => {
entries: formatMessage({ id: 'ui-inventory.receivingHistory' }),
};

const fieldFormatter = {
discoverySuppress: value => value.toString(),
holdingsTypeId: value => referenceData.holdingsTypes?.find(type => type.id === value)?.name,
statisticalCodeIds: value => {
const statisticalCode = referenceData.statisticalCodes?.find(code => code.id === value);

return `${statisticalCode.statisticalCodeType.name}: ${statisticalCode.code} - ${statisticalCode.name}`;
},
callNumberTypeId: value => referenceData.callNumberTypes?.find(type => type.id === value)?.name,
permanentLocationId: value => referenceData.locationsById[value]?.name,
temporaryLocationId: value => referenceData.locationsById[value]?.name,
effectiveLocationId: value => referenceData.locationsById[value]?.name,
illPolicyId: value => referenceData.illPolicies.find(policy => policy.id === value)?.name,
staffOnly: value => value.toString(),
holdingsNoteTypeId: value => referenceData.holdingsNoteTypes?.find(noteType => noteType.id === value)?.name,
relationshipId: value => referenceData.electronicAccessRelationships?.find(noteType => noteType.id === value)?.name,
publicDisplay: value => value.toString(),
};
const fieldFormatter = createVersionHistoryFieldFormatter(referenceData);

return (
<AuditLogPane
Expand Down
31 changes: 31 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1123,3 +1123,34 @@ export const omitCurrentAndCentralTenants = (stripes) => {

return tenants?.filter(tenant => tenant.id !== currentTenantId && tenant.id !== centralTenantId);
};

export const createVersionHistoryFieldFormatter = (referenceData, circulationHistory = {}) => ({
discoverySuppress: value => value.toString(),
typeId: value => referenceData.callNumberTypes?.find(type => type.id === value)?.name,
itemLevelCallNumberTypeId: value => referenceData.callNumberTypes?.find(type => type.id === value)?.name,
itemDamagedStatusId: value => referenceData.itemDamagedStatuses?.find(type => type.id === value)?.name,
permanentLocationId: value => referenceData.locationsById[value]?.name,
temporaryLocationId: value => referenceData.locationsById[value]?.name,
effectiveLocationId: value => referenceData.locationsById[value]?.name,
permanentLoanTypeId: value => referenceData.loanTypes?.find(type => type.id === value)?.name,
temporaryLoanTypeId: value => referenceData.loanTypes?.find(type => type.id === value)?.name,
materialTypeId: value => referenceData.materialTypes?.find(type => type.id === value)?.name,
statisticalCodeIds: value => {
const statisticalCode = referenceData.statisticalCodes?.find(code => code.id === value);

return `${statisticalCode.statisticalCodeType.name}: ${statisticalCode.code} - ${statisticalCode.name}`;
},
relationshipId: value => referenceData.electronicAccessRelationships?.find(type => type.id === value)?.name,
staffOnly: value => value.toString(),
itemNoteTypeId: value => referenceData.itemNoteTypes?.find(type => type.id === value)?.name,
date: value => getDateWithTime(value),
servicePointId: () => circulationHistory.servicePointName,
staffMemberId: () => circulationHistory.source,
dateTime: value => getDateWithTime(value),
source: value => `${value.personal.lastName}, ${value.personal.firstName}`,
holdingsTypeId: value => referenceData.holdingsTypes?.find(type => type.id === value)?.name,
callNumberTypeId: value => referenceData.callNumberTypes?.find(type => type.id === value)?.name,
illPolicyId: value => referenceData.illPolicies.find(policy => policy.id === value)?.name,
holdingsNoteTypeId: value => referenceData.holdingsNoteTypes?.find(noteType => noteType.id === value)?.name,
publicDisplay: value => value.toString(),
});
90 changes: 90 additions & 0 deletions src/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
checkIfCentralOrderingIsActive,
omitCurrentAndCentralTenants,
marshalInstance,
createVersionHistoryFieldFormatter,
} from './utils';
import {
CONTENT_TYPE_HEADER,
Expand Down Expand Up @@ -490,3 +491,92 @@ describe('hasMemberTenantPermission', () => {
});
});
});

describe('createVersionHistoryFieldFormatter', () => {
const date = '2024-02-26T12:00:00Z';
const mockReferenceData = {
callNumberTypes: [{ id: '123', name: 'Test Call Number Type' }],
itemDamagedStatuses: [{ id: 'damaged-1', name: 'Damaged' }],
locationsById: { 'location-1': { name: 'Main Library' } },
loanTypes: [{ id: 'loan-1', name: 'Short Term' }],
materialTypes: [{ id: 'material-1', name: 'Book' }],
statisticalCodes: [{ id: 'stat-1', statisticalCodeType: { name: 'Category' }, code: '001', name: 'Stat Code' }],
electronicAccessRelationships: [{ id: 'rel-1', name: 'Online Access' }],
itemNoteTypes: [{ id: 'note-1', name: 'Public Note' }],
};
const mockCirculationHistory = {
servicePointName: 'Main Desk',
source: 'Librarian User',
};

const fieldFormatter = createVersionHistoryFieldFormatter(mockReferenceData, mockCirculationHistory);

it('should format discoverySuppress field correctly', () => {
expect(fieldFormatter.discoverySuppress(true)).toBe('true');
expect(fieldFormatter.discoverySuppress(false)).toBe('false');
});

it('should format typeId field correctly', () => {
expect(fieldFormatter.typeId('123')).toBe('Test Call Number Type');
});

it('should format typeId itemLevelCallNumberTypeId correctly', () => {
expect(fieldFormatter.itemLevelCallNumberTypeId('123')).toBe('Test Call Number Type');
});

it('should format itemDamagedStatusId field correctly', () => {
expect(fieldFormatter.itemDamagedStatusId('damaged-1')).toBe('Damaged');
});

it('should format location IDs field correctly', () => {
expect(fieldFormatter.permanentLocationId('location-1')).toBe('Main Library');
expect(fieldFormatter.effectiveLocationId('location-1')).toBe('Main Library');
expect(fieldFormatter.temporaryLocationId('location-1')).toBe('Main Library');
});

it('should format loan types field correctly', () => {
expect(fieldFormatter.permanentLoanTypeId('loan-1')).toBe('Short Term');
expect(fieldFormatter.temporaryLoanTypeId('loan-1')).toBe('Short Term');
});

it('should format material types field correctly', () => {
expect(fieldFormatter.materialTypeId('material-1')).toBe('Book');
});

it('should format statistical codes field correctly', () => {
expect(fieldFormatter.statisticalCodeIds('stat-1')).toBe('Category: 001 - Stat Code');
});

it('should format electronic access relationships field correctly', () => {
expect(fieldFormatter.relationshipId('rel-1')).toBe('Online Access');
});

it('should format item note types field correctly', () => {
expect(fieldFormatter.itemNoteTypeId('note-1')).toBe('Public Note');
});

it('should format staffOnly field correctly', () => {
expect(fieldFormatter.staffOnly(true)).toBe('true');
expect(fieldFormatter.staffOnly(false)).toBe('false');
});

it('should format date field correctly', () => {
expect(fieldFormatter.date(date)).toBe(`Formatted Date: ${date}`);
});

it('should format dateTime field correctly', () => {
expect(fieldFormatter.dateTime(date)).toBe(`Formatted Date: ${date}`);
});

it('should format servicePointId field correctly', () => {
expect(fieldFormatter.servicePointId()).toBe('Main Desk');
});

it('should format staffMemberId field correctly', () => {
expect(fieldFormatter.staffMemberId()).toBe('Librarian User');
});

it('should format source field correctly', () => {
expect(fieldFormatter.source({ personal: { firstName: 'John', lastName: 'Doe' } })).toBe('Doe, John');
});
});

0 comments on commit 509ca69

Please sign in to comment.