From bb62ea25bdbddf72a02144d09ed769bf6981bedb Mon Sep 17 00:00:00 2001 From: Lucas Oliveira Date: Wed, 31 May 2023 12:05:24 -0300 Subject: [PATCH] Fixed copy button on node toolbar --- src/frontend/src/contexts/tabsContext.tsx | 6 ++++++ .../components/nodeToolbarComponent/index.tsx | 16 +++++++++++----- src/frontend/src/pages/FlowPage/index.tsx | 16 +++++++++++----- src/frontend/src/types/tabs/index.ts | 2 ++ 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/frontend/src/contexts/tabsContext.tsx b/src/frontend/src/contexts/tabsContext.tsx index 1d7ad43d5..14880a2db 100644 --- a/src/frontend/src/contexts/tabsContext.tsx +++ b/src/frontend/src/contexts/tabsContext.tsx @@ -35,6 +35,9 @@ const TabsContextInitialValue: TabsContextType = { hardReset: () => {}, disableCopyPaste: false, setDisableCopyPaste: (state: boolean) => {}, + lastCopiedSelection: null, + setLastCopiedSelection: (selection: any) => {}, + getNodeId: () => "", paste: ( selection: { nodes: any; edges: any }, @@ -52,6 +55,7 @@ export function TabsProvider({ children }: { children: ReactNode }) { const [flows, setFlows] = useState>([]); const [id, setId] = useState(uuidv4()); const { templates, reactFlowInstance } = useContext(typesContext); + const [lastCopiedSelection, setLastCopiedSelection] = useState(null); const newNodeId = useRef(uuidv4()); function incrementNodeId() { @@ -379,6 +383,8 @@ export function TabsProvider({ children }: { children: ReactNode }) { return ( { + const { setLastCopiedSelection } = useContext(TabsContext); + const reactFlowInstance = useReactFlow(); return ( <>
diff --git a/src/frontend/src/pages/FlowPage/index.tsx b/src/frontend/src/pages/FlowPage/index.tsx index caaddfe0d..6ab16ab8e 100644 --- a/src/frontend/src/pages/FlowPage/index.tsx +++ b/src/frontend/src/pages/FlowPage/index.tsx @@ -38,20 +38,25 @@ const nodeTypes = { }; export default function FlowPage({ flow }: { flow: FlowType }) { - let { updateFlow, disableCopyPaste, addFlow, getNodeId, paste } = - useContext(TabsContext); + let { + updateFlow, + disableCopyPaste, + addFlow, + getNodeId, + paste, + lastCopiedSelection, + setLastCopiedSelection, + } = useContext(TabsContext); const { types, reactFlowInstance, setReactFlowInstance, templates } = useContext(typesContext); const reactFlowWrapper = useRef(null); - const { undo, redo, canUndo, canRedo, takeSnapshot } = useUndoRedo(); + const { takeSnapshot } = useUndoRedo(); const [position, setPosition] = useState({ x: 0, y: 0 }); const [lastSelection, setLastSelection] = useState(null); - const [lastCopiedSelection, setLastCopiedSelection] = useState(null); - useEffect(() => { // this effect is used to attach the global event handlers @@ -63,6 +68,7 @@ export default function FlowPage({ flow }: { flow: FlowType }) { !disableCopyPaste ) { event.preventDefault(); + console.log(_.cloneDeep(lastSelection)); setLastCopiedSelection(_.cloneDeep(lastSelection)); } if ( diff --git a/src/frontend/src/types/tabs/index.ts b/src/frontend/src/types/tabs/index.ts index f99b33dc0..eb7d3fc6f 100644 --- a/src/frontend/src/types/tabs/index.ts +++ b/src/frontend/src/types/tabs/index.ts @@ -20,6 +20,8 @@ export type TabsContextType = { selection: { nodes: any; edges: any }, position: { x: number; y: number } ) => void; + lastCopiedSelection: { nodes: any; edges: any }; + setLastCopiedSelection: (selection: { nodes: any; edges: any }) => void; }; export type LangFlowState = {