feat: Add custom download node function (#10659)

* add custom download node

* use download node
This commit is contained in:
Cristhian Zanforlin Lousa
2025-11-19 17:29:54 -03:00
committed by GitHub
parent 3388fe3478
commit febb616063
3 changed files with 31 additions and 9 deletions

View File

@ -0,0 +1,12 @@
import { FlowType } from "@/types/flow";
export async function customDownloadNodeJson(NodeFLow: FlowType) {
// Fallback to browser download for web version
const element = document.createElement("a");
const file = new Blob([JSON.stringify(NodeFLow)], {
type: "application/json",
});
element.href = URL.createObjectURL(file);
element.download = `${NodeFLow?.name ?? "node"}.json`;
element.click();
}

View File

@ -258,6 +258,21 @@ const NodeToolbarComponent = memo(
});
}, [data.id, data.node?.documentation]);
const handleDownloadNode = useCallback(async () => {
try {
await downloadNode(flowComponent!);
setSuccessData({
title: `${flowComponent?.name || "Node"} downloaded successfully`,
});
} catch (error) {
console.error("Error downloading node:", error);
setErrorData({
title: "Failed to download node",
list: [error instanceof Error ? error.message : "Unknown error"],
});
}
}, [flowComponent]);
useShortcuts({
showOverrideModal,
showModalAdvanced,
@ -349,7 +364,7 @@ const NodeToolbarComponent = memo(
shareComponent();
break;
case "Download":
downloadNode(flowComponent!);
handleDownloadNode();
break;
case "SaveAll":
addFlow({

View File

@ -27,6 +27,7 @@ import {
getRightHandleId,
} from "@/CustomNodes/utils/get-handle-id";
import { INCOMPLETE_LOOP_ERROR_ALERT } from "@/constants/alerts_constants";
import { customDownloadNodeJson } from "@/customization/utils/custom-download-json";
import { customDownloadFlow } from "@/customization/utils/custom-reactFlowUtils";
import useFlowStore from "@/stores/flowStore";
import getFieldTitle from "../CustomNodes/utils/get-field-title";
@ -1767,14 +1768,8 @@ export function createFlowComponent(
return flowNode;
}
export function downloadNode(NodeFLow: FlowType) {
const element = document.createElement("a");
const file = new Blob([JSON.stringify(NodeFLow)], {
type: "application/json",
});
element.href = URL.createObjectURL(file);
element.download = `${NodeFLow?.name ?? "node"}.json`;
element.click();
export async function downloadNode(NodeFLow: FlowType) {
await customDownloadNodeJson(NodeFLow);
}
export function updateComponentNameAndType(