From 369a4a59ca10c03ef2866ff61070eff73144b145 Mon Sep 17 00:00:00 2001 From: anovazzi1 Date: Fri, 30 Jun 2023 17:29:41 -0300 Subject: [PATCH] feat(tabsContext.tsx): add support for flow name and description in downloadFlow function to customize downloaded file name and content fix(exportModal/index.tsx): update downloadFlow function calls to include flow name and description parameters fix(types/tabs/index.ts): update downloadFlow function signature to include flow name and description parameters --- src/frontend/src/contexts/tabsContext.tsx | 6 +++--- src/frontend/src/modals/exportModal/index.tsx | 6 +++--- src/frontend/src/types/tabs/index.ts | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/frontend/src/contexts/tabsContext.tsx b/src/frontend/src/contexts/tabsContext.tsx index 6576f9137..a1ad15335 100644 --- a/src/frontend/src/contexts/tabsContext.tsx +++ b/src/frontend/src/contexts/tabsContext.tsx @@ -275,16 +275,16 @@ export function TabsProvider({ children }: { children: ReactNode }) { /** * Downloads the current flow as a JSON file */ - function downloadFlow(flow: FlowType) { + function downloadFlow(flow: FlowType,flowName:string,flowDescription?:string) { // create a data URI with the current flow data const jsonString = `data:text/json;chatset=utf-8,${encodeURIComponent( - JSON.stringify(flow) + JSON.stringify({...flow, name:flowName, description:flowDescription}) )}`; // create a link element and set its properties const link = document.createElement("a"); link.href = jsonString; - link.download = `${flows.find((f) => f.id === tabId).name}.json`; + link.download = `${flowName}.json`; // simulate a click on the link element to trigger the download link.click(); diff --git a/src/frontend/src/modals/exportModal/index.tsx b/src/frontend/src/modals/exportModal/index.tsx index 236c27366..638807350 100644 --- a/src/frontend/src/modals/exportModal/index.tsx +++ b/src/frontend/src/modals/exportModal/index.tsx @@ -23,7 +23,7 @@ export default function ExportModal() { const { closePopUp } = useContext(PopUpContext); const ref = useRef(); const { setErrorData } = useContext(alertContext); - const { flows, tabId, updateFlow, downloadFlow } = useContext(TabsContext); + const { flows, tabId, updateFlow, downloadFlow,saveFlow } = useContext(TabsContext); const [isMaxLength, setIsMaxLength] = useState(false); function setModalOpen(x: boolean) { setOpen(x); @@ -80,9 +80,9 @@ export default function ExportModal() {