import { IChunkStrategyResponse } from '@/types/knowledge'; import { Alert, Checkbox, Form, FormListFieldData, Input, InputNumber, Radio, RadioChangeEvent } from 'antd'; import { useState } from 'react'; import { useTranslation } from 'react-i18next'; const { TextArea } = Input; type IProps = { strategies: Array; docType: string; field: FormListFieldData; fileName: string; }; /** * render strategies by doc type and file suffix */ export default function StrategyForm({ strategies, docType, fileName, field }: IProps) { const [selectedStrategy, setSelectedStrategy] = useState(); let filleSuffix = ''; if (docType === 'DOCUMENT') { // filter strategy by file suffix const arr = fileName.split('.'); filleSuffix = arr[arr.length - 1]; } const ableStrategies = filleSuffix ? strategies.filter(i => i.suffix.indexOf(filleSuffix) > -1) : strategies; const { t } = useTranslation(); const DEFAULT_STRATEGY = { strategy: 'Automatic', name: t('Automatic'), desc: t('Automatic_desc'), }; function radioChange(e: RadioChangeEvent) { setSelectedStrategy(e.target.value); } function renderStrategyParamForm() { if (!selectedStrategy) { return null; } if (selectedStrategy === DEFAULT_STRATEGY.name) { return

{DEFAULT_STRATEGY.desc}

; } const parameters = ableStrategies?.filter(i => i.strategy === selectedStrategy)[0]?.parameters; if (!parameters || !parameters.length) { return ; } return (
{parameters?.map(param => ( {renderParamByType(param.param_type)} ))}
); } function renderParamByType(type: string) { switch (type) { case 'int': return ; case 'string': return