Feat: Importing data flow files from the list page #9869 (#10446)

### What problem does this PR solve?

Feat: Importing data flow files from the list page #9869

### Type of change


- [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
balibabu
2025-10-09 19:03:29 +08:00
committed by GitHub
parent f04c9e2937
commit f4324e89d9
9 changed files with 90 additions and 41 deletions

View File

@ -1,13 +1,20 @@
import { useToast } from '@/components/hooks/use-toast';
import message from '@/components/ui/message';
import { AgentCategory, DataflowOperator } from '@/constants/agent';
import { FileMimeType } from '@/constants/common';
import { useSetModalState } from '@/hooks/common-hooks';
import { EmptyDsl, useSetAgent } from '@/hooks/use-agent-request';
import { message } from 'antd';
import { Node } from '@xyflow/react';
import isEmpty from 'lodash/isEmpty';
import { useCallback } from 'react';
import { useTranslation } from 'react-i18next';
import { DataflowEmptyDsl } from './hooks/use-create-agent';
import { FormSchemaType } from './upload-agent-dialog/upload-agent-form';
function hasNode(nodes: Node[], operator: DataflowOperator) {
return nodes.some((x) => x.data.label === operator);
}
export const useHandleImportJsonFile = () => {
const {
visible: fileUploadVisible,
@ -32,8 +39,28 @@ export const useHandleImportJsonFile = () => {
try {
const graph = JSON.parse(graphStr);
if (graphStr && !isEmpty(graph) && Array.isArray(graph?.nodes)) {
const dsl = { ...EmptyDsl, graph };
setAgent({ title: name, dsl });
const nodes: Node[] = graph.nodes;
let isAgent = true;
if (
hasNode(nodes, DataflowOperator.Begin) &&
hasNode(nodes, DataflowOperator.Parser)
) {
isAgent = false;
}
const dsl = isAgent
? { ...EmptyDsl, graph }
: { ...DataflowEmptyDsl, graph };
setAgent({
title: name,
dsl,
canvas_category: isAgent
? AgentCategory.AgentCanvas
: AgentCategory.DataflowCanvas,
});
hideFileUploadModal();
} else {
message.error(errorMessage);