From 405f74bef99148ffd751f8080f4dda7f954ed5e3 Mon Sep 17 00:00:00 2001 From: cristhianzl Date: Thu, 19 Oct 2023 21:27:29 -0300 Subject: [PATCH] adding confirmation modal and save flow integratio --- src/frontend/src/controllers/API/index.ts | 4 +- .../extraSidebarComponent/index.tsx | 58 +++++++++++++++++-- src/frontend/src/style/applies.css | 2 +- src/frontend/src/types/components/index.ts | 2 +- 4 files changed, 57 insertions(+), 9 deletions(-) diff --git a/src/frontend/src/controllers/API/index.ts b/src/frontend/src/controllers/API/index.ts index c417c681d..92006340d 100644 --- a/src/frontend/src/controllers/API/index.ts +++ b/src/frontend/src/controllers/API/index.ts @@ -547,9 +547,9 @@ export async function addApiKeyStore(key: string) { * @throws Will throw an error if saving fails. */ export async function saveFlowStore(newFlow: { - name: string; + name?: string; data: ReactFlowJsonObject | null; - description: string; + description?: string; style?: FlowStyleType; is_component?: boolean; }): Promise { diff --git a/src/frontend/src/pages/FlowPage/components/extraSidebarComponent/index.tsx b/src/frontend/src/pages/FlowPage/components/extraSidebarComponent/index.tsx index 8dd33103c..ede799b52 100644 --- a/src/frontend/src/pages/FlowPage/components/extraSidebarComponent/index.tsx +++ b/src/frontend/src/pages/FlowPage/components/extraSidebarComponent/index.tsx @@ -1,5 +1,6 @@ import { cloneDeep } from "lodash"; import { useContext, useEffect, useState } from "react"; +import { ReactFlowJsonObject } from "reactflow"; import ShadTooltip from "../../../../components/ShadTooltipComponent"; import IconComponent from "../../../../components/genericIconComponent"; import { Input } from "../../../../components/ui/input"; @@ -7,7 +8,9 @@ import { Separator } from "../../../../components/ui/separator"; import { alertContext } from "../../../../contexts/alertContext"; import { TabsContext } from "../../../../contexts/tabsContext"; import { typesContext } from "../../../../contexts/typesContext"; +import { saveFlowStore } from "../../../../controllers/API"; import ApiModal from "../../../../modals/ApiModal"; +import ConfirmationModal from "../../../../modals/ConfirmationModal"; import ExportModal from "../../../../modals/exportModal"; import { APIClassType, APIObjectType } from "../../../../types/api"; import { @@ -97,6 +100,29 @@ export default function ExtraSidebar(): JSX.Element { } }, [getFilterEdge, data]); + const handleShareFlow = () => { + const reactFlow = flow!.data as ReactFlowJsonObject; + const saveFlow = { + data: { + ...reactFlow, + }, + is_component: false, + }; + saveFlowStore(saveFlow).then( + () => { + setSuccessData({ + title: "Flow shared successfully", + }); + }, + (err) => { + setErrorData({ + title: "Error sharing flow", + list: [err["response"]["data"]["detail"]], + }); + } + ); + }; + useEffect(() => { if (getFilterEdge?.length > 0) { setFilterData((_) => { @@ -145,7 +171,10 @@ export default function ExtraSidebar(): JSX.Element { uploadFlow(false); }} > - + @@ -153,10 +182,7 @@ export default function ExtraSidebar(): JSX.Element {
- +
@@ -202,6 +228,28 @@ export default function ExtraSidebar(): JSX.Element { + +
+ { + handleShareFlow(); + }} + titleHeader="" + cancelText="Cancel" + > + +
+ +
+
+
+
diff --git a/src/frontend/src/style/applies.css b/src/frontend/src/style/applies.css index ab4a40d2e..f0384367d 100644 --- a/src/frontend/src/style/applies.css +++ b/src/frontend/src/style/applies.css @@ -66,7 +66,7 @@ @apply fixed right-4; } .side-bar-arrangement { - @apply flex h-full w-52 flex-col overflow-hidden border-r scrollbar-hide; + @apply flex h-full w-[14.5rem] flex-col overflow-hidden border-r scrollbar-hide; } .side-bar-search-div-placement { @apply relative mx-auto mb-2 mt-2 flex items-center; diff --git a/src/frontend/src/types/components/index.ts b/src/frontend/src/types/components/index.ts index 5861b53ca..95c1fd6a5 100644 --- a/src/frontend/src/types/components/index.ts +++ b/src/frontend/src/types/components/index.ts @@ -283,7 +283,7 @@ export type ConfirmationModalType = { confirmationText: string; children: ReactElement; icon: string; - data: any; + data?: any; index: number; onConfirm: (index, data) => void; };