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:
parent
88803e31d2
commit
eb69cddc1c
2 changed files with 46 additions and 37 deletions
|
|
@ -53,46 +53,54 @@ const ExportModal = forwardRef(
|
||||||
size="smaller-h-full"
|
size="smaller-h-full"
|
||||||
open={open}
|
open={open}
|
||||||
setOpen={setOpen}
|
setOpen={setOpen}
|
||||||
onSubmit={() => {
|
onSubmit={async () => {
|
||||||
if (checked) {
|
try {
|
||||||
downloadFlow(
|
if (checked) {
|
||||||
{
|
await downloadFlow(
|
||||||
id: currentFlow!.id,
|
{
|
||||||
data: currentFlow!.data!,
|
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,
|
description,
|
||||||
name,
|
);
|
||||||
last_tested_version: version,
|
|
||||||
endpoint_name: currentFlow!.endpoint_name,
|
setNoticeData({
|
||||||
is_component: false,
|
title: API_WARNING_NOTICE_ALERT,
|
||||||
tags: currentFlow!.tags,
|
});
|
||||||
},
|
setOpen(false);
|
||||||
name!,
|
track("Flow Exported", { flowId: currentFlow!.id });
|
||||||
description,
|
} else {
|
||||||
);
|
await downloadFlow(
|
||||||
setNoticeData({
|
removeApiKeys({
|
||||||
title: API_WARNING_NOTICE_ALERT,
|
id: currentFlow!.id,
|
||||||
});
|
data: currentFlow!.data!,
|
||||||
} else
|
description,
|
||||||
downloadFlow(
|
name,
|
||||||
removeApiKeys({
|
last_tested_version: version,
|
||||||
id: currentFlow!.id,
|
endpoint_name: currentFlow!.endpoint_name,
|
||||||
data: currentFlow!.data!,
|
is_component: false,
|
||||||
|
tags: currentFlow!.tags,
|
||||||
|
}),
|
||||||
|
name!,
|
||||||
description,
|
description,
|
||||||
name,
|
);
|
||||||
last_tested_version: version,
|
|
||||||
endpoint_name: currentFlow!.endpoint_name,
|
|
||||||
is_component: false,
|
|
||||||
tags: currentFlow!.tags,
|
|
||||||
}),
|
|
||||||
name!,
|
|
||||||
description,
|
|
||||||
).then(() => {
|
|
||||||
setSuccessData({
|
setSuccessData({
|
||||||
title: "Flow exported successfully",
|
title: "Flow exported successfully",
|
||||||
});
|
});
|
||||||
});
|
setOpen(false);
|
||||||
setOpen(false);
|
track("Flow Exported", { flowId: currentFlow!.id });
|
||||||
track("Flow Exported", { flowId: currentFlow!.id });
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error exporting flow:", error);
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<BaseModal.Trigger asChild>{props.children ?? <></>}</BaseModal.Trigger>
|
<BaseModal.Trigger asChild>{props.children ?? <></>}</BaseModal.Trigger>
|
||||||
|
|
|
||||||
|
|
@ -1904,7 +1904,7 @@ export async function downloadFlow(
|
||||||
flow: FlowType,
|
flow: FlowType,
|
||||||
flowName: string,
|
flowName: string,
|
||||||
flowDescription?: string,
|
flowDescription?: string,
|
||||||
) {
|
): Promise<string | undefined | void> {
|
||||||
try {
|
try {
|
||||||
const clonedFlow = cloneDeep(flow);
|
const clonedFlow = cloneDeep(flow);
|
||||||
|
|
||||||
|
|
@ -1919,9 +1919,10 @@ export async function downloadFlow(
|
||||||
const sortedData = sortJsonStructure(flowData);
|
const sortedData = sortJsonStructure(flowData);
|
||||||
const sortedJsonString = JSON.stringify(sortedData, null, 2);
|
const sortedJsonString = JSON.stringify(sortedData, null, 2);
|
||||||
|
|
||||||
customDownloadFlow(flow, sortedJsonString, flowName);
|
return await customDownloadFlow(flow, sortedJsonString, flowName);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error downloading flow:", error);
|
console.error("Error downloading flow:", error);
|
||||||
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue