fix(usage): carry full filter set in breakdown tables and fix double fetch

- breakdown sub-tables now send all active filters (route/user/api_key), matching the trend chart
- summary tab filters the token trend by user and unions user options from both meta APIs (deduped by id)
- stabilize the filters reference so meta load no longer retriggers a second fetch on mount
This commit is contained in:
jialin
2026-06-30 17:02:17 +08:00
committed by jialin
parent a1dd1ec861
commit db17192e55
7 changed files with 105 additions and 47 deletions
@@ -4,18 +4,18 @@ import PageBox from '@/pages/_components/page-box';
import { useIntl } from '@umijs/max';
import { Table } from 'antd';
import { useEffect, useMemo, useRef, useState } from 'react';
import { BreakdownItem, FilterOptionType } from '../../config/types';
import { BreakdownFilters, BreakdownItem } from '../../config/types';
import useModelsColumns from '../../hooks/use-models-columns';
import useQueryBreakdownList from '../../services/use-query-breakdown-list';
import getBreakdownRowKey from '../../utils/get-breakdown-row-key';
const Models: React.FC<{
routes: FilterOptionType[];
filters: BreakdownFilters;
dateRange: { start_date: string; end_date: string };
scope: string;
pageResetKey?: number;
refreshKey?: number;
}> = ({ routes, dateRange, scope, pageResetKey = 0, refreshKey = 0 }) => {
}> = ({ filters, dateRange, scope, pageResetKey = 0, refreshKey = 0 }) => {
const intl = useIntl();
const { loading, dataSource, fetchData } = useQueryBreakdownList({
@@ -33,7 +33,6 @@ const Models: React.FC<{
const pendingPageResetRef = useRef(false);
const handleTableChange = (pagination: any, filters: any, sorter: any) => {
console.log('pagination, filters, sorter: ', pagination, filters, sorter);
const sort_by =
sorter.order === 'descend' ? `-${sorter.field}` : sorter.field;
setQueryParams((prev) => ({
@@ -72,16 +71,16 @@ const Models: React.FC<{
fetchData({
...queryParams,
group_by: ['route'],
filters: {
routes
},
// Send the full filter set (route / user / api_key), not just the
// table's own dimension, so the breakdown matches the trend chart.
filters,
scope: scope,
...dateRange
});
}, [
dateRange.end_date,
dateRange.start_date,
routes,
filters,
queryParams.page,
queryParams.perPage,
queryParams.sort_by,