Skip to content

Commit

Permalink
Fix after code review
Browse files Browse the repository at this point in the history
Made changes as suggested
  • Loading branch information
przemyslawturek committed Oct 2, 2023
1 parent 5d5d19e commit c43a349
Show file tree
Hide file tree
Showing 14 changed files with 89 additions and 99 deletions.
10 changes: 5 additions & 5 deletions src/QuickMarcEditor/QuickMarcCreateWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const propTypes = {
location: ReactRouterPropTypes.location.isRequired,
locations: PropTypes.object.isRequired,
marcType: PropTypes.oneOf(Object.values(MARC_TYPES)).isRequired,
marcSpec: PropTypes.object.isRequired,
fixedFieldSpec: PropTypes.object.isRequired,
mutator: PropTypes.object.isRequired,
onClose: PropTypes.func.isRequired,
};
Expand All @@ -53,7 +53,7 @@ const QuickMarcCreateWrapper = ({
history,
location,
marcType,
marcSpec,
fixedFieldSpec,
locations,
}) => {
const showCallout = useShowCallout();
Expand All @@ -69,11 +69,11 @@ const QuickMarcCreateWrapper = ({
autopopulatePhysDescriptionField,
autopopulateMaterialCharsField,
marcRecord => autopopulateSubfieldSection(marcRecord, marcType),
marcRecord => cleanBytesFields(marcRecord, marcSpec),
marcRecord => cleanBytesFields(marcRecord, fixedFieldSpec),
)(formValues);

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

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

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

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

Expand Down Expand Up @@ -234,7 +234,7 @@ const QuickMarcEditWrapper = ({
initialValues,
instance,
marcType,
marcSpec,
fixedFieldSpec,
mutator,
linksCount,
location,
Expand All @@ -256,7 +256,7 @@ const QuickMarcEditWrapper = ({
onSubmit={onSubmit}
action={action}
marcType={marcType}
marcSpec={marcSpec}
fixedFieldSpec={fixedFieldSpec}
locations={locations}
httpError={httpError}
externalRecordPath={externalRecordPath}
Expand Down
6 changes: 3 additions & 3 deletions src/QuickMarcEditor/QuickMarcEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const QuickMarcEditor = ({
getState,
},
marcType,
marcSpec,
fixedFieldSpec,
locations,
httpError,
externalRecordPath,
Expand Down Expand Up @@ -476,7 +476,7 @@ const QuickMarcEditor = ({
type={type}
subtype={subtype}
marcType={marcType}
marcSpec={marcSpec}
fixedFieldSpec={fixedFieldSpec}
instance={instance}
linksCount={linksCount}
isLoadingLinkSuggestions={isLoadingLinkSuggestions}
Expand Down Expand Up @@ -553,7 +553,7 @@ QuickMarcEditor.propTypes = {
reset: PropTypes.func.isRequired,
}),
marcType: PropTypes.oneOf(Object.values(MARC_TYPES)).isRequired,
marcSpec: PropTypes.object.isRequired,
fixedFieldSpec: PropTypes.object.isRequired,
linksCount: PropTypes.number,
locations: PropTypes.arrayOf(PropTypes.object).isRequired,
httpError: PropTypes.shape({
Expand Down
16 changes: 8 additions & 8 deletions src/QuickMarcEditor/QuickMarcEditorContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const QuickMarcEditorContainer = ({
const [locations, setLocations] = useState();
const [isLoading, setIsLoading] = useState(true);
const [linksCount, setLinksCount] = useState(0);
const [marcSpec, setMarcSpec] = useState();
const [fixedFieldSpec, setFixedFieldSpec] = useState();

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

const marcSpecPromise = mutator.marcSpec.GET({
const fixedFieldSpecPromise = mutator.fixedFieldSpec.GET({
path: `${MARC_SPEC_API}/${marcType}/008`,
...headers,
});
Expand All @@ -159,15 +159,15 @@ const QuickMarcEditorContainer = ({
locationsPromise,
linksCountPromise,
linkingRulesPromise,
marcSpecPromise,
fixedFieldSpecPromise,
])
.then(([
instanceResponse,
marcRecordResponse,
locationsResponse,
linksCountResponse,
linkingRulesResponse,
marcSpecResponse,
fixedFieldSpecResponse,
]) => {
if (marcType === MARC_TYPES.AUTHORITY) {
setLinksCount(linksCountResponse.links[0].totalLinks);
Expand All @@ -186,7 +186,7 @@ const QuickMarcEditorContainer = ({
if (action === QUICK_MARC_ACTIONS.CREATE) {
dehydratedMarcRecord = createRecordDefaults[marcType](instanceResponse);
} else {
dehydratedMarcRecord = dehydrateMarcRecordResponse(marcRecordResponse, marcType, marcSpecResponse);
dehydratedMarcRecord = dehydrateMarcRecordResponse(marcRecordResponse, marcType, fixedFieldSpecResponse);
}

const formattedMarcRecord = formatMarcRecordByQuickMarcAction(dehydratedMarcRecord, action, marcType);
Expand All @@ -196,7 +196,7 @@ const QuickMarcEditorContainer = ({
setInstance(instanceResponse);
setMarcRecord(marcRecordWithSplitFields);
setLocations(locationsResponse);
setMarcSpec(marcSpecResponse);
setFixedFieldSpec(fixedFieldSpecResponse);
setIsLoading(false);
})
.catch(() => {
Expand Down Expand Up @@ -241,7 +241,7 @@ const QuickMarcEditorContainer = ({
location={location}
locations={locations}
marcType={marcType}
marcSpec={marcSpec}
fixedFieldSpec={fixedFieldSpec}
refreshPageData={loadData}
externalRecordPath={externalRecordUrl}
resources={resources}
Expand Down Expand Up @@ -286,7 +286,7 @@ QuickMarcEditorContainer.manifest = Object.freeze({
path: LINKING_RULES_API,
throwErrors: false,
},
marcSpec: {
fixedFieldSpec: {
type: 'okapi',
fetch: false,
accumulate: true,
Expand Down
2 changes: 1 addition & 1 deletion src/QuickMarcEditor/QuickMarcEditorContainer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ describe('Given Quick Marc Editor Container', () => {
linkingRules: {
GET: jest.fn().mockResolvedValue([]),
},
marcSpec: {
fixedFieldSpec: {
GET: jest.fn(() => Promise.resolve()),
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,47 +31,41 @@ export const FixedFieldFactory = {
return FixedField;
},

getDocumentType(marcSpec, type, subtype) {
let idx = -1;

if (!marcSpec?.spec) {
getFixedFieldType(fixedFieldSpec, type, subtype) {
if (!fixedFieldSpec?.spec) {
return undefined;
}

const checkTypeSubType = (orElement) => {
const hasTypePos = orElement.positions['6'] || false;
const hasSubTypePos = orElement.positions['7'] || false;
const typeOK = hasTypePos && orElement.positions['6'].includes(type);
const subTypeOK = hasSubTypePos ? hasSubTypePos && orElement.positions['7'].includes(subtype) : true;
const checkTypeSubType = (fieldIdentifier) => {
const hasTypePos = fieldIdentifier.positions['6'] || false;
const hasSubTypePos = fieldIdentifier.positions['7'] || false;
const typeOK = hasTypePos && fieldIdentifier.positions['6'].includes(type);
const subTypeOK = hasSubTypePos ? hasSubTypePos && fieldIdentifier.positions['7'].includes(subtype) : true;

return (typeOK && subTypeOK);
};

marcSpec.spec.types.forEach((marcType, indexType) => {
marcType.identifiedBy.or.forEach(orElement => {
if (orElement.tag === LEADER_TAG) {
if (checkTypeSubType(orElement)) {
idx = indexType;
}
}
const fixedFieldType = fixedFieldSpec.spec.types.find((fixedFieldTypeFind) => {
return fixedFieldTypeFind.identifiedBy.or.some((fieldIdentifier) => {
return fieldIdentifier.tag === LEADER_TAG && checkTypeSubType(fieldIdentifier);
});
});

return idx !== -1 ? marcSpec.spec.types[idx] : undefined;
return fixedFieldType;
},

getConfigFixedField(marcSpec, type, subtype = '') {
const documentType = this.getDocumentType(marcSpec, type, subtype);
getConfigFixedField(fixedFieldSpec, type, subtype = '') {
const fixedFieldType = this.getFixedFieldType(fixedFieldSpec, type, subtype);
const config = {
fields: [],
type: documentType?.code || undefined,
type: fixedFieldType?.code || undefined,
};

if (!documentType) {
if (!fixedFieldType) {
return config;
}

config.fields = documentType.items.filter(x => !x.readOnly).map((item) => {
config.fields = fixedFieldType.items.filter(x => !x.readOnly).map((item) => {
if (item.isArray) {
return {
name: item.code,
Expand Down Expand Up @@ -103,9 +97,9 @@ export const FixedFieldFactory = {
return config;
},

getFixedField(name, marcType, marcSpec, type, subtype) {
getFixedField(name, marcType, fixedFieldSpec, type, subtype) {
const FixedField = this.getFixedFieldByType(marcType);
const configFixedField = this.getConfigFixedField(marcSpec, type, subtype);
const configFixedField = this.getConfigFixedField(fixedFieldSpec, type, subtype);

return FixedField ? <FixedField name={name} config={configFixedField} /> : null;
},
Expand Down
Loading

0 comments on commit c43a349

Please sign in to comment.