diff --git a/src/pageEditor/hooks/useAddNewModComponent.ts b/src/pageEditor/hooks/useAddNewModComponent.ts index d9151d5496..bcee911b2b 100644 --- a/src/pageEditor/hooks/useAddNewModComponent.ts +++ b/src/pageEditor/hooks/useAddNewModComponent.ts @@ -34,17 +34,16 @@ import { inspectedTab, } from "@/pageEditor/context/connection"; import { getExampleBrickPipeline } from "@/pageEditor/panes/insert/exampleStarterBrickConfigs"; -import { - type StarterBrickType, - StarterBrickTypes, -} from "@/types/starterBrickTypes"; +import { StarterBrickTypes } from "@/types/starterBrickTypes"; import { openSidePanel } from "@/utils/sidePanelUtils"; import { useInsertPane } from "@/pageEditor/panes/insert/InsertPane"; import { type ModMetadata } from "@/types/modComponentTypes"; -import { adapter } from "@/pageEditor/starterBricks/adapter"; import { getUnsavedModMetadataForFormState } from "@/pageEditor/utils"; +import { type ModComponentFormStateAdapter } from "@/pageEditor/starterBricks/modComponentFormStateAdapter"; -export type AddNewModComponent = (starterBrickType: StarterBrickType) => void; +export type AddNewModComponent = ( + adapter: ModComponentFormStateAdapter, +) => void; function useAddNewModComponent(modMetadata?: ModMetadata): AddNewModComponent { const dispatch = useDispatch(); @@ -58,12 +57,11 @@ function useAddNewModComponent(modMetadata?: ModMetadata): AddNewModComponent { ); const getInitialModComponentFormState = useCallback( - async ( - starterBrickType: StarterBrickType, - ): Promise => { - const { selectNativeElement, fromNativeElement } = - adapter(starterBrickType); - + async ({ + starterBrickType, + selectNativeElement, + fromNativeElement, + }: ModComponentFormStateAdapter): Promise => { let element = null; if (selectNativeElement) { setInsertingStarterBrickType(starterBrickType); @@ -91,8 +89,8 @@ function useAddNewModComponent(modMetadata?: ModMetadata): AddNewModComponent { ); return useCallback( - async (starterBrickType: StarterBrickType) => { - const { label, flag, asDraftModComponent } = adapter(starterBrickType); + async (adapter: ModComponentFormStateAdapter) => { + const { starterBrickType, label, flag, asDraftModComponent } = adapter; if (flag && flagOff(flag)) { dispatch(actions.betaError()); @@ -100,8 +98,7 @@ function useAddNewModComponent(modMetadata?: ModMetadata): AddNewModComponent { } try { - const initialFormState = - await getInitialModComponentFormState(starterBrickType); + const initialFormState = await getInitialModComponentFormState(adapter); dispatch(actions.addModComponentFormState(initialFormState)); dispatch(actions.checkActiveModComponentAvailability()); diff --git a/src/pageEditor/modListingPanel/ModListItem.test.tsx b/src/pageEditor/modListingPanel/ModListItem.test.tsx index 658655c2c1..d6126013d8 100644 --- a/src/pageEditor/modListingPanel/ModListItem.test.tsx +++ b/src/pageEditor/modListingPanel/ModListItem.test.tsx @@ -38,14 +38,7 @@ describe("ModListItem", () => { render( - +
test children
@@ -70,14 +63,7 @@ describe("ModListItem", () => { render( - +
test children
@@ -111,14 +97,7 @@ describe("ModListItem", () => { render( - +
test children
diff --git a/src/pageEditor/modListingPanel/actionMenus/ModActionMenu.tsx b/src/pageEditor/modListingPanel/actionMenus/ModActionMenu.tsx index 849e66190c..b05f5b0f0d 100644 --- a/src/pageEditor/modListingPanel/actionMenus/ModActionMenu.tsx +++ b/src/pageEditor/modListingPanel/actionMenus/ModActionMenu.tsx @@ -70,9 +70,9 @@ const ModActionMenu: React.FC<{ modMetadata: ModMetadata }> = ({ const addStarterBrickSubMenu = useMemo( () => modComponentFormStateAdapters.map((adapter) => ({ - title: adapter.label, + title: adapter.flag ? `${adapter.label} (Beta)` : adapter.label, action() { - addNewModComponent(adapter.starterBrickType); + addNewModComponent(adapter); }, icon: , })), diff --git a/src/pageEditor/modals/Modals.tsx b/src/pageEditor/modals/Modals.tsx index 0e698caeba..a0d41746dc 100644 --- a/src/pageEditor/modals/Modals.tsx +++ b/src/pageEditor/modals/Modals.tsx @@ -17,17 +17,13 @@ import AddBrickModal from "@/pageEditor/modals/addBrickModal/AddBrickModal"; import React from "react"; -import AddToModModal from "@/pageEditor/modListingPanel/modals/AddToModModal"; import CreateModModal from "@/pageEditor/modListingPanel/modals/CreateModModal"; import MoveFromModModal from "@/pageEditor/modListingPanel/modals/MoveFromModModal"; -import SaveAsNewModModal from "@/pageEditor/modListingPanel/modals/SaveAsNewModModal"; import SaveDataIntegrityErrorModal from "@/pageEditor/panes/save/SaveDataIntegrityErrorModal"; const Modals: React.FunctionComponent = () => ( <> - - diff --git a/src/pageEditor/store/editor/editorSlice.test.ts b/src/pageEditor/store/editor/editorSlice.test.ts index 7f1975069b..1a1aad050a 100644 --- a/src/pageEditor/store/editor/editorSlice.test.ts +++ b/src/pageEditor/store/editor/editorSlice.test.ts @@ -16,8 +16,8 @@ */ import { - editorSlice, actions, + editorSlice, initialState, persistEditorConfig, } from "@/pageEditor/store/editor/editorSlice"; @@ -49,6 +49,7 @@ import { migrations } from "@/store/editorMigrations"; import { modMetadataFactory } from "@/testUtils/factories/modComponentFactories"; import { setActiveModId } from "./editorSliceHelpers"; import { castDraft } from "immer"; +import { type ModComponentsRootState } from "@/store/modComponents/modComponentTypes"; function getTabState( state: EditorState, @@ -222,11 +223,14 @@ describe("Add/Remove Bricks", () => { ).toBeArrayOfSize(initialIntegrationDependencies.length); }); - test("Can clone a mod compoenent", async () => { + test("Can clone a mod component", async () => { const dispatch = jest.fn(); - const getState: () => EditorRootState = () => ({ editor }); + const getState: () => EditorRootState & ModComponentsRootState = () => ({ + editor, + options: { activatedModComponents: [] }, + }); - await actions.cloneActiveModComponent()(dispatch, getState, undefined); + await actions.duplicateActiveModComponent()(dispatch, getState, undefined); // Dispatch call args (actions) should be: // 1. thunk pending