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
This commit is contained in:
anovazzi1 2023-06-30 17:29:41 -03:00
commit 369a4a59ca
3 changed files with 7 additions and 7 deletions

View file

@ -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();

View file

@ -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() {
<DialogFooter>
<Button
onClick={() => {
if (checked) downloadFlow(flows.find((f) => f.id === tabId));
if (checked) downloadFlow(flows.find((f) => f.id === tabId),name,description);
else
downloadFlow(removeApiKeys(flows.find((f) => f.id === tabId)));
downloadFlow(removeApiKeys(flows.find((f) => f.id === tabId)),name,description);
closePopUp();
}}

View file

@ -11,7 +11,7 @@ export type TabsContextType = {
addFlow: (flowData?: FlowType, newProject?: boolean) => Promise<String>;
updateFlow: (newFlow: FlowType) => void;
incrementNodeId: () => string;
downloadFlow: (flow: FlowType) => void;
downloadFlow: (flow: FlowType,flowName:string,flowDescription?:string) => void;
downloadFlows: () => void;
uploadFlows: () => void;
uploadFlow: (newFlow?: boolean) => void;