From c96dc535343f5960bc7a3d118d930e6a6a3a2fcd Mon Sep 17 00:00:00 2001 From: zhaoying Date: Fri, 17 Apr 2026 10:07:45 +0800 Subject: [PATCH] fix(web): model options update --- web/src/components/ModelSelect/index.tsx | 18 ++++++------- .../Properties/ModelConfig/index.tsx | 25 +++++++++++++------ 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/web/src/components/ModelSelect/index.tsx b/web/src/components/ModelSelect/index.tsx index 0b4f671e..e89b8eeb 100644 --- a/web/src/components/ModelSelect/index.tsx +++ b/web/src/components/ModelSelect/index.tsx @@ -2,9 +2,9 @@ * @Author: ZhaoYing * @Date: 2026-03-07 16:49:59 * @Last Modified by: ZhaoYing - * @Last Modified time: 2026-04-16 17:46:02 + * @Last Modified time: 2026-04-17 10:05:23 */ -import { useEffect, useState, forwardRef, useImperativeHandle } from 'react'; +import { type FC, useEffect, useState } from 'react'; import { Select, Flex, Space } from 'antd'; import type { SelectProps } from 'antd/es/select'; import { useTranslation } from 'react-i18next'; @@ -26,17 +26,13 @@ interface ModelSelectProps extends SelectProps { fontClassName?: string; isAutoFetch?: boolean; initialData?: Model[]; + updateOptions?: (options: Model[]) => void; } -const ModelSelect = forwardRef(( - { params, placeholder, fontClassName, isAutoFetch = true, initialData = [], ...props }, - ref -) => { +const ModelSelect: FC = ({ params, placeholder, fontClassName, isAutoFetch = true, initialData = [], updateOptions, ...props }) => { const { t } = useTranslation(); const [options, setOptions] = useState([]); - useImperativeHandle(ref, () => ({ options }), [options]); - // Fetch active models whenever params change; stringify for stable deep comparison useEffect(() => { if (!isAutoFetch) return @@ -62,6 +58,10 @@ const ModelSelect = forwardRef(( ); }; + useEffect(() => { + if (updateOptions) updateOptions([...options, ...initialData]); + }, [options, initialData]) + return (