Skip to content

Commit

Permalink
UIQM-716-test
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmytro-Melnyshyn committed Nov 13, 2024
1 parent 949fd48 commit 241e8e0
Show file tree
Hide file tree
Showing 12 changed files with 1,339 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/MarcRoute/MarcRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const MarcRoute = ({
const {
marcType,
action,
useMarcActionHandler,
} = routeProps;
const centralTenantId = stripes.user.user?.consortium?.centralTenantId;
const isRequestToCentralTenantFromMember = applyCentralTenantInHeaders(location, stripes, marcType)
Expand Down Expand Up @@ -75,6 +76,7 @@ const MarcRoute = ({
onClose={onClose}
onSave={onSave}
externalRecordPath={externalRecordPath}
useMarcActionHandler={useMarcActionHandler}
onCheckCentralTenantPerm={checkCentralTenantPerm}
/>
</QuickMarcProvider>
Expand Down
25 changes: 22 additions & 3 deletions src/QuickMarc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useMemo } from 'react';
import PropTypes from 'prop-types';
import {
Switch,
Expand All @@ -13,6 +13,19 @@ import {
MARC_TYPES,
keyboardCommands,
} from './common/constants';
import { useMarcCreate } from './QuickMarcEditor/useMarcCreate';
import { useMarcEdit } from './QuickMarcEditor/useMarcEdit';
import { useMarcDerive } from './QuickMarcEditor/useMarcDerive';

const createUseMarcActionHandler = (action) => {
const marcActionHooks = {
[QUICK_MARC_ACTIONS.CREATE]: useMarcCreate,
[QUICK_MARC_ACTIONS.EDIT]: useMarcEdit,
[QUICK_MARC_ACTIONS.DERIVE]: useMarcDerive,
};

return marcActionHooks[action];
};

const QuickMarc = ({
basePath,
Expand All @@ -33,13 +46,16 @@ const QuickMarc = ({
// .../some-path/create-bibliographic => [, create-bibliographic, create, bibliographic]
const [, page, action] = location.pathname.match(/\/((edit|create|derive)-(bibliographic|authority|holdings))/) || [];

const useMarcActionHandler = useMemo(() => createUseMarcActionHandler(action), [action]);

const editorRoutesConfig = [
{
path: `${basePath}/:action-bibliographic/:externalId?`,
permission: permissionsMap[page],
props: {
action,
marcType: MARC_TYPES.BIB,
useMarcActionHandler,
},
},
{
Expand All @@ -48,22 +64,25 @@ const QuickMarc = ({
props: {
action,
marcType: MARC_TYPES.AUTHORITY,
useMarcActionHandler,
},
},
{
path: `${basePath}/create-holdings/:externalId`,
permission: 'ui-quick-marc.quick-marc-holdings-editor.create',
props: {
action: QUICK_MARC_ACTIONS.CREATE,
action,
marcType: MARC_TYPES.HOLDINGS,
useMarcActionHandler,
},
},
{
path: `${basePath}/edit-holdings/:instanceId/:externalId`,
permission: 'ui-quick-marc.quick-marc-holdings-editor.all',
props: {
action: QUICK_MARC_ACTIONS.EDIT,
action,
marcType: MARC_TYPES.HOLDINGS,
useMarcActionHandler,
},
},
];
Expand Down
241 changes: 241 additions & 0 deletions src/QuickMarcEditor/QuickMarcCreateWrapper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
// import React, {
// useCallback,
// useContext,
// useMemo,
// useState,
// } from 'react';
// import { useHistory, useLocation } from 'react-router-dom';
// import PropTypes from 'prop-types';
// import flow from 'lodash/flow';
// import noop from 'lodash/noop';
// import isEmpty from 'lodash/isEmpty';
//
// import { useShowCallout } from '@folio/stripes-acq-components';
// import { useStripes } from '@folio/stripes/core';
//
// import QuickMarcEditor from './QuickMarcEditor';
// import { QuickMarcContext } from '../contexts';
// import getQuickMarcRecordStatus from './getQuickMarcRecordStatus';
// import {
// useAuthorityLinking,
// useValidation,
// } from '../hooks';
// import { QUICK_MARC_ACTIONS } from './constants';
// import { MARC_TYPES } from '../common/constants';
// import {
// hydrateMarcRecord,
// formatLeaderForSubmit,
// autopopulateSubfieldSection,
// cleanBytesFields,
// parseHttpError,
// removeDeletedRecords,
// saveLinksToNewRecord,
// recordHasLinks,
// combineSplitFields,
// autopopulateFixedField,
// autopopulatePhysDescriptionField,
// autopopulateMaterialCharsField,
// autopopulateIndicators,
// removeRowsWithoutContent,
// applyCentralTenantInHeaders, getFieldIds,
// } from './utils';
//
// const propTypes = {
// action: PropTypes.oneOf(Object.values(QUICK_MARC_ACTIONS)).isRequired,
// initialValues: PropTypes.object.isRequired,
// instance: PropTypes.object,
// locations: PropTypes.object.isRequired,
// marcType: PropTypes.oneOf(Object.values(MARC_TYPES)).isRequired,
// fixedFieldSpec: PropTypes.object.isRequired,
// mutator: PropTypes.object.isRequired,
// onClose: PropTypes.func.isRequired,
// onSave: PropTypes.func.isRequired,
// };
//
// const QuickMarcCreateWrapper = ({
// action,
// instance,
// onClose,
// onSave,
// initialValues,
// mutator,
// marcType,
// fixedFieldSpec,
// locations,
//
// refreshPageData,
// }) => {
// const stripes = useStripes();
// const history = useHistory();
// const location = useLocation();
// const showCallout = useShowCallout();
// const [httpError, setHttpError] = useState(null);
// const { linkableBibFields, actualizeLinks, linkingRules, sourceFiles } = useAuthorityLinking({ marcType, action });
// const {
// validationErrorsRef,
// continueAfterSave,
// basePath,
// } = useContext(QuickMarcContext);
//
// const isRequestToCentralTenantFromMember = applyCentralTenantInHeaders(location, stripes, marcType);
// const centralTenantId = stripes.user.user.consortium?.centralTenantId;
// const tenantId = isRequestToCentralTenantFromMember ? centralTenantId : '';
//
// const validationContext = useMemo(() => ({
// initialValues,
// marcType,
// action: QUICK_MARC_ACTIONS.CREATE,
// locations,
// linkableBibFields,
// linkingRules,
// sourceFiles,
// fixedFieldSpec,
// instanceId: instance.id,
// }), [initialValues, marcType, locations, linkableBibFields, linkingRules, sourceFiles, fixedFieldSpec, instance.id]);
// const { validate } = useValidation(validationContext, tenantId);
//
// const prepareForSubmit = useCallback((formValues) => {
// const formValuesForCreate = flow(
// removeDeletedRecords,
// removeRowsWithoutContent,
// autopopulateIndicators,
// marcRecord => autopopulateFixedField(marcRecord, marcType, fixedFieldSpec),
// autopopulatePhysDescriptionField,
// autopopulateMaterialCharsField,
// marcRecord => autopopulateSubfieldSection(marcRecord, marcType),
// marcRecord => cleanBytesFields(marcRecord, fixedFieldSpec, marcType),
// marcRecord => formatLeaderForSubmit(marcType, marcRecord),
// combineSplitFields,
// )(formValues);
//
// return formValuesForCreate;
// }, [marcType, fixedFieldSpec]);
//
// const runValidation = useCallback(async (formValues) => {
// const formValuesForValidation = prepareForSubmit(formValues);
//
// return validate(formValuesForValidation.records);
// }, [validate, prepareForSubmit]);
//
// const redirectToRecord = useCallback(async (externalId, instanceId) => {
// if (marcType === MARC_TYPES.HOLDINGS) {
// await onSave(`${instanceId}/${externalId}`);
// } else {
// await onSave(externalId);
// }
// }, [onSave, marcType]);
//
// const processEditingAfterCreation = useCallback(async (formValues, externalId) => {
// const fieldIds = getFieldIds(formValues);
// const searchParams = new URLSearchParams(location.search);
//
// const routes = {
// [MARC_TYPES.BIB]: `${basePath}/edit-bibliographic/${externalId}`,
// [MARC_TYPES.AUTHORITY]: `${basePath}/edit-authority/${externalId}`,
// [MARC_TYPES.HOLDINGS]: `${basePath}/edit-holdings/${externalId}`,
// };
//
// await refreshPageData(fieldIds, QUICK_MARC_ACTIONS.EDIT, externalId);
//
// history.push({
// pathname: routes[marcType],
// search: searchParams.toString(),
// });
// }, [basePath, marcType, location, history, refreshPageData]);
//
// const onSubmit = useCallback(async (formValues, _api, complete) => {
// // if validation has any issues - cancel submit
// if (!isEmpty(validationErrorsRef.current)) {
// return complete();
// }
//
// const formValuesToProcess = prepareForSubmit(formValues);
//
// let formValuesToHydrate;
//
// try {
// if (marcType === MARC_TYPES.BIB) {
// formValuesToHydrate = await actualizeLinks(formValuesToProcess);
// } else {
// formValuesToHydrate = formValuesToProcess;
// }
// } catch (errorResponse) {
// const parsedError = await parseHttpError(errorResponse);
//
// setHttpError(parsedError);
//
// return null;
// }
//
// formValuesToHydrate._actionType = 'create';
//
// const formValuesForCreate = hydrateMarcRecord(formValuesToHydrate);
//
// return mutator.quickMarcEditMarcRecord.POST(formValuesForCreate)
// .then(async ({ qmRecordId }) => {
// const instanceId = formValues.externalId;
//
// showCallout({ messageId: 'ui-quick-marc.record.save.success.processing' });
//
// try {
// const { externalId } = await getQuickMarcRecordStatus({
// quickMarcRecordStatusGETRequest: mutator.quickMarcRecordStatus.GET,
// qmRecordId,
// showCallout,
// });
//
// showCallout({ messageId: 'ui-quick-marc.record.saveNew.success' });
//
// if (marcType === MARC_TYPES.BIB && recordHasLinks(formValuesForCreate.fields)) {
// await saveLinksToNewRecord(mutator, externalId, formValuesForCreate)
// .catch(noop);
// }
//
// if (continueAfterSave.current) {
// await processEditingAfterCreation(formValues, externalId);
//
// return;
// }
//
// await redirectToRecord(externalId, instanceId);
// } catch (e) {
// showCallout({
// messageId: 'ui-quick-marc.record.saveNew.error',
// type: 'error',
// });
// }
// })
// .catch(async (errorResponse) => {
// const parsedError = await parseHttpError(errorResponse);
//
// setHttpError(parsedError);
// });
// // eslint-disable-next-line react-hooks/exhaustive-deps
// }, [
// onClose,
// showCallout,
// prepareForSubmit,
// actualizeLinks,
// validationErrorsRef,
// continueAfterSave,
// processEditingAfterCreation,
// ]);
//
// return (
// <QuickMarcEditor
// instance={instance}
// onClose={onClose}
// initialValues={initialValues}
// onSubmit={onSubmit}
// action={action}
// marcType={marcType}
// fixedFieldSpec={fixedFieldSpec}
// httpError={httpError}
// validate={runValidation}
// />
// );
// };
//
// QuickMarcCreateWrapper.propTypes = propTypes;
//
// export default QuickMarcCreateWrapper;
Loading

0 comments on commit 241e8e0

Please sign in to comment.