Skip to content

Commit

Permalink
UIQM-431 Marc record fixed field 008 with proper order. (#602)
Browse files Browse the repository at this point in the history
* UIQM-431 Marc record fixed field 008 with proper order.

Depends of marc specifications api for fixed field 008.

* Fix after code review

Made changes as suggested

* Replace Bibliographic, Authority, Holdings FixedField to one FixedField

Replace Bibliographic, Authority, Holdings FixedField to one FixedField
Refactory getFixedField without marcType
Removed unnecessary tests, fixed current without using the marcType props
  • Loading branch information
przemyslawturek authored Oct 3, 2023
1 parent b28eaa4 commit 2e8a25f
Show file tree
Hide file tree
Showing 39 changed files with 1,328 additions and 1,076 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@
* [UIQM-559](https://issues.folio.org/browse/UIQM-559) Make auto-linking for the consortium.
* [UIQM-558](https://issues.folio.org/browse/UIQM-558) Allow a user to select a location code from the plugin.
* [UIQM-562](https://issues.folio.org/browse/UIQM-562) Fix optimistic locking error doesn't appear when edit "MARC authority" record.
* [UIQM-564](https://issues.folio.org/browse/UIQM-564) Hide permission `quickMARC: Create a new MARC authority record`.
* [UIQM-564](https://issues.folio.org/browse/UIQM-564) Hide permission `quickMARC: Create a new MARC authority record
* [UIQM-431](https://issues.folio.org/browse/UIQM-431) Marc record fixed field 008 with proper order.

## [6.0.2](https://github.com/folio-org/ui-quick-marc/tree/v6.0.2) (2023-03-30)

Expand Down
7 changes: 5 additions & 2 deletions src/QuickMarcEditor/QuickMarcCreateWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const propTypes = {
location: ReactRouterPropTypes.location.isRequired,
locations: PropTypes.object.isRequired,
marcType: PropTypes.oneOf(Object.values(MARC_TYPES)).isRequired,
fixedFieldSpec: PropTypes.object.isRequired,
mutator: PropTypes.object.isRequired,
onClose: PropTypes.func.isRequired,
};
Expand All @@ -52,6 +53,7 @@ const QuickMarcCreateWrapper = ({
history,
location,
marcType,
fixedFieldSpec,
locations,
}) => {
const showCallout = useShowCallout();
Expand All @@ -67,11 +69,11 @@ const QuickMarcCreateWrapper = ({
autopopulatePhysDescriptionField,
autopopulateMaterialCharsField,
marcRecord => autopopulateSubfieldSection(marcRecord, marcType),
marcRecord => cleanBytesFields(marcRecord, marcType),
marcRecord => cleanBytesFields(marcRecord, fixedFieldSpec),
)(formValues);

return formValuesForCreate;
}, [marcType]);
}, [marcType, fixedFieldSpec]);

const validate = useCallback((formValues) => {
const formValuesForValidation = prepareForSubmit(formValues);
Expand Down Expand Up @@ -182,6 +184,7 @@ const QuickMarcCreateWrapper = ({
onSubmit={onSubmit}
action={action}
marcType={marcType}
fixedFieldSpec={fixedFieldSpec}
httpError={httpError}
validate={validate}
/>
Expand Down
7 changes: 5 additions & 2 deletions src/QuickMarcEditor/QuickMarcDeriveWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const propTypes = {
initialValues: PropTypes.object.isRequired,
instance: PropTypes.object,
marcType: PropTypes.oneOf(Object.values(MARC_TYPES)).isRequired,
fixedFieldSpec: PropTypes.object.isRequired,
mutator: PropTypes.object.isRequired,
onClose: PropTypes.func.isRequired,
};
Expand All @@ -47,6 +48,7 @@ const QuickMarcDeriveWrapper = ({
initialValues,
mutator,
marcType,
fixedFieldSpec,
}) => {
const showCallout = useShowCallout();
const { linkableBibFields, actualizeLinks, linkingRules } = useAuthorityLinking({ marcType, action });
Expand All @@ -62,11 +64,11 @@ const QuickMarcDeriveWrapper = ({
autopopulatePhysDescriptionField,
autopopulateMaterialCharsField,
marcRecord => autopopulateSubfieldSection(marcRecord, marcType),
marcRecord => cleanBytesFields(marcRecord, marcType),
marcRecord => cleanBytesFields(marcRecord, fixedFieldSpec),
)(formValues);

return formValuesForDerive;
}, [marcType]);
}, [marcType, fixedFieldSpec]);

const validate = useCallback((formValues) => {
const formValuesForValidation = prepareForSubmit(formValues);
Expand Down Expand Up @@ -157,6 +159,7 @@ const QuickMarcDeriveWrapper = ({
onSubmit={onSubmit}
action={action}
marcType={marcType}
fixedFieldSpec={fixedFieldSpec}
httpError={httpError}
confirmRemoveAuthorityLinking
validate={validate}
Expand Down
6 changes: 5 additions & 1 deletion src/QuickMarcEditor/QuickMarcEditWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const propTypes = {
initialValues: PropTypes.object.isRequired,
instance: PropTypes.object,
marcType: PropTypes.oneOf(Object.values(MARC_TYPES)).isRequired,
fixedFieldSpec: PropTypes.object.isRequired,
mutator: PropTypes.object.isRequired,
onClose: PropTypes.func.isRequired,
onCheckCentralTenantPerm: PropTypes.func,
Expand All @@ -64,6 +65,7 @@ const QuickMarcEditWrapper = ({
initialValues,
mutator,
marcType,
fixedFieldSpec,
linksCount,
locations,
refreshPageData,
Expand Down Expand Up @@ -141,7 +143,7 @@ const QuickMarcEditWrapper = ({
autopopulatePhysDescriptionField,
autopopulateMaterialCharsField,
marcRecord => autopopulateSubfieldSection(marcRecord, marcType),
marcRecord => cleanBytesFields(marcRecord, marcType),
marcRecord => cleanBytesFields(marcRecord, fixedFieldSpec),
combineSplitFields,
)(formValues);

Expand Down Expand Up @@ -233,6 +235,7 @@ const QuickMarcEditWrapper = ({
initialValues,
instance,
marcType,
fixedFieldSpec,
mutator,
linksCount,
location,
Expand All @@ -254,6 +257,7 @@ const QuickMarcEditWrapper = ({
onSubmit={onSubmit}
action={action}
marcType={marcType}
fixedFieldSpec={fixedFieldSpec}
locations={locations}
httpError={httpError}
externalRecordPath={externalRecordPath}
Expand Down
7 changes: 5 additions & 2 deletions src/QuickMarcEditor/QuickMarcEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ const QuickMarcEditor = ({
getState,
},
marcType,
fixedFieldSpec,
locations,
httpError,
externalRecordPath,
Expand Down Expand Up @@ -125,8 +126,8 @@ const QuickMarcEditor = ({
}, [records]);

const leader = records[0];
const type = leader?.content?.[6];
const subtype = leader?.content?.[7];
const type = leader?.content?.[6] || '';
const subtype = leader?.content?.[7] || '';

const saveFormDisabled = action === QUICK_MARC_ACTIONS.EDIT
? pristine || submitting
Expand Down Expand Up @@ -475,6 +476,7 @@ const QuickMarcEditor = ({
type={type}
subtype={subtype}
marcType={marcType}
fixedFieldSpec={fixedFieldSpec}
instance={instance}
linksCount={linksCount}
isLoadingLinkSuggestions={isLoadingLinkSuggestions}
Expand Down Expand Up @@ -551,6 +553,7 @@ QuickMarcEditor.propTypes = {
reset: PropTypes.func.isRequired,
}),
marcType: PropTypes.oneOf(Object.values(MARC_TYPES)).isRequired,
fixedFieldSpec: PropTypes.object.isRequired,
linksCount: PropTypes.number,
locations: PropTypes.arrayOf(PropTypes.object).isRequired,
httpError: PropTypes.shape({
Expand Down
36 changes: 33 additions & 3 deletions src/QuickMarcEditor/QuickMarcEditorContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
MARC_RECORD_STATUS_API,
MARC_TYPES,
LINKING_RULES_API,
MARC_SPEC_API,
} from '../common/constants';

import {
Expand Down Expand Up @@ -85,6 +86,7 @@ const QuickMarcEditorContainer = ({
const [locations, setLocations] = useState();
const [isLoading, setIsLoading] = useState(true);
const [linksCount, setLinksCount] = useState(0);
const [fixedFieldSpec, setFixedFieldSpec] = useState();

const searchParams = new URLSearchParams(location.search);
const { token, locale } = stripes.okapi;
Expand Down Expand Up @@ -146,8 +148,27 @@ const QuickMarcEditorContainer = ({
? fetchLinksCount([externalId])
: Promise.resolve();

await Promise.all([instancePromise, marcRecordPromise, locationsPromise, linksCountPromise, linkingRulesPromise])
.then(([instanceResponse, marcRecordResponse, locationsResponse, linksCountResponse, linkingRulesResponse]) => {
const fixedFieldSpecPromise = mutator.fixedFieldSpec.GET({
path: `${MARC_SPEC_API}/${marcType}/008`,
...headers,
});

await Promise.all([
instancePromise,
marcRecordPromise,
locationsPromise,
linksCountPromise,
linkingRulesPromise,
fixedFieldSpecPromise,
])
.then(([
instanceResponse,
marcRecordResponse,
locationsResponse,
linksCountResponse,
linkingRulesResponse,
fixedFieldSpecResponse,
]) => {
if (marcType === MARC_TYPES.AUTHORITY) {
setLinksCount(linksCountResponse.links[0].totalLinks);
}
Expand All @@ -165,7 +186,7 @@ const QuickMarcEditorContainer = ({
if (action === QUICK_MARC_ACTIONS.CREATE) {
dehydratedMarcRecord = createRecordDefaults[marcType](instanceResponse);
} else {
dehydratedMarcRecord = dehydrateMarcRecordResponse(marcRecordResponse, marcType);
dehydratedMarcRecord = dehydrateMarcRecordResponse(marcRecordResponse, marcType, fixedFieldSpecResponse);
}

const formattedMarcRecord = formatMarcRecordByQuickMarcAction(dehydratedMarcRecord, action, marcType);
Expand All @@ -175,6 +196,7 @@ const QuickMarcEditorContainer = ({
setInstance(instanceResponse);
setMarcRecord(marcRecordWithSplitFields);
setLocations(locationsResponse);
setFixedFieldSpec(fixedFieldSpecResponse);
setIsLoading(false);
})
.catch(() => {
Expand Down Expand Up @@ -219,6 +241,7 @@ const QuickMarcEditorContainer = ({
location={location}
locations={locations}
marcType={marcType}
fixedFieldSpec={fixedFieldSpec}
refreshPageData={loadData}
externalRecordPath={externalRecordUrl}
resources={resources}
Expand Down Expand Up @@ -263,6 +286,13 @@ QuickMarcEditorContainer.manifest = Object.freeze({
path: LINKING_RULES_API,
throwErrors: false,
},
fixedFieldSpec: {
type: 'okapi',
fetch: false,
accumulate: true,
path: MARC_SPEC_API,
throwErrors: false,
},
});

QuickMarcEditorContainer.propTypes = propTypes;
Expand Down
3 changes: 3 additions & 0 deletions src/QuickMarcEditor/QuickMarcEditorContainer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ describe('Given Quick Marc Editor Container', () => {
linkingRules: {
GET: jest.fn().mockResolvedValue([]),
},
fixedFieldSpec: {
GET: jest.fn(() => Promise.resolve()),
},
};

applyCentralTenantInHeaders.mockReturnValue(false);
Expand Down
76 changes: 50 additions & 26 deletions src/QuickMarcEditor/QuickMarcEditorRows/BytesField/BytesField.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { FormattedMessage } from 'react-intl';
import {
Label,
TextField,
Tooltip,
Select,
} from '@folio/stripes/components';

Expand All @@ -24,6 +25,8 @@ export const SUBFIELD_TYPES = {
const renderSubField = (name, config) => {
const fieldName = `${name}.${config.name}`;
const label = <FormattedMessage id={`ui-quick-marc.record.fixedField.${config.name}`} />;
const hint = config.hint ? config.hint : config.name;
const labelHint = <FormattedMessage id={`ui-quick-marc.record.fixedField.tip.${hint}`} />;
const defaultValue = new Array(config.length || 1).fill('\\').join('');

if (config.type === SUBFIELD_TYPES.BYTES) {
Expand All @@ -45,19 +48,30 @@ const renderSubField = (name, config) => {
id={`ui-quick-marc.record.fixedField.${config.name}`}
>
{([ariaLabel]) => (
<Field
dirty={false}
ariaLabel={ariaLabel}
name={`${fieldName}[${idx}]`}
component={TextField}
maxLength={FIXED_FIELD_MAX_LENGTH}
disabled={config.disabled}
className={styles.fixedFieldSubFieldByte}
hasClearIcon={false}
data-testid={`fixed-field-${config.type}`}
parse={value => value || defaultValue}
defaultValue={defaultValue}
/>

<Tooltip
id={`ui-quick-marc.record.fixedField-${config.name}${idx}`}
text={labelHint}
placement="bottom-start"
>
{({ ref, ariaIds }) => (
<Field
inputRef={ref}
dirty={false}
ariaLabel={ariaLabel}
aria-labelledby={ariaIds.text}
name={`${fieldName}[${idx}]`}
component={TextField}
maxLength={FIXED_FIELD_MAX_LENGTH}
disabled={config.disabled}
className={styles.fixedFieldSubFieldByte}
hasClearIcon={false}
data-testid={`fixed-field-${config.type}`}
parse={value => value || defaultValue}
defaultValue={defaultValue}
/>
)}
</Tooltip>
)}
</FormattedMessage>
);
Expand Down Expand Up @@ -92,19 +106,29 @@ const renderSubField = (name, config) => {
return (
<FormattedMessage id={`ui-quick-marc.record.fixedField.${config.name}`}>
{([ariaLabel]) => (
<Field
dirty={false}
ariaLabel={ariaLabel}
name={fieldName}
label={label}
component={TextField}
disabled={config.disabled}
maxLength={getMaxLengthByType}
className={styles[`bytesFieldSubField${config.type}`]}
hasClearIcon={false}
data-testid={`fixed-field-${config.type}`}
defaultValue={defaultValue}
/>
<Tooltip
id={`ui-quick-marc.record.fixedField-${config.name}`}
text={labelHint}
placement="bottom-start"
>
{({ ref, ariaIds }) => (
<Field
inputRef={ref}
dirty={false}
ariaLabel={ariaLabel}
aria-labelledby={ariaIds.text}
name={fieldName}
label={label}
component={TextField}
disabled={config.disabled}
maxLength={getMaxLengthByType}
className={styles[`bytesFieldSubField${config.type}`]}
hasClearIcon={false}
data-testid={`fixed-field-${config.type}`}
defaultValue={defaultValue}
/>
)}
</Tooltip>
)}
</FormattedMessage>
);
Expand Down
Loading

0 comments on commit 2e8a25f

Please sign in to comment.