From 633881c652a156d12f3ac91e48eb265f3129300c Mon Sep 17 00:00:00 2001 From: anovazzi1 Date: Mon, 18 Mar 2024 16:39:24 -0300 Subject: [PATCH 1/2] Add setSuccessData function to handleAddFlow and add duplicate flow functionality --- .../components/menuBar/index.tsx | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/frontend/src/components/headerComponent/components/menuBar/index.tsx b/src/frontend/src/components/headerComponent/components/menuBar/index.tsx index 2cd06f65c..8faf442db 100644 --- a/src/frontend/src/components/headerComponent/components/menuBar/index.tsx +++ b/src/frontend/src/components/headerComponent/components/menuBar/index.tsx @@ -29,6 +29,7 @@ export const MenuBar = ({ const addFlow = useFlowsManagerStore((state) => state.addFlow); const currentFlow = useFlowsManagerStore((state) => state.currentFlow); const setErrorData = useAlertStore((state) => state.setErrorData); + const setSuccessData = useAlertStore((state) => state.setSuccessData); const undo = useFlowsManagerStore((state) => state.undo); const redo = useFlowsManagerStore((state) => state.redo); const saveLoading = useFlowsManagerStore((state) => state.saveLoading); @@ -38,11 +39,22 @@ export const MenuBar = ({ const navigate = useNavigate(); const isBuilding = useFlowStore((state) => state.isBuilding); - function handleAddFlow() { + function handleAddFlow(duplicate?: boolean) { try { - addFlow(true).then((id) => { - navigate("/flow/" + id); - }); + if(duplicate) { + if (!currentFlow) { + throw new Error("No flow to duplicate"); + } + addFlow(true, currentFlow).then((_) => { + setSuccessData({title:"Flow duplicated successfully"}); + }); + } + else + { + addFlow(true).then((id) => { + navigate("/flow/" + id); + }); + } } catch (err) { setErrorData(err as { title: string; list?: Array }); } @@ -88,6 +100,15 @@ export const MenuBar = ({ New + { + handleAddFlow(true); + }} + className="cursor-pointer" + > + + Duplicate + { From a02b2e1776f9eff20eadf939139a08f2cd99afa2 Mon Sep 17 00:00:00 2001 From: anovazzi1 Date: Tue, 19 Mar 2024 18:08:21 -0300 Subject: [PATCH 2/2] Fix flow duplication and navigation bug in MenuBar component --- .../components/headerComponent/components/menuBar/index.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/frontend/src/components/headerComponent/components/menuBar/index.tsx b/src/frontend/src/components/headerComponent/components/menuBar/index.tsx index 8faf442db..eb242bebf 100644 --- a/src/frontend/src/components/headerComponent/components/menuBar/index.tsx +++ b/src/frontend/src/components/headerComponent/components/menuBar/index.tsx @@ -45,8 +45,9 @@ export const MenuBar = ({ if (!currentFlow) { throw new Error("No flow to duplicate"); } - addFlow(true, currentFlow).then((_) => { + addFlow(true, currentFlow).then((id) => { setSuccessData({title:"Flow duplicated successfully"}); + navigate("/flow/" + id); }); } else @@ -74,7 +75,7 @@ export const MenuBar = ({