Skip to content

Commit

Permalink
UIQM-534 Remove fields that have no MARC tag and no subfield value. (#…
Browse files Browse the repository at this point in the history
…630)

* UIQM-534 Remove fields that have no MARC tag and no subfield value.

* UIQM-534 Make tag length a constant value
  • Loading branch information
BogdanDenis authored Dec 7, 2023
1 parent 72457a7 commit adddfc1
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* [UIQM-591](https://issues.folio.org/browse/UIQM-591) Show permission `quickMARC: Create a new MARC authority record`. Don't load locations when MARC type is not Holdings.
* [UIQM-594](https://issues.folio.org/browse/UIQM-594) *BREAKING* Add authority-source-files interface.
* [UIQM-522](https://issues.folio.org/browse/UIQM-522) Create/Derive a new MARC bib record & Create a MARC holdings | Default state of Save & close button should be disabled.
* [UIQM-534](https://issues.folio.org/browse/UIQM-534) Remove fields that have no MARC tag and no subfield value.

## [7.0.4](https://github.com/folio-org/ui-quick-marc/tree/v7.0.4) (2023-11-09)

Expand Down
2 changes: 2 additions & 0 deletions src/QuickMarcEditor/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { MARC_TYPES } from '../common/constants';

export const LEADER_TAG = 'LDR';

export const TAG_LENGTH = 3;

export const LEADER_EDITABLE_BYTES = {
[MARC_TYPES.BIB]: [5, 6, 7, 8, 17, 18, 19],
[MARC_TYPES.HOLDINGS]: [5, 6, 17, 18],
Expand Down
25 changes: 15 additions & 10 deletions src/QuickMarcEditor/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
CREATE_AUTHORITY_RECORD_DEFAULT_FIELD_TAGS,
UNCONTROLLED_ALPHA,
UNCONTROLLED_NUMBER,
TAG_LENGTH,
} from './constants';
import { RECORD_STATUS_NEW } from './QuickMarcRecordInfo/constants';
import { SUBFIELD_TYPES } from './QuickMarcEditorRows/BytesField';
Expand Down Expand Up @@ -579,14 +580,26 @@ export const validateLocationSubfield = (field, locations) => {
return !!locations.find(location => location.code === locationValue);
};

const checkIsEmptyContent = (field) => {
if (typeof field.content === 'string') {
return compact(field.content.split(' ')).every(content => /^\$[a-z0-9]?$/.test(content));
}

return false;
};

export const validateRecordTag = marcRecords => {
if (marcRecords.some(({ tag }) => !tag || tag.length !== 3)) {
const nonEmptyRecords = marcRecords.filter(field => !checkIsEmptyContent(field));

if (nonEmptyRecords.some(({ tag }) => !tag || tag.length !== TAG_LENGTH)) {
return <FormattedMessage id="ui-quick-marc.record.error.tag.length" />;
}

const marcRecordsWithoutLDR = marcRecords.filter(record => record.tag !== LEADER_TAG);

if (marcRecordsWithoutLDR.some(({ tag }) => !tag.match(/\d{3}/))) {
const tagDigitsRegex = new RegExp(`^\\d{0,${TAG_LENGTH}}$`);

if (marcRecordsWithoutLDR.some(({ tag }) => !tag.match(tagDigitsRegex))) {
return <FormattedMessage id="ui-quick-marc.record.error.tag.nonDigits" />;
}

Expand Down Expand Up @@ -1100,14 +1113,6 @@ export const removeFieldsForDerive = (formValues) => {
};
};

const checkIsEmptyContent = (field) => {
if (typeof field.content === 'string') {
return compact(field.content.split(' ')).every(content => /^\$[a-z0-9]?$/.test(content));
}

return false;
};

export const autopopulateIndicators = (formValues) => {
const { records } = formValues;

Expand Down
15 changes: 15 additions & 0 deletions src/QuickMarcEditor/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1302,10 +1302,25 @@ describe('QuickMarcEditor utils', () => {
expect(utils.validateRecordTag(records)).not.toBeDefined();
});

it('should not return error message when tag is valid (invalid length) and field content is empty', () => {
const records = [
{
tag: '10',
content: '$a ',
},
{
tag: '245',
},
];

expect(utils.validateRecordTag(records)).not.toBeDefined();
});

it('should return error message when tag is not valid (invalid length)', () => {
const records = [
{
tag: '10',
content: '$a test',
},
{
tag: '245',
Expand Down

0 comments on commit adddfc1

Please sign in to comment.