Skip to content

Commit

Permalink
UIIN-3175: Revert changes
Browse files Browse the repository at this point in the history
  • Loading branch information
OleksandrHladchenko1 committed Feb 28, 2025
1 parent 98fd0e0 commit cbf12a8
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 124 deletions.
30 changes: 28 additions & 2 deletions src/Item/ItemVersionHistory/ItemVersionHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,33 @@ import { AuditLogPane } from '@folio/stripes-acq-components';

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

export const createFieldFormatter = (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}`,
});

const ItemVersionHistory = ({
onClose,
Expand Down Expand Up @@ -63,7 +89,7 @@ const ItemVersionHistory = ({
date: formatMessage({ id: 'ui-inventory.date' }),
};

const fieldFormatter = createVersionHistoryFieldFormatter(referenceData, circulationHistory);
const fieldFormatter = createFieldFormatter(referenceData, circulationHistory);

return (
<AuditLogPane
Expand Down
90 changes: 89 additions & 1 deletion src/Item/ItemVersionHistory/ItemVersionHistory.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from '../../../test/jest/helpers';

import { DataContext } from '../../contexts';
import ItemVersionHistory from './ItemVersionHistory';
import ItemVersionHistory, { createFieldFormatter } from './ItemVersionHistory';

jest.mock('@folio/stripes-acq-components', () => ({
...jest.requireActual('@folio/stripes-acq-components'),
Expand All @@ -30,6 +30,21 @@ const queryClient = new QueryClient();

const onCloseMock = jest.fn();
const itemId = 'itemId';
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 renderItemVersionHistory = () => {
const component = (
Expand All @@ -54,3 +69,76 @@ describe('ItemVersionHistory', () => {
expect(screen.getByText('Version history')).toBeInTheDocument();
});
});

describe('createFieldFormatter', () => {
const fieldFormatter = createFieldFormatter(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');
});
});
31 changes: 0 additions & 31 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1128,34 +1128,3 @@ export const omitCurrentAndCentralTenants = (stripes) => {
export const getIsVersionHistoryEnabled = settings => {
return settings?.find(setting => setting.key === VERSION_HISTORY_ENABLED_SETTING)?.value;
};

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: 0 additions & 90 deletions src/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
omitCurrentAndCentralTenants,
marshalInstance,
getIsVersionHistoryEnabled,
createVersionHistoryFieldFormatter,
} from './utils';
import {
CONTENT_TYPE_HEADER,
Expand Down Expand Up @@ -507,92 +506,3 @@ describe('getIsVersionHistoryEnabled', () => {
expect(getIsVersionHistoryEnabled(settings)).toBe(false);
});
});

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 cbf12a8

Please sign in to comment.