feat(clients): restore traffic usage progress bars on Clients page (#5150)

Bring back the v2.9.x traffic column UX: used amount, color-coded progress bar, limit/infinity label, and hover popover with upload/download/remaining breakdown. Adds a shared ClientTrafficCell component, traffic display helpers, and unit tests.
This commit is contained in:
nima1024m
2026-06-11 13:40:49 +03:30
committed by GitHub
parent c7a76e9626
commit 941eba546d
5 changed files with 314 additions and 11 deletions
@@ -0,0 +1,85 @@
import { useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import { Popover, Progress } from 'antd';
import InfinityIcon from '@/components/ui/InfinityIcon';
import { useTheme } from '@/hooks/useTheme';
import { computeTrafficDisplay } from '@/lib/clients/traffic-display';
import { SizeFormatter } from '@/utils';
import './ClientTrafficCell.css';
export interface ClientTrafficCellProps {
up?: number;
down?: number;
total?: number;
enabled?: boolean;
trafficDiff?: number;
compact?: boolean;
}
export default function ClientTrafficCell({
up = 0,
down = 0,
total = 0,
enabled = true,
trafficDiff = 0,
compact = false,
}: ClientTrafficCellProps) {
const { t } = useTranslation();
const { isDark } = useTheme();
const display = useMemo(
() => computeTrafficDisplay({ up, down, total, enabled, trafficDiff }, isDark),
[up, down, total, enabled, trafficDiff, isDark],
);
const popover = (
<table className="client-traffic-popover">
<tbody>
<tr>
<td></td>
<td>{SizeFormatter.sizeFormat(up)}</td>
<td></td>
<td>{SizeFormatter.sizeFormat(down)}</td>
</tr>
{!display.isUnlimited && (
<tr>
<td colSpan={2}>{t('remained')}</td>
<td colSpan={2}>{SizeFormatter.sizeFormat(display.remaining)}</td>
</tr>
)}
</tbody>
</table>
);
const rootClass = [
'client-traffic-cell',
compact ? 'is-compact' : '',
display.isUnlimited ? 'is-unlimited' : '',
].filter(Boolean).join(' ');
return (
<Popover content={popover} trigger={['hover', 'click']} placement="top">
<div className={rootClass}>
<span className="client-traffic-cell-used">{SizeFormatter.sizeFormat(display.used)}</span>
<Progress
className="client-traffic-cell-bar"
percent={display.percent}
showInfo={false}
strokeColor={display.strokeColor}
status={display.status}
size={compact ? 'small' : 'default'}
/>
<span className="client-traffic-cell-limit">
{display.isUnlimited ? (
<span className="client-traffic-cell-infinity" aria-label={t('subscription.unlimited')}>
<InfinityIcon />
</span>
) : (
SizeFormatter.sizeFormat(total)
)}
</span>
</div>
</Popover>
);
}