2025-05-30 16:02:27 +08:00
|
|
|
import { RAGFlowNodeType } from '@/interfaces/database/flow';
|
|
|
|
|
import { isEmpty } from 'lodash';
|
|
|
|
|
import { useMemo } from 'react';
|
2025-07-02 18:34:21 +08:00
|
|
|
import { initialCodeValues } from '../../constant';
|
2025-05-30 16:02:27 +08:00
|
|
|
|
2025-07-02 18:34:21 +08:00
|
|
|
function convertToArray(args: Record<string, string>) {
|
|
|
|
|
return Object.entries(args).map(([key, value]) => ({
|
|
|
|
|
name: key,
|
|
|
|
|
component_id: value,
|
|
|
|
|
}));
|
|
|
|
|
}
|
2025-05-30 16:02:27 +08:00
|
|
|
|
2025-07-02 18:34:21 +08:00
|
|
|
export function useValues(node?: RAGFlowNodeType) {
|
2025-05-30 16:02:27 +08:00
|
|
|
const values = useMemo(() => {
|
|
|
|
|
const formData = node?.data?.form;
|
|
|
|
|
|
|
|
|
|
if (isEmpty(formData)) {
|
2025-07-02 18:34:21 +08:00
|
|
|
return initialCodeValues;
|
2025-05-30 16:02:27 +08:00
|
|
|
}
|
|
|
|
|
|
2025-07-02 18:34:21 +08:00
|
|
|
return { ...formData, arguments: convertToArray(formData.arguments) };
|
|
|
|
|
}, [node?.data?.form]);
|
2025-05-30 16:02:27 +08:00
|
|
|
|
|
|
|
|
return values;
|
|
|
|
|
}
|