From 63b9457b6cb2074c99ad46f62d842ee2542dfae6 Mon Sep 17 00:00:00 2001 From: t0ng7u Date: Tue, 12 Aug 2025 23:32:25 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=8D=20fix(pricing):=20synchronize=20se?= =?UTF-8?q?arch=20term=20with=20sidebar=20filters=20&=20reset=20behavior?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add `searchValue` to every dependency array in `usePricingFilterCounts` to ensure group/vendor/tag counts and disabled states update dynamically while performing fuzzy search. * Refactor `PricingTopSection` search box into a controlled component: - Accept `searchValue` prop and bind it to `Input.value` - Extend memo dependencies to include `searchValue` This keeps the UI in sync with state changes triggered by `handleChange`. * Guarantee that `resetPricingFilters` clears the search field by leveraging the new controlled input. As a result, sidebar counters/disabled states now react to search input, and the “Reset” button fully restores default filters without leaving the search term visible. --- .../layout/header/PricingTopSection.jsx | 4 +++- .../model-pricing/usePricingFilterCounts.js | 17 +++++------------ 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/web/src/components/table/model-pricing/layout/header/PricingTopSection.jsx b/web/src/components/table/model-pricing/layout/header/PricingTopSection.jsx index 1a4c301a..b255216f 100644 --- a/web/src/components/table/model-pricing/layout/header/PricingTopSection.jsx +++ b/web/src/components/table/model-pricing/layout/header/PricingTopSection.jsx @@ -35,6 +35,7 @@ const PricingTopSection = ({ models, filteredModels, loading, + searchValue, t }) => { const [showFilterModal, setShowFilterModal] = useState(false); @@ -46,6 +47,7 @@ const PricingTopSection = ({ } placeholder={t('模糊搜索模型名称')} + value={searchValue} onCompositionStart={handleCompositionStart} onCompositionEnd={handleCompositionEnd} onChange={handleChange} @@ -78,7 +80,7 @@ const PricingTopSection = ({ )} - ), [selectedRowKeys, t, handleCompositionStart, handleCompositionEnd, handleChange, copyText, isMobile]); + ), [selectedRowKeys, t, handleCompositionStart, handleCompositionEnd, handleChange, copyText, isMobile, searchValue]); return ( <> diff --git a/web/src/hooks/model-pricing/usePricingFilterCounts.js b/web/src/hooks/model-pricing/usePricingFilterCounts.js index ee7f41c7..046d3729 100644 --- a/web/src/hooks/model-pricing/usePricingFilterCounts.js +++ b/web/src/hooks/model-pricing/usePricingFilterCounts.js @@ -104,34 +104,27 @@ export const usePricingFilterCounts = ({ // 生成不同视图所需的模型集合 const quotaTypeModels = useMemo( () => allModels.filter((m) => matchesFilters(m, ['quota'])), - [allModels, filterGroup, filterEndpointType, filterVendor, filterTag] + [allModels, filterGroup, filterEndpointType, filterVendor, filterTag, searchValue] ); const endpointTypeModels = useMemo( () => allModels.filter((m) => matchesFilters(m, ['endpoint'])), - [allModels, filterGroup, filterQuotaType, filterVendor, filterTag] + [allModels, filterGroup, filterQuotaType, filterVendor, filterTag, searchValue] ); const vendorModels = useMemo( () => allModels.filter((m) => matchesFilters(m, ['vendor'])), - [allModels, filterGroup, filterQuotaType, filterEndpointType, filterTag] + [allModels, filterGroup, filterQuotaType, filterEndpointType, filterTag, searchValue] ); const tagModels = useMemo( () => allModels.filter((m) => matchesFilters(m, ['tag'])), - [allModels, filterGroup, filterQuotaType, filterEndpointType, filterVendor] + [allModels, filterGroup, filterQuotaType, filterEndpointType, filterVendor, searchValue] ); const groupCountModels = useMemo( () => allModels.filter((m) => matchesFilters(m, ['group'])), - [ - allModels, - filterQuotaType, - filterEndpointType, - filterVendor, - filterTag, - searchValue, - ] + [allModels, filterQuotaType, filterEndpointType, filterVendor, filterTag, searchValue] ); return {