♻️ refactor(model-pricing): extract resetPricingFilters utility and eliminate duplication (#1365)
Centralize filter-reset logic to improve maintainability and consistency. - Add `resetPricingFilters` helper to `web/src/helpers/utils.js`, encapsulating all reset actions (search, category, currency, ratio, group, quota type, etc.). - Update `PricingFilterModal.jsx` and `PricingSidebar.jsx` to import and use the new utility instead of keeping their own duplicate `handleResetFilters`. - Removes repeated code, ensures future changes to reset behavior require modification in only one place, and keeps components lean.
This commit is contained in:
@@ -616,3 +616,55 @@ export const createCardProPagination = ({
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
// -------------------------------
|
||||
// 重置模型定价筛选条件
|
||||
export const resetPricingFilters = ({
|
||||
handleChange,
|
||||
setActiveKey,
|
||||
availableCategories,
|
||||
setShowWithRecharge,
|
||||
setCurrency,
|
||||
setShowRatio,
|
||||
setFilterGroup,
|
||||
setFilterQuotaType,
|
||||
}) => {
|
||||
// 重置搜索
|
||||
if (typeof handleChange === 'function') {
|
||||
handleChange('');
|
||||
}
|
||||
|
||||
// 重置模型分类到默认
|
||||
if (
|
||||
typeof setActiveKey === 'function' &&
|
||||
Array.isArray(availableCategories) &&
|
||||
availableCategories.length > 0
|
||||
) {
|
||||
setActiveKey(availableCategories[0]);
|
||||
}
|
||||
|
||||
// 重置充值价格显示
|
||||
if (typeof setShowWithRecharge === 'function') {
|
||||
setShowWithRecharge(false);
|
||||
}
|
||||
|
||||
// 重置货币
|
||||
if (typeof setCurrency === 'function') {
|
||||
setCurrency('USD');
|
||||
}
|
||||
|
||||
// 重置显示倍率
|
||||
if (typeof setShowRatio === 'function') {
|
||||
setShowRatio(false);
|
||||
}
|
||||
|
||||
// 重置分组筛选
|
||||
if (typeof setFilterGroup === 'function') {
|
||||
setFilterGroup('all');
|
||||
}
|
||||
|
||||
// 重置计费类型筛选
|
||||
if (typeof setFilterQuotaType === 'function') {
|
||||
setFilterQuotaType('all');
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user