Skip to content

Commit

Permalink
UIQM-426: Allow a user to manual enter/edit for non-linkable/non-cont…
Browse files Browse the repository at this point in the history
…rollable bib field
  • Loading branch information
BogdanDenis authored and Dmytro-Melnyshyn committed Mar 30, 2023
1 parent 4765349 commit 522e1de
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* [UIQM-430](https://issues.folio.org/browse/UIQM-430) If the user manually enters the $9 field on a non-linkable, then hide the authorized icon on the view source.
* [UIQM-426](https://issues.folio.org/browse/UIQM-426) Show error if $9 is added during deriving.
* [UIQM-422](https://issues.folio.org/browse/UIQM-422) Edit/Derive MARC bib | Show Type label on 006 and 007 MARC fields.
* [UIQM-426](https://issues.folio.org/browse/UIQM-426) Allow a user to manual enter/edit $9 for non-linkable/non-controllable bib field

## [6.0.1](https://github.com/folio-org/ui-quick-marc/tree/v6.0.1) (2023-03-14)

Expand Down
6 changes: 4 additions & 2 deletions src/QuickMarcEditor/QuickMarcEditWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import PropTypes from 'prop-types';
import { useShowCallout } from '@folio/stripes-acq-components';

import QuickMarcEditor from './QuickMarcEditor';

import { useAuthorityLinking } from '../hooks';
import { QUICK_MARC_ACTIONS } from './constants';
import {
EXTERNAL_INSTANCE_APIS,
Expand Down Expand Up @@ -56,6 +56,7 @@ const QuickMarcEditWrapper = ({
const showCallout = useShowCallout();
const location = useLocation();
const [httpError, setHttpError] = useState(null);
const { linkableBibFields } = useAuthorityLinking();

const prepareForSubmit = useCallback((formValues) => {
const formValuesToSave = removeDeletedRecords(formValues);
Expand All @@ -78,14 +79,15 @@ const QuickMarcEditWrapper = ({
locations,
linksCount,
naturalId: instance.naturalId,
linkableBibFields,
});

if (validationErrorMessage) {
return validationErrorMessage;
}

return undefined;
}, [initialValues, linksCount, locations, marcType, prepareForSubmit, instance.naturalId]);
}, [initialValues, linksCount, locations, marcType, prepareForSubmit, instance.naturalId, linkableBibFields]);

const onSubmit = useCallback(async (formValues) => {
let is1xxOr010Updated = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ const QuickMarcEditorRows = ({
const isContentField = !(isLocationField || isFixedField || isMaterialCharsField || isPhysDescriptionField);
const isMARCFieldProtections = marcType !== MARC_TYPES.HOLDINGS && action === QUICK_MARC_ACTIONS.EDIT;
const isProtectedField = recordRow.isProtected;
const isLinkVisible = checkCanBeLinked(stripes, marcType, action, linkableBibFields, recordRow.tag);
const isLinkVisible = checkCanBeLinked(stripes, marcType, linkableBibFields, recordRow.tag);

const canViewAuthorityRecord = stripes.hasPerm('ui-marc-authorities.authority-record.view') && recordRow._isLinked;

Expand Down
27 changes: 13 additions & 14 deletions src/QuickMarcEditor/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ export const checkDuplicate010Field = (marcRecords) => {
return undefined;
};

export const checkCanBeLinked = (stripes, marcType, action, linkableBibFields, tag) => (
export const checkCanBeLinked = (stripes, marcType, linkableBibFields, tag) => (
stripes.hasPerm('ui-quick-marc.quick-marc-authority-records.linkUnlink') &&
marcType === MARC_TYPES.BIB &&
linkableBibFields.includes(tag)
Expand All @@ -446,19 +446,17 @@ export const validateSubfield = (marcRecords, initialMarcRecords) => {
return undefined;
};

const validate$9 = (marcRecords, uncontrolledSubfields) => {
const hasEntered$9 = marcRecords.some(field => {
if (typeof field.content !== 'string') {
return false;
}
const validate$9InLinkable = (marcRecords, linkableBibFields, uncontrolledSubfields) => {
const fieldsToCheck = marcRecords.filter(field => linkableBibFields.includes(field.tag));

if (field.subfieldGroups) {
return uncontrolledSubfields.some(subfield => {
return field.subfieldGroups[subfield] && '$9' in getContentSubfieldValue(field.subfieldGroups[subfield]);
});
const hasEntered$9 = fieldsToCheck.some(field => {
if (!field.subfieldGroups) {
return '$9' in getContentSubfieldValue(field.content);
}

return '$9' in getContentSubfieldValue(field.content);
return uncontrolledSubfields.some(subfield => {
return field.subfieldGroups[subfield] && '$9' in getContentSubfieldValue(field.subfieldGroups[subfield]);
});
});

if (hasEntered$9) {
Expand Down Expand Up @@ -516,7 +514,7 @@ const validateSubfieldsThatCanBeControlled = (marcRecords, uncontrolledSubfields
return null;
};

const validateMarcBibRecord = (marcRecords) => {
const validateMarcBibRecord = (marcRecords, linkableBibFields) => {
const titleRecords = marcRecords.filter(({ tag }) => tag === '245');

if (titleRecords.length === 0) {
Expand All @@ -529,7 +527,7 @@ const validateMarcBibRecord = (marcRecords) => {

const uncontrolledSubfields = ['uncontrolledAlpha', 'uncontrolledNumber'];

const $9Error = validate$9(marcRecords, uncontrolledSubfields);
const $9Error = validate$9InLinkable(marcRecords, linkableBibFields, uncontrolledSubfields);

if ($9Error) {
return $9Error;
Expand Down Expand Up @@ -685,6 +683,7 @@ export const validateMarcRecord = ({
locations = [],
linksCount,
naturalId,
linkableBibFields = [],
}) => {
const marcRecords = marcRecord.records || [];
const initialMarcRecords = initialValues.records;
Expand All @@ -699,7 +698,7 @@ export const validateMarcRecord = ({
let validationResult;

if (marcType === MARC_TYPES.BIB) {
validationResult = validateMarcBibRecord(marcRecords);
validationResult = validateMarcBibRecord(marcRecords, linkableBibFields);
} else if (marcType === MARC_TYPES.HOLDINGS) {
validationResult = validateMarcHoldingsRecord(marcRecords, locations);
} else if (marcType === MARC_TYPES.AUTHORITY) {
Expand Down
27 changes: 25 additions & 2 deletions src/QuickMarcEditor/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,15 @@ describe('QuickMarcEditor utils', () => {
'_isDeleted': false,
'_isLinked': false,
},
{
'tag': '500',
'content': '$a Black Panther $c (Fictitious character) $v Comic books, strips, etc.',
'indicators': ['0', '0'],
'isProtected': false,
'id': '402c0aec-5e1b-49a3-83a2-da788f48b27a',
'_isDeleted': false,
'_isLinked': false,
},
],
};

Expand All @@ -430,19 +439,33 @@ describe('QuickMarcEditor utils', () => {
expect(utils.validateMarcRecord({
marcRecord: record,
initialValues,
linkableBibFields: ['100', '600'],
}).props.id).toBe('ui-quick-marc.record.error.$9');
});

it('should return an error for a not linked field', () => {
it('should return an error for linkable field', () => {
const record = cloneDeep(initialValues);

record.records[4].content += ' $9 fakeValue';
record.records[4].content = '$9 fakeValue';

expect(utils.validateMarcRecord({
marcRecord: record,
initialValues,
linkableBibFields: ['100', '600'],
}).props.id).toBe('ui-quick-marc.record.error.$9');
});

it('should not return an error for a not linkable field', () => {
const record = cloneDeep(initialValues);

record.records[5].content += ' $9 fakeValue';

expect(utils.validateMarcRecord({
marcRecord: record,
initialValues,
linkableBibFields: ['100', '600'],
})).toBeUndefined();
});
});

describe('when a user enters into the linked field subfield(s) that can be controlled', () => {
Expand Down
2 changes: 1 addition & 1 deletion translations/ui-quick-marc/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
"record.error.tag.nonDigits": "Invalid MARC tag. Please try again.",
"record.error.subfield": "Missing a subfield value for a MARC tag",
"record.error.location.invalid": "852 $b contains an invalid Location code. Please try again.",
"record.error.$9": "$9 is not a valid subfield.",
"record.error.$9": "$9 is an invalid subfield for linkable bibliographic fields.",
"record.error.1xx.change": "Cannot change the <b>saved MARC authority field {tag}</b> because it controls a bibliographic field(s). To change this 1XX, you must unlink all controlled bibliographic fields.",
"record.error.1xx.add$t": "Cannot add a <b>$t to the ${tag} field</b> because it controls a bibliographic field(s) that cannot control this subfield. To change this 1XX value, you must unlink all controlled bibliographic fields that cannot control $t.",
"record.error.1xx.remove$t": "Cannot remove <b>$t from the ${tag} field</b> because it controls a bibliographic field(s) that requires this subfield. To change this 1XX value, you must unlink all controlled bibliographic fields that requires $t to be controlled.",
Expand Down

0 comments on commit 522e1de

Please sign in to comment.