From aecd5d1747221d068690efbbb3cb1f46cce77e21 Mon Sep 17 00:00:00 2001 From: Timofey Obraztsov <35554964+timobraz@users.noreply.github.com> Date: Sat, 11 Jan 2025 13:07:24 -0800 Subject: [PATCH] added button to duplicate roadmap (#532) * added button to duplicate roadmap * fix: improved duplicate panel to be more like AA * fix: brought back copy index --- .../pages/RoadmapPage/RoadmapMultiplan.tsx | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/site/src/pages/RoadmapPage/RoadmapMultiplan.tsx b/site/src/pages/RoadmapPage/RoadmapMultiplan.tsx index 362c1431..026a09b2 100644 --- a/site/src/pages/RoadmapPage/RoadmapMultiplan.tsx +++ b/site/src/pages/RoadmapPage/RoadmapMultiplan.tsx @@ -20,6 +20,7 @@ interface RoadmapSelectableItemProps { index: number; clickHandler: () => void; editHandler: () => void; + duplicateHandler: () => void; deleteHandler: () => void; } @@ -28,6 +29,7 @@ const RoadmapSelectableItem: FC = ({ index, clickHandler, editHandler, + duplicateHandler, deleteHandler, }) => { return ( @@ -38,6 +40,9 @@ const RoadmapSelectableItem: FC = ({ + @@ -89,6 +94,24 @@ const RoadmapMultiplan: FC = () => { setEditIdx(-1); }; + const duplicatePlan = (plan: RoadmapPlan) => { + let newName = `${plan.name} (Copy)`; + let counter = 1; + while (allPlans.plans.find((p) => p.name === newName)) { + counter++; + newName = `${plan.name} (Copy ${counter})`; + } + dispatch( + addRoadmapPlan({ + name: newName, + content: JSON.parse(JSON.stringify(plan.content)), + }), + ); + const newIndex = allPlans.plans.length; + setCurrentPlanIndex(newIndex); + dispatch(setPlanIndex(newIndex)); + }; + useEffect(() => { document.title = `${name} | PeterPortal`; }, [name]); @@ -121,6 +144,7 @@ const RoadmapMultiplan: FC = () => { setCurrentPlanIndex(index); }} editHandler={() => setEditIdx(index)} + duplicateHandler={() => duplicatePlan(plan)} deleteHandler={() => setDelIdx(index)} /> ))}