diff --git a/web/src/pages/data-flow/constant.tsx b/web/src/pages/data-flow/constant.tsx index 402ff364f..30a153f38 100644 --- a/web/src/pages/data-flow/constant.tsx +++ b/web/src/pages/data-flow/constant.tsx @@ -380,7 +380,7 @@ export const initialParserValues = { outputs: {}, parser: [] }; export const initialSplitterValues = { outputs: {}, chunk_token_size: 512 }; -export const initialHierarchicalMergerValues = {}; +export const initialHierarchicalMergerValues = { outputs: {} }; export const CategorizeAnchorPointPositions = [ { top: 1, right: 34 }, diff --git a/web/src/pages/data-flow/form/hierarchical-merger-form/index.tsx b/web/src/pages/data-flow/form/hierarchical-merger-form/index.tsx index f002c4cca..8f92026ad 100644 --- a/web/src/pages/data-flow/form/hierarchical-merger-form/index.tsx +++ b/web/src/pages/data-flow/form/hierarchical-merger-form/index.tsx @@ -1,134 +1,152 @@ -import { FormContainer } from '@/components/form-container'; -import NumberInput from '@/components/originui/number-input'; import { SelectWithSearch } from '@/components/originui/select-with-search'; -import { - Form, - FormControl, - FormField, - FormItem, - FormLabel, - FormMessage, -} from '@/components/ui/form'; -import { useTranslate } from '@/hooks/common-hooks'; +import { RAGFlowFormItem } from '@/components/ragflow-form'; +import { BlockButton, Button } from '@/components/ui/button'; +import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; +import { Form } from '@/components/ui/form'; +import { Input } from '@/components/ui/input'; import { zodResolver } from '@hookform/resolvers/zod'; +import { X } from 'lucide-react'; import { memo } from 'react'; -import { useForm, useFormContext } from 'react-hook-form'; +import { useFieldArray, useForm, useFormContext } from 'react-hook-form'; import { z } from 'zod'; -import { initialChunkerValues } from '../../constant'; +import { initialHierarchicalMergerValues } from '../../constant'; import { useFormValues } from '../../hooks/use-form-values'; import { useWatchFormChange } from '../../hooks/use-watch-form-change'; import { INextOperatorForm } from '../../interface'; -import { GoogleCountryOptions, GoogleLanguageOptions } from '../../options'; import { buildOutputList } from '../../utils/build-output-list'; -import { ApiKeyField } from '../components/api-key-field'; import { FormWrapper } from '../components/form-wrapper'; import { Output } from '../components/output'; -import { QueryVariable } from '../components/query-variable'; -const outputList = buildOutputList(initialChunkerValues.outputs); +const outputList = buildOutputList(initialHierarchicalMergerValues.outputs); -export const GoogleFormPartialSchema = { - api_key: z.string(), - country: z.string(), - language: z.string(), -}; +enum Hierarchy { + H1 = '1', + H2 = '2', + H3 = '3', + H4 = '4', + H5 = '5', +} + +const HierarchyOptions = [ + { label: 'H1', value: Hierarchy.H1 }, + { label: 'H2', value: Hierarchy.H2 }, + { label: 'H3', value: Hierarchy.H3 }, + { label: 'H4', value: Hierarchy.H4 }, + { label: 'H5', value: Hierarchy.H5 }, +]; export const FormSchema = z.object({ - ...GoogleFormPartialSchema, - q: z.string(), - start: z.number(), - num: z.number(), + hierarchy: z.number(), + levels: z.array( + z.object({ + expressions: z.array(z.object({ expression: z.string() })), + }), + ), }); -export function GoogleFormWidgets() { +type RegularExpressionsProps = { + index: number; + parentName: string; + removeParent: (index: number) => void; +}; + +export function RegularExpressions({ + index, + parentName, + removeParent, +}: RegularExpressionsProps) { const form = useFormContext(); - const { t } = useTranslate('flow'); + + const name = `${parentName}.${index}.expressions`; + + const { fields, append, remove } = useFieldArray({ + name: name, + control: form.control, + }); return ( - <> - ( - - {t('country')} - - - - - - )} - /> - ( - - {t('language')} - - - - - - )} - /> - + + + H{index} + + + +
+ {fields.map((field, index) => ( +
+
+ + + +
+ +
+ ))} +
+ append({ expression: '' })} + className="mt-6" + > + Add + +
+
); } const HierarchicalMergerForm = ({ node }: INextOperatorForm) => { - const { t } = useTranslate('flow'); - const defaultValues = useFormValues(initialChunkerValues, node); + const defaultValues = useFormValues(initialHierarchicalMergerValues, node); const form = useForm>({ defaultValues, resolver: zodResolver(FormSchema), }); + const name = 'levels'; + + const { fields, append, remove } = useFieldArray({ + name: name, + control: form.control, + }); + useWatchFormChange(node?.id, form); return (
- - - - - - ( - - {t('flowStart')} - - - - - - )} - /> - ( - - {t('flowNum')} - - - - - - )} - /> - - + + + + {fields.map((field, index) => ( +
+
+ +
+
+ ))} + append({ expressions: [] })}> + Add +
diff --git a/web/src/utils/form.ts b/web/src/utils/form.ts index 002409435..ecb56c424 100644 --- a/web/src/utils/form.ts +++ b/web/src/utils/form.ts @@ -35,7 +35,9 @@ export function buildOptions( ) { if (t) { return Object.values(data).map((val) => ({ - label: t(`${prefix ? prefix + '.' : ''}${val.toLowerCase()}`), + label: t( + `${prefix ? prefix + '.' : ''}${typeof val === 'string' ? val.toLowerCase() : val}`, + ), value: val, })); }