Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UIQM-431 Marc record fixed field 008 with proper order. #602

Merged
merged 4 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
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 @@ -50,6 +50,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 @@ -63,6 +64,7 @@ const QuickMarcEditWrapper = ({
initialValues,
mutator,
marcType,
fixedFieldSpec,
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, fixedFieldSpec),
combineSplitFields,
)(formValues);

Expand Down Expand Up @@ -232,6 +234,7 @@ const QuickMarcEditWrapper = ({
initialValues,
instance,
marcType,
fixedFieldSpec,
mutator,
linksCount,
location,
Expand All @@ -253,6 +256,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
Loading