diff --git a/web/src/components/cross-language-form-field.tsx b/web/src/components/cross-language-form-field.tsx index 9f7dc9a05..3322324e1 100644 --- a/web/src/components/cross-language-form-field.tsx +++ b/web/src/components/cross-language-form-field.tsx @@ -30,11 +30,13 @@ const options = Languages.map((x) => ({ type CrossLanguageItemProps = { name?: string; vertical?: boolean; + label?: string; }; export const CrossLanguageFormField = ({ name = 'prompt_config.cross_languages', vertical = true, + label, }: CrossLanguageItemProps) => { const { t } = useTranslation(); const form = useFormContext(); @@ -53,7 +55,7 @@ export const CrossLanguageFormField = ({ })} > - {t('chat.crossLanguage')} + {label || t('chat.crossLanguage')} { - if (typeof field.value === 'undefined') { - // default value set - form.setValue( - 'parser_config.layout_recognize', - form.formState.defaultValues?.parser_config?.layout_recognize ?? - 'DeepDOC', - ); - } return ( - -
+ +
{t('layoutRecognize')} -
+
-
+
diff --git a/web/src/pages/data-flow/form/parser-form/common-form-fields.tsx b/web/src/pages/data-flow/form/parser-form/common-form-fields.tsx index 094f82014..7e36f78c1 100644 --- a/web/src/pages/data-flow/form/parser-form/common-form-fields.tsx +++ b/web/src/pages/data-flow/form/parser-form/common-form-fields.tsx @@ -1,32 +1,53 @@ +import { LayoutRecognizeFormField } from '@/components/layout-recognize-form-field'; import { LLMFormField } from '@/components/llm-setting-items/llm-form-field'; -import { SelectWithSearch } from '@/components/originui/select-with-search'; +import { + SelectWithSearch, + SelectWithSearchFlagOptionType, +} from '@/components/originui/select-with-search'; import { RAGFlowFormItem } from '@/components/ragflow-form'; +import { buildOptions } from '@/utils/form'; +import { FileType } from '../../constant'; +import { OutputFormatMap } from './constant'; import { CommonProps } from './interface'; import { buildFieldNameWithPrefix } from './utils'; -export function LanguageFormField({ prefix }: CommonProps) { - return ( - - - - ); +function buildOutputOptionsFormatMap() { + return Object.entries(OutputFormatMap).reduce< + Record + >((pre, [key, value]) => { + pre[key] = buildOptions(value); + return pre; + }, {}); } -export function OutputFormatFormField({ prefix }: CommonProps) { +export type OutputFormatFormFieldProps = CommonProps & { + fileType: FileType; +}; + +export function OutputFormatFormField({ + prefix, + fileType, +}: OutputFormatFormFieldProps) { return ( - + ); } export function ParserMethodFormField({ prefix }: CommonProps) { + return ( + + ); + return ( - + ); } diff --git a/web/src/pages/data-flow/form/parser-form/image-form-fields.tsx b/web/src/pages/data-flow/form/parser-form/image-form-fields.tsx index 6c8479269..987b4f0be 100644 --- a/web/src/pages/data-flow/form/parser-form/image-form-fields.tsx +++ b/web/src/pages/data-flow/form/parser-form/image-form-fields.tsx @@ -1,3 +1,4 @@ +import { FileType } from '../../constant'; import { LargeModelFormField, OutputFormatFormField, @@ -11,7 +12,10 @@ export function ImageFormFields({ prefix }: CommonProps) { {/* Multimodal Model */} - + ); } diff --git a/web/src/pages/data-flow/form/parser-form/index.tsx b/web/src/pages/data-flow/form/parser-form/index.tsx index 732564936..ec93f0fbd 100644 --- a/web/src/pages/data-flow/form/parser-form/index.tsx +++ b/web/src/pages/data-flow/form/parser-form/index.tsx @@ -1,13 +1,20 @@ -import { FormContainer } from '@/components/form-container'; import { SelectWithSearch } from '@/components/originui/select-with-search'; import { RAGFlowFormItem } from '@/components/ragflow-form'; import { BlockButton, Button } from '@/components/ui/button'; import { Form } from '@/components/ui/form'; +import { Separator } from '@/components/ui/separator'; +import { cn } from '@/lib/utils'; import { buildOptions } from '@/utils/form'; import { zodResolver } from '@hookform/resolvers/zod'; +import { useHover } from 'ahooks'; import { Trash2 } from 'lucide-react'; -import { memo, useCallback } from 'react'; -import { useFieldArray, useForm } from 'react-hook-form'; +import { memo, useCallback, useRef } from 'react'; +import { + UseFieldArrayRemove, + useFieldArray, + useForm, + useFormContext, +} from 'react-hook-form'; import { z } from 'zod'; import { FileType, initialParserValues } from '../../constant'; import { useFormValues } from '../../hooks/use-form-values'; @@ -34,6 +41,51 @@ const FileFormatWidgetMap = { [FileType.Image]: ImageFormFields, }; +type ParserItemProps = { + name: string; + index: number; + fieldLength: number; + remove: UseFieldArrayRemove; +}; + +function ParserItem({ name, index, fieldLength, remove }: ParserItemProps) { + const form = useFormContext(); + const ref = useRef(null); + const isHovering = useHover(ref); + + const prefix = `${name}.${index}`; + const fileFormat = form.getValues(`${name}.${index}.fileFormat`); + + const Widget = + fileFormat && fileFormat in FileFormatWidgetMap + ? FileFormatWidgetMap[fileFormat as keyof typeof FileFormatWidgetMap] + : OutputFormatFormField; + return ( +
+
+ Parser {index} + {index > 0 && ( + + )} +
+ + + + + {index < fieldLength - 1 && } +
+ ); +} + export const FormSchema = z.object({ parser: z.array( z.object({ @@ -67,35 +119,22 @@ const ParserForm = ({ node }: INextOperatorForm) => { return (
- {fields.map((field, index) => { - const prefix = `${name}.${index}`; - const fileFormat = form.getValues(`${name}.${index}.fileFormat`); - - const Widget = - fileFormat && fileFormat in FileFormatWidgetMap - ? FileFormatWidgetMap[ - fileFormat as keyof typeof FileFormatWidgetMap - ] - : OutputFormatFormField; - return ( - -
- Parser {index} - -
- - - - -
- ); - })} - Add Parser + + {fields.map((field, index) => { + return ( + + ); + })} + + Add Parser + +
diff --git a/web/src/pages/data-flow/form/parser-form/pdf-form-fields.tsx b/web/src/pages/data-flow/form/parser-form/pdf-form-fields.tsx index 0b67ed7a7..97fb7aaca 100644 --- a/web/src/pages/data-flow/form/parser-form/pdf-form-fields.tsx +++ b/web/src/pages/data-flow/form/parser-form/pdf-form-fields.tsx @@ -1,10 +1,12 @@ +import { CrossLanguageFormField } from '@/components/cross-language-form-field'; +import { FileType } from '../../constant'; import { - LanguageFormField, LargeModelFormField, OutputFormatFormField, ParserMethodFormField, } from './common-form-fields'; import { CommonProps } from './interface'; +import { buildFieldNameWithPrefix } from './utils'; export function PdfFormFields({ prefix }: CommonProps) { return ( @@ -12,8 +14,14 @@ export function PdfFormFields({ prefix }: CommonProps) { {/* Multimodal Model */} - - + + ); } diff --git a/web/src/pages/data-flow/form/parser-form/video-form-fields.tsx b/web/src/pages/data-flow/form/parser-form/video-form-fields.tsx index 619336143..88e07cacb 100644 --- a/web/src/pages/data-flow/form/parser-form/video-form-fields.tsx +++ b/web/src/pages/data-flow/form/parser-form/video-form-fields.tsx @@ -1,15 +1,21 @@ import { LargeModelFormField, OutputFormatFormField, + OutputFormatFormFieldProps, } from './common-form-fields'; -import { CommonProps } from './interface'; -export function VideoFormFields({ prefix }: CommonProps) { +export function VideoFormFields({ + prefix, + fileType, +}: OutputFormatFormFieldProps) { return ( <> {/* Multimodal Model */} - + ); } diff --git a/web/tailwind.config.js b/web/tailwind.config.js index c04ca939d..34b888a54 100644 --- a/web/tailwind.config.js +++ b/web/tailwind.config.js @@ -80,7 +80,10 @@ module.exports = { 'bg-accent': 'var(--bg-accent)', 'state-success': 'var(--state-success)', 'state-warning': 'var(--state-warning)', - 'state-error': 'var(--state-error)', + 'state-error': { + DEFAULT: 'rgb(var(--state-error) / )', + 5: 'rgba(var(--state-error) / 0.05)', // 5% + }, 'team-group': 'var(--team-group)', 'team-member': 'var(--team-member)', 'team-department': 'var(--team-department)', diff --git a/web/tailwind.css b/web/tailwind.css index 9df292555..67a188cfd 100644 --- a/web/tailwind.css +++ b/web/tailwind.css @@ -119,7 +119,7 @@ --state-success: #3ba05c; --state-warning: #faad14; - --state-error: #d8494b; + --state-error: 216 73 75; --team-group: #5ab77e; --team-member: #5c96c8;