From 5c6c39eb4981377c33250f4229660069b2615061 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Fri, 9 Jun 2023 15:45:08 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=80=20feat(menuBar):=20create=20a=20ne?= =?UTF-8?q?w=20component=20to=20handle=20the=20menu=20bar=20in=20the=20Mai?= =?UTF-8?q?nPage=20The=20new=20component=20MenuBar=20was=20created=20to=20?= =?UTF-8?q?handle=20the=20menu=20bar=20in=20the=20MainPage.=20It=20contain?= =?UTF-8?q?s=20all=20the=20logic=20and=20UI=20elements=20related=20to=20th?= =?UTF-8?q?e=20menu=20bar.=20The=20component=20receives=20props=20such=20a?= =?UTF-8?q?s=20activeTab,=20setRename,=20rename,=20flows,=20tabIndex,=20an?= =?UTF-8?q?d=20handleSaveFlow.=20The=20handleSaveFlow=20function=20was=20m?= =?UTF-8?q?oved=20from=20the=20MainPage=20component=20to=20the=20MenuBar?= =?UTF-8?q?=20component.=20The=20code=20related=20to=20the=20menu=20bar=20?= =?UTF-8?q?was=20removed=20from=20the=20MainPage=20component=20and=20repla?= =?UTF-8?q?ced=20by=20the=20MenuBar=20component.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MainPage/components/menuBar/index.tsx | 157 ++++++++++++++ src/frontend/src/pages/MainPage/index.tsx | 191 ++---------------- 2 files changed, 173 insertions(+), 175 deletions(-) create mode 100644 src/frontend/src/pages/MainPage/components/menuBar/index.tsx diff --git a/src/frontend/src/pages/MainPage/components/menuBar/index.tsx b/src/frontend/src/pages/MainPage/components/menuBar/index.tsx new file mode 100644 index 000000000..b87ff556a --- /dev/null +++ b/src/frontend/src/pages/MainPage/components/menuBar/index.tsx @@ -0,0 +1,157 @@ +import React, { useContext } from "react"; +import { TabsContext } from "../../../../contexts/tabsContext"; +import { PopUpContext } from "../../../../contexts/popUpContext"; +import { + Menubar, + MenubarContent, + MenubarItem, + MenubarMenu, + MenubarTrigger, + MenubarRadioGroup, + MenubarRadioItem, +} from "../../../../components/ui/menubar"; +import { + ArrowUpTrayIcon, + ArrowDownTrayIcon, + CodeBracketSquareIcon, + CloudArrowUpIcon, + PencilSquareIcon, + PlusIcon, +} from "@heroicons/react/24/outline"; +import RenameLabel from "../../../../components/ui/rename-label"; +import _ from "lodash"; +import ImportModal from "../../../../modals/importModal"; +import ExportModal from "../../../../modals/exportModal"; +import ApiModal from "../../../../modals/ApiModal"; +import { alertContext } from "../../../../contexts/alertContext"; +import { updateFlowInDatabase } from "../../../../controllers/API"; + +const MenuBar = ({ activeTab, setRename, rename, flows, tabIndex }) => { + const { updateFlow, setTabIndex, addFlow } = useContext(TabsContext); + const { setErrorData } = useContext(alertContext); + const { openPopUp } = useContext(PopUpContext); + + function handleSaveFlow(flow) { + try { + updateFlowInDatabase(flow); + // updateFlowStyleInDataBase(flow); + } catch (err) { + setErrorData(err); + } + } + + function handleAddFlow() { + try { + addFlow(); + // saveFlowStyleInDataBase(); + } catch (err) { + setErrorData(err); + } + } + + return ( +
+ ⛓️ + {activeTab === "myflow" && ( +
+ + + + + { + if (value !== "") { + let newFlow = _.cloneDeep(flows[tabIndex]); + newFlow.name = value; + updateFlow(newFlow); + } + }} + rename={rename} + setRename={setRename} + /> + + + + { + openPopUp(); + }} + > + + Import + + { + openPopUp(); + }} + > + + Export + + { + openPopUp(); + }} + > + + Code + + + + + Edit + + { + handleSaveFlow(flows[tabIndex]); + }} + > + + Save + + { + setRename(true); + }} + > + + Rename + + + + + Flows + + { + setTabIndex(parseInt(value)); + }} + > + {flows.map((flow, idx) => { + return ( + + {flow.name} + + ); + })} + + { + handleAddFlow(); + }} + > + + Add Flow + + + + +
+ )} +
+ ); +}; + +export default MenuBar; diff --git a/src/frontend/src/pages/MainPage/index.tsx b/src/frontend/src/pages/MainPage/index.tsx index d5b351ca5..aa3df49a7 100644 --- a/src/frontend/src/pages/MainPage/index.tsx +++ b/src/frontend/src/pages/MainPage/index.tsx @@ -15,61 +15,14 @@ import { alertContext } from "../../contexts/alertContext"; import { darkContext } from "../../contexts/darkContext"; import { PopUpContext } from "../../contexts/popUpContext"; import { typesContext } from "../../contexts/typesContext"; -import { - ArrowDownTrayIcon, - ArrowTopRightOnSquareIcon, - ArrowUpTrayIcon, - ChevronDownIcon, - CodeBracketSquareIcon, - GlobeAltIcon, - PencilSquareIcon, - CloudArrowUpIcon, - PlusCircleIcon, - PlusIcon, - PlusSmallIcon, - TrashIcon, -} from "@heroicons/react/24/outline"; -import { - DropdownMenu, - DropdownMenuContent, - DropdownMenuItem, - DropdownMenuLabel, - DropdownMenuRadioGroup, - DropdownMenuRadioItem, - DropdownMenuSeparator, - DropdownMenuTrigger, -} from "../../components/ui/dropdown-menu"; -import ImportModal from "../../modals/importModal"; -import ExportModal from "../../modals/exportModal"; -import ApiModal from "../../modals/ApiModal"; -import { Separator } from "../../components/ui/separator"; import { Button } from "../../components/ui/button"; import { FaGithub } from "react-icons/fa"; -import { - Card, - CardContent, - CardDescription, - CardFooter, - CardHeader, - CardTitle, -} from "../../components/ui/card"; -import RenameLabel from "../../components/ui/rename-label"; -import _ from "lodash"; -import { Badge } from "../../components/ui/badge"; -import { OpenAiIcon } from "../../icons/OpenAi"; -import { Menu } from "@mui/material"; -import { - Menubar, - MenubarContent, - MenubarItem, - MenubarMenu, - MenubarRadioGroup, - MenubarRadioItem, - MenubarTrigger, -} from "../../components/ui/menubar"; -import { updateFlowInDatabase } from "../../controllers/API"; -import { CardComponent } from "../../components/cardComponent"; +import _ from "lodash"; + +import { updateFlowInDatabase } from "../../controllers/API"; +import { CardComponent } from "./components/cardComponent"; +import { MenuBar } from "./components/menuBar"; export default function HomePage() { const { flows, @@ -81,7 +34,6 @@ export default function HomePage() { downloadFlow, } = useContext(TabsContext); const { openPopUp } = useContext(PopUpContext); - const { updateFlow } = useContext(TabsContext); const { templates } = useContext(typesContext); const AlertWidth = 384; const { dark, setDark } = useContext(darkContext); @@ -96,25 +48,6 @@ export default function HomePage() { } }, [addFlow, flows.length, templates]); - function handleAddFlow() { - try { - addFlow(); - // saveFlowStyleInDataBase(); - } catch (err) { - setErrorData(err); - } - } - - function handleSave(flow) { - // Put your save logic here. - try { - updateFlowInDatabase(flow); - // updateFlowStyleInDataBase(flow); - } catch (err) { - setErrorData(err); - } - } - return ( flows.length !== 0 && ( -
- ⛓️ - {activeTab === "myflow" && ( -
- - - - - { - if (value !== "") { - let newFlow = _.cloneDeep(flows[tabIndex]); - newFlow.name = value; - updateFlow(newFlow); - } - }} - rename={rename} - setRename={setRename} - /> - - - - { - openPopUp(); - }} - > - - Import - - { - openPopUp(); - }} - > - - Export - - { - openPopUp( - - ); - }} - > - - Code - - - - - Edit - - - - Save - - { - setRename(true); - }} - > - - Rename - - - - - Flows - - { - setTabIndex(parseInt(value)); - }} - > - {flows.map((flow, idx) => { - return ( - - {flow.name} - - ); - })} - - { - handleAddFlow(); - }} - > - - Add Flow - - - - -
- )} -
+
Explore My Flows @@ -260,10 +102,9 @@ export default function HomePage() { className="text-gray-600 hover:text-gray-500 dark:text-gray-300 dark:hover:text-gray-200 relative" onClick={(event: React.MouseEvent) => { setNotificationCenter(false); - const top = (event.target as Element).getBoundingClientRect() - .top; - const left = (event.target as Element).getBoundingClientRect() - .left; + const { top, left } = ( + event.target as Element + ).getBoundingClientRect(); openPopUp( <>