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

UIQM-573: Edit MARC authority | Allow user to Add/Edit 010 $a when linking is based on 001. #617

Merged
merged 1 commit into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 1 addition & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
## [8.0.0] (IN PROGRESS)

* [UIQM-580](https://issues.folio.org/browse/UIQM-580) *BREAKING* Move QuickMarcView, PrintPopup and getHeaders to stripes-marc-components.

## [7.1.0] (IN PROGRESS)

* [UIQM-543](https://issues.folio.org/browse/UIQM-543) Remove eslint deps that are already listed in eslint-config-stripes.
* [UIQM-573](https://issues.folio.org/browse/UIQM-573) Edit MARC authority | Allow user to Add/Edit 010 $a when linking is based on 001.

## [7.0.2](https://github.com/folio-org/ui-quick-marc/tree/v7.0.2) (2023-10-27)

Expand Down
24 changes: 2 additions & 22 deletions src/QuickMarcEditor/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,6 @@ export const getContentSubfieldValue = (content = '') => {
}, {});
};

const is001LinkedToBibRecord = (initialRecords, naturalId) => {
const field001 = initialRecords.find(record => record.tag === '001');

return naturalId === field001?.content.replaceAll(' ', '');
};

export const is010LinkedToBibRecord = (initialRecords, naturalId) => {
const initial010Field = initialRecords.find(record => record.tag === '010');

Expand All @@ -108,13 +102,6 @@ export const is010LinkedToBibRecord = (initialRecords, naturalId) => {
return naturalId === initial010$a?.replaceAll(' ', '');
};

export const is010$aCreated = (initial, updated) => {
const initial010 = initial.find(rec => rec.tag === '010');
const updated010 = updated.find(rec => rec.tag === '010');

return !initial010 && updated010 && !!getContentSubfieldValue(updated010.content).$a?.[0];
};

export const is010$aUpdated = (initial, updated) => {
const initial010 = initial.find(rec => rec.tag === '010');
const updated010 = updated.find(rec => rec.tag === '010');
Expand Down Expand Up @@ -857,7 +844,7 @@ const validateMarcAuthority1xxField = (initialRecords, formValuesToSave) => {
return undefined;
};

const validateLinkedAuthority010Field = (field010, initialRecords, records, naturalId) => {
const validateLinkedAuthority010Field = (field010, initialRecords, naturalId) => {
if (is010LinkedToBibRecord(initialRecords, naturalId)) {
if (!field010) {
return <FormattedMessage id="ui-quick-marc.record.error.010.removed" />;
Expand All @@ -872,13 +859,6 @@ const validateLinkedAuthority010Field = (field010, initialRecords, records, natu
return undefined;
}

if (
is001LinkedToBibRecord(initialRecords, naturalId)
&& (is010$aCreated(initialRecords, records) || is010$aUpdated(initialRecords, records))
) {
return <FormattedMessage id="ui-quick-marc.record.error.010.edit$a" />;
}

return undefined;
};

Expand All @@ -900,7 +880,7 @@ const validateAuthority010Field = (initialRecords, records, naturalId, marcRecor
}

if (isLinked) {
return validateLinkedAuthority010Field(field010, initialRecords, records, naturalId);
return validateLinkedAuthority010Field(field010, initialRecords, naturalId);
}

return undefined;
Expand Down
57 changes: 0 additions & 57 deletions src/QuickMarcEditor/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1209,63 +1209,6 @@ describe('QuickMarcEditor utils', () => {
}).props.id).toBe('ui-quick-marc.record.error.1xx.remove$t');
});

it('should return an error if 010 $a edited and 001 is linked', () => {
const newInitialValues = {
...initialValues,
records: [
...initialValues.records,
{
content: 'n 83073672 ',
tag: '001',
},
{
tag: '010',
content: '$a 63943573',
},
],
};

const record = cloneDeep(newInitialValues);

record.records[4].content += 'test';

expect(utils.validateMarcRecord({
marcRecord: record,
initialValues: newInitialValues,
marcType: MARC_TYPES.AUTHORITY,
linksCount,
naturalId: 'n83073672',
}).props.id).toBe('ui-quick-marc.record.error.010.edit$a');
});

it('should return an error if 010 $a created and 001 is linked', () => {
const newInitialValues = {
...initialValues,
records: [
...initialValues.records,
{
content: 'n 83073672 ',
tag: '001',
},
],
};

const record = cloneDeep(newInitialValues);

record.records.push({
tag: '010',
content: '$a 63943573',
});

expect(utils.validateMarcRecord({
marcRecord: record,
initialValues: newInitialValues,
marcType: MARC_TYPES.AUTHORITY,
linksCount,
naturalId: 'n83073672',
}).props.id).toBe('ui-quick-marc.record.error.010.edit$a');
});

it('should return an error if 010 $a removed and 010 is linked', () => {
const newInitialValues = {
...initialValues,
Expand Down
Loading