diff --git a/src/common/entities/MarcFieldContent/MarcFieldContent.js b/src/common/entities/MarcFieldContent/MarcFieldContent.js index 9f3d5304..fc13ac8b 100644 --- a/src/common/entities/MarcFieldContent/MarcFieldContent.js +++ b/src/common/entities/MarcFieldContent/MarcFieldContent.js @@ -57,7 +57,7 @@ export class MarcFieldContent { return this.subfieldsArr.forEach(callback); } - join() { + toContentString() { return this.subfieldsArr.reduce((acc, cur) => { return `${acc} ${cur.code} ${cur.value}`; }, '').trim(); diff --git a/src/common/entities/MarcFieldContent/MarcFieldContent.test.js b/src/common/entities/MarcFieldContent/MarcFieldContent.test.js index 581ee886..6d407005 100644 --- a/src/common/entities/MarcFieldContent/MarcFieldContent.test.js +++ b/src/common/entities/MarcFieldContent/MarcFieldContent.test.js @@ -51,9 +51,9 @@ describe('MarcFieldContent', () => { }); }); - describe('when calling `join`', () => { + describe('when calling `toContentString`', () => { it('should transform subfields array back to a string', () => { - expect(marcFieldContent.join()).toEqual(content); + expect(marcFieldContent.toContentString()).toEqual(content); }); }); @@ -61,7 +61,7 @@ describe('MarcFieldContent', () => { it('should add a new subfield to the end', () => { marcFieldContent.append('$a', 'a3'); - expect(marcFieldContent.join()).toEqual(`${content} $a a3`); + expect(marcFieldContent.toContentString()).toEqual(`${content} $a a3`); }); }); @@ -69,7 +69,7 @@ describe('MarcFieldContent', () => { it('should add a new subfield to the beginning', () => { marcFieldContent.prepend('$a', 'a3'); - expect(marcFieldContent.join()).toEqual(`$a a3 ${content}`); + expect(marcFieldContent.toContentString()).toEqual(`$a a3 ${content}`); }); }); @@ -77,7 +77,7 @@ describe('MarcFieldContent', () => { it('should remove all subfields by code', () => { marcFieldContent.removeByCode('$a'); - expect(marcFieldContent.join()).toEqual('$b b1 $b b2'); + expect(marcFieldContent.toContentString()).toEqual('$b b1 $b b2'); }); }); diff --git a/src/hooks/useAuthorityLinking/useAuthorityLinking.js b/src/hooks/useAuthorityLinking/useAuthorityLinking.js index 6b8fd3e8..930d1b87 100644 --- a/src/hooks/useAuthorityLinking/useAuthorityLinking.js +++ b/src/hooks/useAuthorityLinking/useAuthorityLinking.js @@ -31,12 +31,6 @@ import { QUICK_MARC_ACTIONS, } from '../../QuickMarcEditor/constants'; -const joinSubfields = (subfields) => Object.keys(subfields).reduce((content, key) => { - const subfield = subfields[key].join(` ${key} `); - - return [content, `${key} ${subfield}`].join(' '); -}, '').trim(); - const formatSubfieldCode = (code) => { return code.startsWith('$') ? code : `$${code}`; }; const useAuthorityLinking = ({ tenantId, marcType, action } = {}) => { @@ -192,7 +186,7 @@ const useAuthorityLinking = ({ tenantId, marcType, action } = {}) => { updatedBibSubfields.removeByCode('$9'); updatedBibSubfields.append('$9', authorityRecord.id); bibField.prevContent = bibField.content; - bibField.content = updatedBibSubfields.join(); + bibField.content = updatedBibSubfields.toContentString(); }, [copySubfieldsFromAuthority, sourceFiles]); const getSubfieldGroups = useCallback((field, suggestedField) => { @@ -211,11 +205,11 @@ const useAuthorityLinking = ({ tenantId, marcType, action } = {}) => { const uncontrolledAlphaSubfields = new MarcFieldContent(field.subfieldGroups?.[UNCONTROLLED_ALPHA]); const uncontrolledNumber = uncontrolledNumberSubfields.$9?.[0] - ? uncontrolledNumberSubfields.removeByCode('$9').join() + ? uncontrolledNumberSubfields.removeByCode('$9').toContentString() : field.subfieldGroups[UNCONTROLLED_NUMBER]; const uncontrolledAlpha = uncontrolledAlphaSubfields.$9?.[0] - ? uncontrolledAlphaSubfields.removeByCode('$9').join() + ? uncontrolledAlphaSubfields.removeByCode('$9').toContentString() : field.subfieldGroups[UNCONTROLLED_ALPHA]; return { @@ -237,7 +231,7 @@ const useAuthorityLinking = ({ tenantId, marcType, action } = {}) => { ) { return { ...field, - content: subfields.removeByCode('$9').join(), + content: subfields.removeByCode('$9').toContentString(), }; } @@ -338,7 +332,7 @@ const useAuthorityLinking = ({ tenantId, marcType, action } = {}) => { delete field.linkDetails; delete field.subfieldGroups; - field.content = field.prevContent ?? bibSubfields.join(); + field.content = field.prevContent ?? bibSubfields.toContentString(); delete field.prevContent; return {