From da291f4648cbc33bdf0507f7929609f3e233f9a9 Mon Sep 17 00:00:00 2001 From: Xavier Rutayisire Date: Mon, 22 Jan 2024 10:55:05 +0100 Subject: [PATCH] refactor(changes): Remove changes saga and store --- packages/manager/src/index.ts | 2 +- .../CustomTypeTable/changesPage.tsx | 1 + .../HardDeleteDocumentsDrawer.tsx | 34 +-- .../ReferencesErrorDrawer.tsx | 92 ------ .../SoftDeleteDocumentsDrawer.tsx | 34 +-- .../DeleteDocumentsDrawer/index.tsx | 1 - .../components/SliceMachineDrawer/index.tsx | 10 +- .../lib/models/common/TransactionalPush.ts | 10 - packages/slice-machine/pages/changes.tsx | 95 +++++-- .../features/changes/actions/pushChanges.ts | 66 +++++ .../actions}/trackPushChangesSuccess.ts | 28 +- .../src/modules/loading/types.ts | 1 - .../slice-machine/src/modules/modal/types.ts | 3 - .../src/modules/pushChangesSaga/index.ts | 191 ------------- .../src/modules/useSliceMachineActions.ts | 21 +- .../src/modules/userContext/index.ts | 9 +- packages/slice-machine/src/redux/reducer.ts | 2 - packages/slice-machine/src/redux/saga.ts | 2 - packages/slice-machine/src/redux/type.ts | 2 - .../test/src/modules/pushChangesSaga.test.ts | 261 ------------------ playwright/tests/changes/changes.spec.ts | 10 +- 21 files changed, 193 insertions(+), 682 deletions(-) delete mode 100644 packages/slice-machine/components/DeleteDocumentsDrawer/ReferencesErrorDrawer.tsx delete mode 100644 packages/slice-machine/lib/models/common/TransactionalPush.ts create mode 100644 packages/slice-machine/src/features/changes/actions/pushChanges.ts rename packages/slice-machine/src/{modules/pushChangesSaga => features/changes/actions}/trackPushChangesSuccess.ts (80%) delete mode 100644 packages/slice-machine/src/modules/pushChangesSaga/index.ts delete mode 100644 packages/slice-machine/test/src/modules/pushChangesSaga.test.ts diff --git a/packages/manager/src/index.ts b/packages/manager/src/index.ts index 4851d0e0ab..d5df44543a 100644 --- a/packages/manager/src/index.ts +++ b/packages/manager/src/index.ts @@ -13,7 +13,7 @@ export { createSliceMachineManager } from "./managers/createSliceMachineManager" export { createSliceMachineManagerMiddleware } from "./managers/createSliceMachineManagerMiddleware"; export type { CreateSliceMachineManagerMiddlewareArgs } from "./managers/createSliceMachineManagerMiddleware"; -export type { Environment } from "./managers/prismicRepository/types"; +export type { Environment, Limit } from "./managers/prismicRepository/types"; export type { PrismicAuthManager, diff --git a/packages/slice-machine/components/CustomTypeTable/changesPage.tsx b/packages/slice-machine/components/CustomTypeTable/changesPage.tsx index c0d17609a1..6af2fc36d7 100644 --- a/packages/slice-machine/components/CustomTypeTable/changesPage.tsx +++ b/packages/slice-machine/components/CustomTypeTable/changesPage.tsx @@ -90,6 +90,7 @@ export const CustomTypeTable: React.FC = ({ tabIndex={0} className="disabled" data-cy={`custom-type-${customType.remote.id}`} + key={customType.remote.id} > void; -}> = ({ pushChanges }) => { - const { isDeleteDocumentsDrawerOpen, remoteOnlyCustomTypes, modalData } = - useSelector((store: SliceMachineStoreType) => ({ - isDeleteDocumentsDrawerOpen: isModalOpen( - store, - ModalKeysEnum.HARD_DELETE_DOCUMENTS_DRAWER, - ), + modalData?: Limit; + onClose: () => void; +}> = ({ pushChanges, modalData, onClose }) => { + const { remoteOnlyCustomTypes } = useSelector( + (store: SliceMachineStoreType) => ({ remoteOnlyCustomTypes: selectAllCustomTypes(store).filter(isRemoteOnly), - modalData: store.pushChanges, - })); - - const { closeModals, openToaster } = useSliceMachineActions(); - - if (!isDeleteDocumentsDrawerOpen) return null; + }), + ); - if (modalData?.type !== "HARD") { - openToaster("No change data", ToasterType.ERROR); - return null; - } + if (modalData?.type !== "HARD") return null; const associatedDocumentsCards = modalData.details.customTypes.map( (customTypeDetail) => { @@ -57,14 +45,14 @@ export const HardDeleteDocumentsDrawer: React.FunctionComponent<{ return ( { - closeModals(); pushChanges(false); }} sx={{ diff --git a/packages/slice-machine/components/DeleteDocumentsDrawer/ReferencesErrorDrawer.tsx b/packages/slice-machine/components/DeleteDocumentsDrawer/ReferencesErrorDrawer.tsx deleted file mode 100644 index b44924bc4d..0000000000 --- a/packages/slice-machine/components/DeleteDocumentsDrawer/ReferencesErrorDrawer.tsx +++ /dev/null @@ -1,92 +0,0 @@ -import React from "react"; -import { Text } from "theme-ui"; -import useSliceMachineActions from "@src/modules/useSliceMachineActions"; -import { Button } from "@components/Button"; -import { useSelector } from "react-redux"; -import { SliceMachineStoreType } from "@src/redux/type"; -import { ModalKeysEnum } from "@src/modules/modal/types"; -import { isModalOpen } from "@src/modules/modal"; -import { getModelId, hasLocal } from "@lib/models/common/ModelData"; -import { CustomTypesReferencesCard } from "./AssociatedDocumentsCard"; -import { ToasterType } from "@src/modules/toaster"; -import { selectAllCustomTypes } from "@src/modules/availableCustomTypes"; -import { SliceMachineDrawerUI } from "@components/SliceMachineDrawer"; - -export const ReferencesErrorDrawer: React.FunctionComponent<{ - pushChanges: (confirmDeleteDocuments: boolean) => void; -}> = ({ pushChanges }) => { - const { isOpen, modalData, localCustomTypes } = useSelector( - (store: SliceMachineStoreType) => ({ - isOpen: isModalOpen(store, ModalKeysEnum.REFERENCES_MISSING_DRAWER), - localCustomTypes: selectAllCustomTypes(store).filter(hasLocal), - modalData: store.pushChanges, - }), - ); - const { closeModals, openToaster } = useSliceMachineActions(); - - if (!isOpen) return null; - - if (modalData?.details === undefined) { - openToaster("No change data", ToasterType.ERROR); - return null; - } - - const hasMoreThanOne = modalData?.details.customTypes.length > 1; - - const associatedDocumentsCards = modalData.details.customTypes.map( - (customTypeDetail) => { - const customType = localCustomTypes.find( - (customType) => getModelId(customType) === customTypeDetail.id, - ); - if (customType === undefined) return null; - - return ( - - ); - }, - ); - - return ( - -