fix: Improve flow export error handling and validation (#8943)

*  (exportModal/index.tsx): Refactor onSubmit function to improve flow export functionality and error handling
♻️ (reactflowUtils.ts): Refactor downloadFlow function to return a Promise and improve error handling

* 📝 (exportModal/index.tsx): remove unnecessary comment about handling error in export flow to improve code readability

* 🐛 (exportModal/index.tsx): remove unnecessary filePath variable and simplify logic for exporting flows
💡 (exportModal/index.tsx): refactor code to improve readability and remove redundant code for exporting flows
This commit is contained in:
Cristhian Zanforlin Lousa 2025-07-09 09:57:02 -03:00 committed by GitHub
commit eb69cddc1c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 46 additions and 37 deletions

View file

@ -53,46 +53,54 @@ const ExportModal = forwardRef(
size="smaller-h-full"
open={open}
setOpen={setOpen}
onSubmit={() => {
if (checked) {
downloadFlow(
{
id: currentFlow!.id,
data: currentFlow!.data!,
onSubmit={async () => {
try {
if (checked) {
await downloadFlow(
{
id: currentFlow!.id,
data: currentFlow!.data!,
description,
name,
last_tested_version: version,
endpoint_name: currentFlow!.endpoint_name,
is_component: false,
tags: currentFlow!.tags,
},
name!,
description,
name,
last_tested_version: version,
endpoint_name: currentFlow!.endpoint_name,
is_component: false,
tags: currentFlow!.tags,
},
name!,
description,
);
setNoticeData({
title: API_WARNING_NOTICE_ALERT,
});
} else
downloadFlow(
removeApiKeys({
id: currentFlow!.id,
data: currentFlow!.data!,
);
setNoticeData({
title: API_WARNING_NOTICE_ALERT,
});
setOpen(false);
track("Flow Exported", { flowId: currentFlow!.id });
} else {
await downloadFlow(
removeApiKeys({
id: currentFlow!.id,
data: currentFlow!.data!,
description,
name,
last_tested_version: version,
endpoint_name: currentFlow!.endpoint_name,
is_component: false,
tags: currentFlow!.tags,
}),
name!,
description,
name,
last_tested_version: version,
endpoint_name: currentFlow!.endpoint_name,
is_component: false,
tags: currentFlow!.tags,
}),
name!,
description,
).then(() => {
);
setSuccessData({
title: "Flow exported successfully",
});
});
setOpen(false);
track("Flow Exported", { flowId: currentFlow!.id });
setOpen(false);
track("Flow Exported", { flowId: currentFlow!.id });
}
} catch (error) {
console.error("Error exporting flow:", error);
}
}}
>
<BaseModal.Trigger asChild>{props.children ?? <></>}</BaseModal.Trigger>

View file

@ -1904,7 +1904,7 @@ export async function downloadFlow(
flow: FlowType,
flowName: string,
flowDescription?: string,
) {
): Promise<string | undefined | void> {
try {
const clonedFlow = cloneDeep(flow);
@ -1919,9 +1919,10 @@ export async function downloadFlow(
const sortedData = sortJsonStructure(flowData);
const sortedJsonString = JSON.stringify(sortedData, null, 2);
customDownloadFlow(flow, sortedJsonString, flowName);
return await customDownloadFlow(flow, sortedJsonString, flowName);
} catch (error) {
console.error("Error downloading flow:", error);
throw error;
}
}