From f8a241c2c2eb20732dfe694b6f1122b8cb285a3e Mon Sep 17 00:00:00 2001 From: Siarhei Karol Date: Mon, 2 Dec 2024 11:57:09 +0300 Subject: [PATCH] code refactoring: rename properties and methods; disable devtools in prod mode --- src/common/constants/bundle.constants.ts | 1 + src/common/hooks/useComplexLookup.ts | 6 ++--- src/common/hooks/useMarcData.ts | 2 +- .../MarcPreviewComplexLookup.tsx | 2 +- .../ComplexLookupField/ModalComplexLookup.tsx | 8 +++--- .../EditControlPane/EditControlPane.tsx | 4 +-- src/components/Footer/Footer.tsx | 2 +- src/components/Nav/Nav.tsx | 2 +- .../ViewMarcControlPane.tsx | 2 +- .../ViewMarcModal/ViewMarcModal.tsx | 2 +- src/store/marcPreview.ts | 18 ++++++++----- src/store/status.ts | 26 +++++++++++-------- .../common/constants/bundle.constants.mock.ts | 1 + src/test/__mocks__/setupMocks.ts | 1 + src/test/__mocks__/store/index.ts | 2 +- .../common/hooks/useContainerEvents.test.ts | 4 +-- .../common/hooks/useRecordStatus.test.ts | 4 +-- .../components/CommonStatus.test.tsx | 6 ++--- .../MarcPreviewComplexLookup.test.tsx | 4 +-- .../__tests__/components/SaveRecord.test.tsx | 4 +-- .../components/ViewMarcModal.test.tsx | 4 +-- src/views/Edit/Edit.tsx | 2 +- 22 files changed, 59 insertions(+), 48 deletions(-) create mode 100644 src/common/constants/bundle.constants.ts create mode 100644 src/test/__mocks__/common/constants/bundle.constants.mock.ts diff --git a/src/common/constants/bundle.constants.ts b/src/common/constants/bundle.constants.ts new file mode 100644 index 00000000..53d96c17 --- /dev/null +++ b/src/common/constants/bundle.constants.ts @@ -0,0 +1 @@ +export const IS_PROD_MODE = import.meta.env.PROD; \ No newline at end of file diff --git a/src/common/hooks/useComplexLookup.ts b/src/common/hooks/useComplexLookup.ts index bb67b06d..2ed56211 100644 --- a/src/common/hooks/useComplexLookup.ts +++ b/src/common/hooks/useComplexLookup.ts @@ -30,14 +30,14 @@ export const useComplexLookup = ({ const schema = useRecoilValue(state.config.schema); const [selectedEntries, setSelectedEntries] = useRecoilState(state.config.selectedEntries); const { - setData, - resetData: resetMarcPreviewData, + setComplexValue, + resetComplexValue: resetMarcPreviewData, metaData: marcPreviewMetadata, resetMetaData: resetMarcPreviewMetadata, } = useMarcPreviewState(); const resetIsMarcPreviewOpen = useResetRecoilState(state.ui.isMarcPreviewOpen); const { isModalOpen, setIsModalOpen, openModal } = useModalControls(); - const { fetchMarcData } = useMarcData(setData); + const { fetchMarcData } = useMarcData(setComplexValue); const { uuid, linkedEntry } = entry; const linkedField = getLinkedField({ schema, linkedEntry }); diff --git a/src/common/hooks/useMarcData.ts b/src/common/hooks/useMarcData.ts index c530f7c0..059baebe 100644 --- a/src/common/hooks/useMarcData.ts +++ b/src/common/hooks/useMarcData.ts @@ -2,8 +2,8 @@ import { useSetRecoilState } from 'recoil'; import { getMarcRecord } from '@common/api/records.api'; import { StatusType } from '@common/constants/status.constants'; import { UserNotificationFactory } from '@common/services/userNotification'; -import state from '@state'; import { useStatusState } from '@src/store'; +import state from '@state'; export const useMarcData = (setMarcPreviewData: (value: any) => void) => { const setIsLoading = useSetRecoilState(state.loadingState.isLoading); diff --git a/src/components/ComplexLookupField/MarcPreviewComplexLookup.tsx b/src/components/ComplexLookupField/MarcPreviewComplexLookup.tsx index 3761a182..7ef8a8db 100644 --- a/src/components/ComplexLookupField/MarcPreviewComplexLookup.tsx +++ b/src/components/ComplexLookupField/MarcPreviewComplexLookup.tsx @@ -17,7 +17,7 @@ type MarcPreviewComplexLookupProps = { export const MarcPreviewComplexLookup: FC = ({ onClose }) => { const { onAssignRecord } = useSearchContext(); const isMarcPreviewOpen = useRecoilValue(state.ui.isMarcPreviewOpen); - const { data: marcPreviewData, metaData: marcPreviewMetadata } = useMarcPreviewState(); + const { complexValue: marcPreviewData, metaData: marcPreviewMetadata } = useMarcPreviewState(); const renderCloseButton = () => (