From 31c80204ebddd2b03864185c78587dca00395eee Mon Sep 17 00:00:00 2001 From: Lucas Oliveira Date: Mon, 8 Jan 2024 14:00:33 -0300 Subject: [PATCH] Fix copy paste not being able to paste on other flow --- .../pages/FlowPage/components/PageComponent/index.tsx | 10 +++++----- src/frontend/src/stores/flowStore.ts | 4 ++++ src/frontend/src/types/zustand/flow/index.ts | 5 +++++ 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/frontend/src/pages/FlowPage/components/PageComponent/index.tsx b/src/frontend/src/pages/FlowPage/components/PageComponent/index.tsx index d4b2b8e3b..1d2264947 100644 --- a/src/frontend/src/pages/FlowPage/components/PageComponent/index.tsx +++ b/src/frontend/src/pages/FlowPage/components/PageComponent/index.tsx @@ -43,6 +43,7 @@ import { cn, getRandomName, isWrappedWithClass } from "../../../../utils/utils"; import ConnectionLineComponent from "../ConnectionLineComponent"; import SelectionMenu from "../SelectionMenuComponent"; import ExtraSidebar from "../extraSidebarComponent"; +import { stat } from "fs"; const nodeTypes = { genericNode: GenericNode, @@ -64,11 +65,6 @@ export default function Page({ const setFilterEdge = useTypesStore((state) => state.setFilterEdge); const reactFlowWrapper = useRef(null); - const [lastCopiedSelection, setLastCopiedSelection] = useState<{ - nodes: any; - edges: any; - } | null>(null); - const reactFlowInstance = useFlowStore((state) => state.reactFlowInstance); const setReactFlowInstance = useFlowStore( (state) => state.setReactFlowInstance @@ -86,6 +82,10 @@ export default function Page({ const redo = useFlowsManagerStore((state) => state.redo); const takeSnapshot = useFlowsManagerStore((state) => state.takeSnapshot); const paste = useFlowStore((state) => state.paste); + const lastCopiedSelection = useFlowStore((state) => state.lastCopiedSelection); + const setLastCopiedSelection = useFlowStore( + (state) => state.setLastCopiedSelection + ); const position = useRef({ x: 0, y: 0 }); const [lastSelection, setLastSelection] = diff --git a/src/frontend/src/stores/flowStore.ts b/src/frontend/src/stores/flowStore.ts index 273ee2533..dcdd4e82e 100644 --- a/src/frontend/src/stores/flowStore.ts +++ b/src/frontend/src/stores/flowStore.ts @@ -204,6 +204,10 @@ const useFlowStore = create((set, get) => ({ }); set({ edges: newEdges }); }, + lastCopiedSelection: null, + setLastCopiedSelection: (newSelection) => { + set({ lastCopiedSelection: newSelection }); + }, })); export default useFlowStore; diff --git a/src/frontend/src/types/zustand/flow/index.ts b/src/frontend/src/types/zustand/flow/index.ts index cacc7f909..e278517f2 100644 --- a/src/frontend/src/types/zustand/flow/index.ts +++ b/src/frontend/src/types/zustand/flow/index.ts @@ -24,6 +24,11 @@ export type FlowStoreType = { selection: { nodes: any; edges: any }, position: { x: number; y: number; paneX?: number; paneY?: number } ) => void; + lastCopiedSelection: { nodes: any; edges: any } | null; + setLastCopiedSelection: ( + newSelection: { nodes: any; edges: any } | null + ) => void; isBuilt: boolean; setIsBuilt: (isBuilt: boolean) => void; + };