2025-07-23 01:58:51 +08:00
|
|
|
/*
|
|
|
|
|
Copyright (C) 2025 QuantumNous
|
|
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Affero General Public License as
|
|
|
|
|
published by the Free Software Foundation, either version 3 of the
|
|
|
|
|
License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
For commercial licensing, please contact support@quantumnous.com
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import React from 'react';
|
2025-07-23 03:14:25 +08:00
|
|
|
import { Button } from '@douyinfe/semi-ui';
|
2025-07-24 03:19:32 +08:00
|
|
|
import PricingCategories from '../filter/PricingCategories';
|
|
|
|
|
import PricingGroups from '../filter/PricingGroups';
|
|
|
|
|
import PricingQuotaTypes from '../filter/PricingQuotaTypes';
|
2025-07-24 03:25:57 +08:00
|
|
|
import PricingEndpointTypes from '../filter/PricingEndpointTypes';
|
2025-07-24 03:19:32 +08:00
|
|
|
import PricingDisplaySettings from '../filter/PricingDisplaySettings';
|
|
|
|
|
import { resetPricingFilters } from '../../../../helpers/utils';
|
✨ refactor: pricing filters for dynamic counting & cleaner logic
This commit introduces a unified, maintainable solution for all model-pricing filter buttons and removes redundant code.
Key points
• Added `usePricingFilterCounts` hook
- Centralises filtering logic and returns:
- `quotaTypeModels`, `endpointTypeModels`, `dynamicCategoryCounts`, `groupCountModels`
- Keeps internal helpers private (removed public `modelsAfterCategory`).
• Updated components to consume the new hook
- `PricingSidebar.jsx`
- `FilterModalContent.jsx`
• Improved button UI/UX
- `SelectableButtonGroup.jsx` now respects `item.disabled` and auto-disables when `tagCount === 0`.
- `PricingGroups.jsx` counts models per group (after all other filters) and disables groups with zero matches.
- `PricingEndpointTypes.jsx` enumerates all endpoint types, computes filtered counts, and disables entries with zero matches.
• Removed obsolete / duplicate calculations and comments to keep components lean.
The result is consistent, real-time tag counts across all filter groups, automatic disabling of unavailable options, and a single source of truth for filter computations, making future extensions straightforward.
2025-07-26 18:38:18 +08:00
|
|
|
import { usePricingFilterCounts } from '../../../../hooks/model-pricing/usePricingFilterCounts';
|
2025-07-23 01:58:51 +08:00
|
|
|
|
|
|
|
|
const PricingSidebar = ({
|
|
|
|
|
showWithRecharge,
|
|
|
|
|
setShowWithRecharge,
|
|
|
|
|
currency,
|
|
|
|
|
setCurrency,
|
|
|
|
|
handleChange,
|
|
|
|
|
setActiveKey,
|
|
|
|
|
showRatio,
|
|
|
|
|
setShowRatio,
|
2025-07-24 03:19:32 +08:00
|
|
|
viewMode,
|
|
|
|
|
setViewMode,
|
2025-07-23 01:58:51 +08:00
|
|
|
filterGroup,
|
|
|
|
|
setFilterGroup,
|
|
|
|
|
filterQuotaType,
|
|
|
|
|
setFilterQuotaType,
|
2025-07-24 03:25:57 +08:00
|
|
|
filterEndpointType,
|
|
|
|
|
setFilterEndpointType,
|
2025-07-24 03:19:32 +08:00
|
|
|
currentPage,
|
|
|
|
|
setCurrentPage,
|
2025-07-24 17:10:08 +08:00
|
|
|
tokenUnit,
|
|
|
|
|
setTokenUnit,
|
2025-07-23 04:31:27 +08:00
|
|
|
loading,
|
2025-07-23 01:58:51 +08:00
|
|
|
t,
|
|
|
|
|
...categoryProps
|
|
|
|
|
}) => {
|
|
|
|
|
|
✨ refactor: pricing filters for dynamic counting & cleaner logic
This commit introduces a unified, maintainable solution for all model-pricing filter buttons and removes redundant code.
Key points
• Added `usePricingFilterCounts` hook
- Centralises filtering logic and returns:
- `quotaTypeModels`, `endpointTypeModels`, `dynamicCategoryCounts`, `groupCountModels`
- Keeps internal helpers private (removed public `modelsAfterCategory`).
• Updated components to consume the new hook
- `PricingSidebar.jsx`
- `FilterModalContent.jsx`
• Improved button UI/UX
- `SelectableButtonGroup.jsx` now respects `item.disabled` and auto-disables when `tagCount === 0`.
- `PricingGroups.jsx` counts models per group (after all other filters) and disables groups with zero matches.
- `PricingEndpointTypes.jsx` enumerates all endpoint types, computes filtered counts, and disables entries with zero matches.
• Removed obsolete / duplicate calculations and comments to keep components lean.
The result is consistent, real-time tag counts across all filter groups, automatic disabling of unavailable options, and a single source of truth for filter computations, making future extensions straightforward.
2025-07-26 18:38:18 +08:00
|
|
|
const {
|
|
|
|
|
quotaTypeModels,
|
|
|
|
|
endpointTypeModels,
|
|
|
|
|
dynamicCategoryCounts,
|
|
|
|
|
groupCountModels,
|
|
|
|
|
} = usePricingFilterCounts({
|
|
|
|
|
models: categoryProps.models,
|
|
|
|
|
modelCategories: categoryProps.modelCategories,
|
|
|
|
|
activeKey: categoryProps.activeKey,
|
|
|
|
|
filterGroup,
|
|
|
|
|
filterQuotaType,
|
|
|
|
|
filterEndpointType,
|
|
|
|
|
searchValue: categoryProps.searchValue,
|
|
|
|
|
});
|
|
|
|
|
|
2025-07-23 03:29:11 +08:00
|
|
|
const handleResetFilters = () =>
|
|
|
|
|
resetPricingFilters({
|
|
|
|
|
handleChange,
|
|
|
|
|
setActiveKey,
|
|
|
|
|
availableCategories: categoryProps.availableCategories,
|
|
|
|
|
setShowWithRecharge,
|
|
|
|
|
setCurrency,
|
|
|
|
|
setShowRatio,
|
2025-07-24 03:19:32 +08:00
|
|
|
setViewMode,
|
2025-07-23 03:29:11 +08:00
|
|
|
setFilterGroup,
|
|
|
|
|
setFilterQuotaType,
|
2025-07-24 03:25:57 +08:00
|
|
|
setFilterEndpointType,
|
2025-07-24 03:19:32 +08:00
|
|
|
setCurrentPage,
|
2025-07-24 17:10:08 +08:00
|
|
|
setTokenUnit,
|
2025-07-23 03:29:11 +08:00
|
|
|
});
|
2025-07-23 01:58:51 +08:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="p-4">
|
|
|
|
|
<div className="flex items-center justify-between mb-6">
|
|
|
|
|
<div className="text-lg font-semibold text-gray-800">
|
|
|
|
|
{t('筛选')}
|
|
|
|
|
</div>
|
|
|
|
|
<Button
|
|
|
|
|
theme="outline"
|
2025-07-23 03:14:25 +08:00
|
|
|
type='tertiary'
|
2025-07-23 01:58:51 +08:00
|
|
|
onClick={handleResetFilters}
|
|
|
|
|
className="text-gray-500 hover:text-gray-700"
|
|
|
|
|
>
|
|
|
|
|
{t('重置')}
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
|
2025-07-23 03:14:25 +08:00
|
|
|
<PricingDisplaySettings
|
|
|
|
|
showWithRecharge={showWithRecharge}
|
|
|
|
|
setShowWithRecharge={setShowWithRecharge}
|
|
|
|
|
currency={currency}
|
|
|
|
|
setCurrency={setCurrency}
|
|
|
|
|
showRatio={showRatio}
|
|
|
|
|
setShowRatio={setShowRatio}
|
2025-07-24 03:19:32 +08:00
|
|
|
viewMode={viewMode}
|
|
|
|
|
setViewMode={setViewMode}
|
2025-07-24 17:10:08 +08:00
|
|
|
tokenUnit={tokenUnit}
|
|
|
|
|
setTokenUnit={setTokenUnit}
|
2025-07-23 04:31:27 +08:00
|
|
|
loading={loading}
|
2025-07-23 03:14:25 +08:00
|
|
|
t={t}
|
|
|
|
|
/>
|
2025-07-23 01:58:51 +08:00
|
|
|
|
2025-07-24 03:19:32 +08:00
|
|
|
<PricingCategories
|
|
|
|
|
{...categoryProps}
|
✨ refactor: pricing filters for dynamic counting & cleaner logic
This commit introduces a unified, maintainable solution for all model-pricing filter buttons and removes redundant code.
Key points
• Added `usePricingFilterCounts` hook
- Centralises filtering logic and returns:
- `quotaTypeModels`, `endpointTypeModels`, `dynamicCategoryCounts`, `groupCountModels`
- Keeps internal helpers private (removed public `modelsAfterCategory`).
• Updated components to consume the new hook
- `PricingSidebar.jsx`
- `FilterModalContent.jsx`
• Improved button UI/UX
- `SelectableButtonGroup.jsx` now respects `item.disabled` and auto-disables when `tagCount === 0`.
- `PricingGroups.jsx` counts models per group (after all other filters) and disables groups with zero matches.
- `PricingEndpointTypes.jsx` enumerates all endpoint types, computes filtered counts, and disables entries with zero matches.
• Removed obsolete / duplicate calculations and comments to keep components lean.
The result is consistent, real-time tag counts across all filter groups, automatic disabling of unavailable options, and a single source of truth for filter computations, making future extensions straightforward.
2025-07-26 18:38:18 +08:00
|
|
|
categoryCounts={dynamicCategoryCounts}
|
2025-07-24 03:19:32 +08:00
|
|
|
setActiveKey={setActiveKey}
|
|
|
|
|
loading={loading}
|
|
|
|
|
t={t}
|
|
|
|
|
/>
|
2025-07-23 01:58:51 +08:00
|
|
|
|
2025-07-24 03:19:32 +08:00
|
|
|
<PricingGroups
|
|
|
|
|
filterGroup={filterGroup}
|
|
|
|
|
setFilterGroup={setFilterGroup}
|
|
|
|
|
usableGroup={categoryProps.usableGroup}
|
|
|
|
|
groupRatio={categoryProps.groupRatio}
|
✨ refactor: pricing filters for dynamic counting & cleaner logic
This commit introduces a unified, maintainable solution for all model-pricing filter buttons and removes redundant code.
Key points
• Added `usePricingFilterCounts` hook
- Centralises filtering logic and returns:
- `quotaTypeModels`, `endpointTypeModels`, `dynamicCategoryCounts`, `groupCountModels`
- Keeps internal helpers private (removed public `modelsAfterCategory`).
• Updated components to consume the new hook
- `PricingSidebar.jsx`
- `FilterModalContent.jsx`
• Improved button UI/UX
- `SelectableButtonGroup.jsx` now respects `item.disabled` and auto-disables when `tagCount === 0`.
- `PricingGroups.jsx` counts models per group (after all other filters) and disables groups with zero matches.
- `PricingEndpointTypes.jsx` enumerates all endpoint types, computes filtered counts, and disables entries with zero matches.
• Removed obsolete / duplicate calculations and comments to keep components lean.
The result is consistent, real-time tag counts across all filter groups, automatic disabling of unavailable options, and a single source of truth for filter computations, making future extensions straightforward.
2025-07-26 18:38:18 +08:00
|
|
|
models={groupCountModels}
|
2025-07-24 03:19:32 +08:00
|
|
|
loading={loading}
|
|
|
|
|
t={t}
|
|
|
|
|
/>
|
2025-07-23 01:58:51 +08:00
|
|
|
|
2025-07-24 03:19:32 +08:00
|
|
|
<PricingQuotaTypes
|
|
|
|
|
filterQuotaType={filterQuotaType}
|
|
|
|
|
setFilterQuotaType={setFilterQuotaType}
|
✨ refactor: pricing filters for dynamic counting & cleaner logic
This commit introduces a unified, maintainable solution for all model-pricing filter buttons and removes redundant code.
Key points
• Added `usePricingFilterCounts` hook
- Centralises filtering logic and returns:
- `quotaTypeModels`, `endpointTypeModels`, `dynamicCategoryCounts`, `groupCountModels`
- Keeps internal helpers private (removed public `modelsAfterCategory`).
• Updated components to consume the new hook
- `PricingSidebar.jsx`
- `FilterModalContent.jsx`
• Improved button UI/UX
- `SelectableButtonGroup.jsx` now respects `item.disabled` and auto-disables when `tagCount === 0`.
- `PricingGroups.jsx` counts models per group (after all other filters) and disables groups with zero matches.
- `PricingEndpointTypes.jsx` enumerates all endpoint types, computes filtered counts, and disables entries with zero matches.
• Removed obsolete / duplicate calculations and comments to keep components lean.
The result is consistent, real-time tag counts across all filter groups, automatic disabling of unavailable options, and a single source of truth for filter computations, making future extensions straightforward.
2025-07-26 18:38:18 +08:00
|
|
|
models={quotaTypeModels}
|
2025-07-24 03:19:32 +08:00
|
|
|
loading={loading}
|
|
|
|
|
t={t}
|
|
|
|
|
/>
|
2025-07-24 03:25:57 +08:00
|
|
|
|
|
|
|
|
<PricingEndpointTypes
|
|
|
|
|
filterEndpointType={filterEndpointType}
|
|
|
|
|
setFilterEndpointType={setFilterEndpointType}
|
✨ refactor: pricing filters for dynamic counting & cleaner logic
This commit introduces a unified, maintainable solution for all model-pricing filter buttons and removes redundant code.
Key points
• Added `usePricingFilterCounts` hook
- Centralises filtering logic and returns:
- `quotaTypeModels`, `endpointTypeModels`, `dynamicCategoryCounts`, `groupCountModels`
- Keeps internal helpers private (removed public `modelsAfterCategory`).
• Updated components to consume the new hook
- `PricingSidebar.jsx`
- `FilterModalContent.jsx`
• Improved button UI/UX
- `SelectableButtonGroup.jsx` now respects `item.disabled` and auto-disables when `tagCount === 0`.
- `PricingGroups.jsx` counts models per group (after all other filters) and disables groups with zero matches.
- `PricingEndpointTypes.jsx` enumerates all endpoint types, computes filtered counts, and disables entries with zero matches.
• Removed obsolete / duplicate calculations and comments to keep components lean.
The result is consistent, real-time tag counts across all filter groups, automatic disabling of unavailable options, and a single source of truth for filter computations, making future extensions straightforward.
2025-07-26 18:38:18 +08:00
|
|
|
models={endpointTypeModels}
|
|
|
|
|
allModels={categoryProps.models}
|
2025-07-24 03:25:57 +08:00
|
|
|
loading={loading}
|
|
|
|
|
t={t}
|
|
|
|
|
/>
|
2025-07-23 01:58:51 +08:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default PricingSidebar;
|