mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-06 19:38:36 +08:00
### What problem does this PR solve? Feat: Convert the arguments parameter of the code operator to a dictionary #3221 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
26 lines
657 B
TypeScript
26 lines
657 B
TypeScript
import { RAGFlowNodeType } from '@/interfaces/database/flow';
|
|
import { isEmpty } from 'lodash';
|
|
import { useMemo } from 'react';
|
|
import { initialCodeValues } from '../../constant';
|
|
|
|
function convertToArray(args: Record<string, string>) {
|
|
return Object.entries(args).map(([key, value]) => ({
|
|
name: key,
|
|
component_id: value,
|
|
}));
|
|
}
|
|
|
|
export function useValues(node?: RAGFlowNodeType) {
|
|
const values = useMemo(() => {
|
|
const formData = node?.data?.form;
|
|
|
|
if (isEmpty(formData)) {
|
|
return initialCodeValues;
|
|
}
|
|
|
|
return { ...formData, arguments: convertToArray(formData.arguments) };
|
|
}, [node?.data?.form]);
|
|
|
|
return values;
|
|
}
|