Skip to content

Commit

Permalink
UIQM-431 Marc record fixed field 008 with proper order.
Browse files Browse the repository at this point in the history
Depends of marc specifications api for fixed field 008.
  • Loading branch information
przemyslawturek committed Sep 29, 2023
1 parent 4b28c4f commit 5d5d19e
Show file tree
Hide file tree
Showing 39 changed files with 1,380 additions and 1,010 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
* [UIQM-558](https://issues.folio.org/browse/UIQM-558) *BREAKING* bump `react-intl` to `v6.4.4`.
* [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-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,
marcSpec: PropTypes.object.isRequired,
mutator: PropTypes.object.isRequired,
onClose: PropTypes.func.isRequired,
};
Expand All @@ -52,6 +53,7 @@ const QuickMarcCreateWrapper = ({
history,
location,
marcType,
marcSpec,
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, marcSpec),
)(formValues);

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

const validate = useCallback((formValues) => {
const formValuesForValidation = prepareForSubmit(formValues);
Expand Down Expand Up @@ -182,6 +184,7 @@ const QuickMarcCreateWrapper = ({
onSubmit={onSubmit}
action={action}
marcType={marcType}
marcSpec={marcSpec}
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,
marcSpec: PropTypes.object.isRequired,
mutator: PropTypes.object.isRequired,
onClose: PropTypes.func.isRequired,
};
Expand All @@ -47,6 +48,7 @@ const QuickMarcDeriveWrapper = ({
initialValues,
mutator,
marcType,
marcSpec,
}) => {
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, marcSpec),
)(formValues);

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

const validate = useCallback((formValues) => {
const formValuesForValidation = prepareForSubmit(formValues);
Expand Down Expand Up @@ -157,6 +159,7 @@ const QuickMarcDeriveWrapper = ({
onSubmit={onSubmit}
action={action}
marcType={marcType}
marcSpec={marcSpec}
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 @@ -50,6 +50,7 @@ const propTypes = {
initialValues: PropTypes.object.isRequired,
instance: PropTypes.object,
marcType: PropTypes.oneOf(Object.values(MARC_TYPES)).isRequired,
marcSpec: PropTypes.object.isRequired,
mutator: PropTypes.object.isRequired,
onClose: PropTypes.func.isRequired,
onCheckCentralTenantPerm: PropTypes.func,
Expand All @@ -63,6 +64,7 @@ const QuickMarcEditWrapper = ({
initialValues,
mutator,
marcType,
marcSpec,
linksCount,
locations,
refreshPageData,
Expand Down Expand Up @@ -140,7 +142,7 @@ const QuickMarcEditWrapper = ({
autopopulatePhysDescriptionField,
autopopulateMaterialCharsField,
marcRecord => autopopulateSubfieldSection(marcRecord, marcType),
marcRecord => cleanBytesFields(marcRecord, marcType),
marcRecord => cleanBytesFields(marcRecord, marcSpec),
combineSplitFields,
)(formValues);

Expand Down Expand Up @@ -232,6 +234,7 @@ const QuickMarcEditWrapper = ({
initialValues,
instance,
marcType,
marcSpec,
mutator,
linksCount,
location,
Expand All @@ -253,6 +256,7 @@ const QuickMarcEditWrapper = ({
onSubmit={onSubmit}
action={action}
marcType={marcType}
marcSpec={marcSpec}
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,
marcSpec,
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}
marcSpec={marcSpec}
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,
marcSpec: 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 [marcSpec, setMarcSpec] = 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 marcSpecPromise = mutator.marcSpec.GET({
path: `${MARC_SPEC_API}/${marcType}/008`,
...headers,
});

await Promise.all([
instancePromise,
marcRecordPromise,
locationsPromise,
linksCountPromise,
linkingRulesPromise,
marcSpecPromise,
])
.then(([
instanceResponse,
marcRecordResponse,
locationsResponse,
linksCountResponse,
linkingRulesResponse,
marcSpecResponse,
]) => {
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, marcSpecResponse);
}

const formattedMarcRecord = formatMarcRecordByQuickMarcAction(dehydratedMarcRecord, action, marcType);
Expand All @@ -175,6 +196,7 @@ const QuickMarcEditorContainer = ({
setInstance(instanceResponse);
setMarcRecord(marcRecordWithSplitFields);
setLocations(locationsResponse);
setMarcSpec(marcSpecResponse);
setIsLoading(false);
})
.catch(() => {
Expand Down Expand Up @@ -219,6 +241,7 @@ const QuickMarcEditorContainer = ({
location={location}
locations={locations}
marcType={marcType}
marcSpec={marcSpec}
refreshPageData={loadData}
externalRecordPath={externalRecordUrl}
resources={resources}
Expand Down Expand Up @@ -263,6 +286,13 @@ QuickMarcEditorContainer.manifest = Object.freeze({
path: LINKING_RULES_API,
throwErrors: false,
},
marcSpec: {
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([]),
},
marcSpec: {
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 5d5d19e

Please sign in to comment.