From 84b4e32c3485cc4e21410a55943da28c115b3696 Mon Sep 17 00:00:00 2001 From: balibabu Date: Thu, 12 Jun 2025 12:31:57 +0800 Subject: [PATCH] Feat: The value selected in the Select component only displays the icon #3221 (#8209) ### What problem does this PR solve? Feat: The value selected in the Select component only displays the icon #3221 ### Type of change - [x] New Feature (non-breaking change which adds functionality) --- web/.umirc.ts | 1 + web/src/components/ui/select.tsx | 35 ++++++++++-- web/src/pages/agent/constant.tsx | 24 ++++---- .../pages/agent/form/switch-form/index.tsx | 57 +++++++++++-------- 4 files changed, 74 insertions(+), 43 deletions(-) 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 (