diff --git a/web/.umirc.ts b/web/.umirc.ts index cae37519d..dab80fcb2 100644 --- a/web/.umirc.ts +++ b/web/.umirc.ts @@ -16,6 +16,7 @@ export default defineConfig({ icons: {}, hash: true, favicons: ['/logo.svg'], + headScripts: [{ src: '/iconfont.js', defer: true }], clickToComponent: {}, history: { type: 'browser', diff --git a/web/src/components/ui/select.tsx b/web/src/components/ui/select.tsx index 834371529..9010c896f 100644 --- a/web/src/components/ui/select.tsx +++ b/web/src/components/ui/select.tsx @@ -134,17 +134,16 @@ const SelectItem = React.forwardRef< - + - {children} )); @@ -179,6 +178,7 @@ export type RAGFlowSelectOptionType = { label: React.ReactNode; value: string; disabled?: boolean; + icon?: React.ReactNode; }; export type RAGFlowSelectGroupOptionType = { @@ -193,6 +193,7 @@ export type RAGFlowSelectProps = Partial & { placeholder?: React.ReactNode; contentProps?: React.ComponentPropsWithoutRef; triggerClassName?: string; + onlyShowSelectedIcon?: boolean; } & SelectPrimitive.SelectProps; /** @@ -225,6 +226,7 @@ export const RAGFlowSelect = forwardRef< contentProps = {}, defaultValue, triggerClassName, + onlyShowSelectedIcon = false, }, ref, ) { @@ -257,6 +259,24 @@ export const RAGFlowSelect = forwardRef< }); }, [initialValue]); + // The value selected in the drop-down box only displays the icon + const label = React.useMemo(() => { + let nextOptions = options; + if (options.some((x) => !('value' in x))) { + nextOptions = (options as RAGFlowSelectGroupOptionType[]).reduce< + RAGFlowSelectOptionType[] + >((pre, cur) => { + return pre.concat(cur?.options ?? []); + }, []); + } + + const option = (nextOptions as RAGFlowSelectOptionType[]).find( + (x) => x.value === value, + ); + + return onlyShowSelectedIcon ? option?.icon : option?.label; + }, [onlyShowSelectedIcon, options, value]); + return ( @@ -267,7 +287,7 @@ export const RAGFlowSelect = forwardRef< ref={ref} className={triggerClassName} > - + {label} @@ -279,14 +299,17 @@ export const RAGFlowSelect = forwardRef< key={o.value} disabled={o.disabled} > - {o.label} + + {o.icon} + {o.label} + ); } return ( - {o.label} + {o.label} {o.options.map((x) => ( {x.label} diff --git a/web/src/pages/agent/constant.tsx b/web/src/pages/agent/constant.tsx index 2776b0c22..4f02a8b36 100644 --- a/web/src/pages/agent/constant.tsx +++ b/web/src/pages/agent/constant.tsx @@ -3003,18 +3003,18 @@ export const ExeSQLOptions = ['mysql', 'postgresql', 'mariadb', 'mssql'].map( export const SwitchElseTo = 'end_cpn_id'; export const SwitchOperatorOptions = [ - { value: '=', label: 'equal' }, - { value: '≠', label: 'notEqual' }, - { value: '>', label: 'gt' }, - { value: '≥', label: 'ge' }, - { value: '<', label: 'lt' }, - { value: '≤', label: 'le' }, - { value: 'contains', label: 'contains' }, - { value: 'not contains', label: 'notContains' }, - { value: 'start with', label: 'startWith' }, - { value: 'end with', label: 'endWith' }, - { value: 'empty', label: 'empty' }, - { value: 'not empty', label: 'notEmpty' }, + { value: '=', label: 'equal', icon: 'equal' }, + { value: '≠', label: 'notEqual', icon: 'not-equals' }, + { value: '>', label: 'gt', icon: 'Less' }, + { value: '≥', label: 'ge', icon: 'Greater-or-equal' }, + { value: '<', label: 'lt', icon: 'Less' }, + { value: '≤', label: 'le', icon: 'less-or-equal' }, + { value: 'contains', label: 'contains', icon: 'Contains' }, + { value: 'not contains', label: 'notContains', icon: 'not-contains' }, + { value: 'start with', label: 'startWith', icon: 'list-start' }, + { value: 'end with', label: 'endWith', icon: 'list-end' }, + // { value: 'empty', label: 'empty', icon: '' }, + // { value: 'not empty', label: 'notEmpty', icon: '' }, ]; export const SwitchLogicOperatorOptions = ['and', 'or']; diff --git a/web/src/pages/agent/form/switch-form/index.tsx b/web/src/pages/agent/form/switch-form/index.tsx index 35306375b..e8d6af692 100644 --- a/web/src/pages/agent/form/switch-form/index.tsx +++ b/web/src/pages/agent/form/switch-form/index.tsx @@ -1,4 +1,5 @@ import { FormContainer } from '@/components/form-container'; +import { IconFont } from '@/components/icon-font'; import { BlockButton, Button } from '@/components/ui/button'; import { Card, CardContent } from '@/components/ui/card'; import { @@ -9,8 +10,10 @@ import { FormMessage, } from '@/components/ui/form'; import { RAGFlowSelect } from '@/components/ui/select'; +import { Separator } from '@/components/ui/separator'; import { Textarea } from '@/components/ui/textarea'; import { ISwitchForm } from '@/interfaces/database/flow'; +import { cn } from '@/lib/utils'; import { zodResolver } from '@hookform/resolvers/zod'; import { X } from 'lucide-react'; import { useMemo } from 'react'; @@ -49,6 +52,12 @@ function ConditionCards({ name: parentName, node }: ConditionCardsProps) { const switchOperatorOptions = useMemo(() => { return SwitchOperatorOptions.map((x) => ({ value: x.value, + icon: ( + ' })} + > + ), label: t(`flow.switchOperatorOptions.${x.label}`), })); }, [t]); @@ -66,7 +75,7 @@ function ConditionCards({ name: parentName, node }: ConditionCardsProps) { return ( - + - - - - )} - /> - ( - - - )} /> + + + ( + + + + + + + )} + /> + { return conditions?.filter((x) => !!x).map((x) => x?.to) ?? []; }; - const switchOperatorOptions = useMemo(() => { - return SwitchOperatorOptions.map((x) => ({ - value: x.value, - label: t(`flow.switchOperatorOptions.${x.label}`), - })); - }, [t]); - const switchLogicOperatorOptions = useMemo(() => { return SwitchLogicOperatorOptions.map((x) => ({ value: x,