Skip to content

Commit

Permalink
UIQM-724 renamed MarcFieldContent join to toContentString
Browse files Browse the repository at this point in the history
  • Loading branch information
BogdanDenis committed Oct 30, 2024
1 parent 83e834d commit 54926a7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/common/entities/MarcFieldContent/MarcFieldContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
10 changes: 5 additions & 5 deletions src/common/entities/MarcFieldContent/MarcFieldContent.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,33 +51,33 @@ 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);
});
});

describe('when calling `append`', () => {
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`);
});
});

describe('when calling `prepend`', () => {
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}`);
});
});

describe('when calling `removeByCode`', () => {
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');
});
});

Expand Down
16 changes: 5 additions & 11 deletions src/hooks/useAuthorityLinking/useAuthorityLinking.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 } = {}) => {
Expand Down Expand Up @@ -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) => {
Expand All @@ -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 {
Expand All @@ -237,7 +231,7 @@ const useAuthorityLinking = ({ tenantId, marcType, action } = {}) => {
) {
return {
...field,
content: subfields.removeByCode('$9').join(),
content: subfields.removeByCode('$9').toContentString(),
};
}

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 54926a7

Please sign in to comment.