mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-08-23 11:27:13 +00:00
perf(clients): make the clients page scale to large panels
The clients page was slow on panels with many clients for two independent reasons: the server rebuilt the whole picture on every request, and the browser rebuilt the whole table on every poll. Server side, ListPaged loaded every client row, every client_inbounds link and every client_traffics row into Go memory, then filtered, sorted and paginated in a loop -- on a request the page repeats every five seconds. Every predicate now runs in SQL and only the requested page's ids are hydrated, so the cost tracks the page size rather than the client count. Measured on SQLite with a realistic status mix: the default view at 100k clients goes from 1,072ms to 64ms. Behaviour is preserved deliberately in the subtle places -- the cross-panel global-traffic overlay is folded into the same used-bytes expression the predicates and sort use, LIKE wildcards are escaped so a search for "a_b" stays literal, and the two different tiebreak rules the in-memory comparator had are reproduced per sort key. The summary's per-bucket email lists are capped at 200 with exact counters beside them. They only back hover popovers, but shipping every match made the response grow with the panel: at 100k clients it carried ~42k emails, and the page revalidated all of them through a strict Zod parse every five seconds. The popover now shows a "+N" chip for the remainder. Browser side, the page fired three sequential list requests per load and threw the first two away: the query went out before the persisted sort was applied, and again before the configured page size was known -- 0 meaning "one long page" is indistinguishable from "not loaded yet". The page size is now derived rather than mirrored through an effect, and the previous visit's value is remembered so the single request goes out at mount instead of queueing behind /setting/defaultSettings. Then the per-poll work. Reading isFetching made it a tracked property, so the refetch interval notified twice per cycle and re-rendered the page even when structural sharing left the data identical. Xray reports a traffic row per client whether or not it moved bytes, so the speed map was mostly zeros and was replaced wholesale every push; zero rows are now dropped and an unchanged result returns the previous object, which lets React bail out instead of re-rendering. The five Tooltip-wrapped buttons and the inbound chips per row do not depend on traffic at all and are now memoised, keyed on the email because a push replaces the row object of every client whose counters moved. antd's hashed:false drops 3,311 :where(.css-<hash>) wrappers and 29% of the generated stylesheet, and a pinned cssVar key stops each of the eleven page-level ConfigProviders minting its own token scope. Two callers that only need the mutations, GroupsPage and ClientBulkAddModal, no longer start the list query -- the groups page had been polling the full paged list every five seconds for data it never renders.
This commit is contained in:
@@ -56,7 +56,7 @@ export default function ClientBulkAddModal({
|
||||
}: ClientBulkAddModalProps) {
|
||||
const { t } = useTranslation();
|
||||
const [messageApi, messageContextHolder] = message.useMessage();
|
||||
const { bulkCreate } = useClients();
|
||||
const { bulkCreate } = useClients({ list: false });
|
||||
|
||||
const methods = useForm<ClientBulkAddFormValues>({ defaultValues: EMPTY });
|
||||
const inboundIds = useWatch({ control: methods.control, name: 'inboundIds' });
|
||||
|
||||
@@ -16,6 +16,13 @@
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.client-email-more {
|
||||
margin-top: 4px;
|
||||
padding-top: 4px;
|
||||
border-top: 1px solid var(--ant-color-border-secondary, rgba(128, 128, 128, 0.2));
|
||||
opacity: 0.65;
|
||||
}
|
||||
|
||||
.filter-bar {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { lazy, useCallback, useEffect, useMemo, useState } from 'react';
|
||||
import { lazy, useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import {
|
||||
Badge,
|
||||
@@ -16,7 +16,6 @@ import {
|
||||
Result,
|
||||
Row,
|
||||
Select,
|
||||
Space,
|
||||
Spin,
|
||||
Statistic,
|
||||
Switch,
|
||||
@@ -80,12 +79,14 @@ const BulkAttachInboundsModal = lazy(() => import('./BulkAttachInboundsModal'));
|
||||
const BulkDetachInboundsModal = lazy(() => import('./BulkDetachInboundsModal'));
|
||||
const TextModal = lazy(() => import('@/components/feedback/TextModal'));
|
||||
const PromptModal = lazy(() => import('@/components/feedback/PromptModal'));
|
||||
import { ClientInboundChips, ClientRowActions } from './RowCells';
|
||||
import { emptyFilters, activeFilterCount } from './filters';
|
||||
import type { ClientFilters } from './filters';
|
||||
import './ClientsPage.css';
|
||||
|
||||
const FILTER_STATE_KEY = 'clientsFilterState';
|
||||
const DISABLED_PAGE_SIZE = 200;
|
||||
const DEFAULT_TABLE_PAGE_SIZE = 25;
|
||||
|
||||
function UngroupIcon() {
|
||||
return (
|
||||
@@ -126,12 +127,29 @@ function UngroupIcon() {
|
||||
);
|
||||
}
|
||||
|
||||
// The server sends exact counters but caps the email arrays behind them, so a
|
||||
// panel with thousands of depleted clients neither ships nor renders them all.
|
||||
// The trailing chip reports what the popover left out.
|
||||
function ClientEmailList({ emails, total }: { emails: string[]; total: number }) {
|
||||
const hidden = total - emails.length;
|
||||
return (
|
||||
<div className="client-email-list">
|
||||
{emails.map((e) => <div key={e}>{e}</div>)}
|
||||
{hidden > 0 && <div className="client-email-more">+{hidden}</div>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
type Bucket = 'active' | 'deactive' | 'depleted' | 'expiring';
|
||||
|
||||
interface PersistedFilterState {
|
||||
searchKey: string;
|
||||
filters: ClientFilters;
|
||||
sort: string;
|
||||
// The page size resolved on the previous visit. Without it the first list
|
||||
// request has to wait for /setting/defaultSettings just to learn how many rows
|
||||
// to ask for, which serialises two round trips on every load.
|
||||
pageSize: number | null;
|
||||
}
|
||||
|
||||
const INBOUND_PROTOCOL_COLORS: Record<string, string> = {
|
||||
@@ -147,6 +165,9 @@ const INBOUND_PROTOCOL_COLORS: Record<string, string> = {
|
||||
tunnel: 'orange',
|
||||
};
|
||||
const INBOUND_CHIP_LIMIT = 1;
|
||||
// A shared empty array keeps the memoised chip cell from seeing a fresh prop for
|
||||
// every unattached client on every render.
|
||||
const EMPTY_INBOUND_IDS: number[] = [];
|
||||
|
||||
function readFilterState(): PersistedFilterState {
|
||||
try {
|
||||
@@ -164,9 +185,10 @@ function readFilterState(): PersistedFilterState {
|
||||
groups: Array.isArray(fromRaw.groups) ? fromRaw.groups : [],
|
||||
},
|
||||
sort: typeof raw.sort === 'string' ? raw.sort : '',
|
||||
pageSize: typeof raw.pageSize === 'number' && raw.pageSize > 0 ? raw.pageSize : null,
|
||||
};
|
||||
} catch {
|
||||
return { searchKey: '', filters: emptyFilters(), sort: '' };
|
||||
return { searchKey: '', filters: emptyFilters(), sort: '', pageSize: null };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -208,8 +230,8 @@ export default function ClientsPage() {
|
||||
summary,
|
||||
allGroups,
|
||||
setQuery,
|
||||
inbounds, onlines, loading, transitioning, fetched, fetchError, subSettings,
|
||||
tgBotEnable, expireDiff, trafficDiff, pageSize,
|
||||
inbounds, onlines, transitioning, fetched, fetchError, subSettings,
|
||||
tgBotEnable, expireDiff, trafficDiff, pageSize, settingsReady,
|
||||
create, update, remove, bulkDelete, bulkAdjust, bulkEnable, bulkDisable, bulkAddToGroup, bulkRemoveFromGroup, attach, setExternalLinks, bulkAttach, detach, bulkDetach,
|
||||
resetTraffic, resetAllTraffics, delDepleted, delOrphans, exportClients, importClients, setEnable,
|
||||
clientSpeed,
|
||||
@@ -265,14 +287,31 @@ export default function ClientsPage() {
|
||||
const [sortColumn, setSortColumn] = useState<string | null>(initialSort.column);
|
||||
const [sortOrder, setSortOrder] = useState<'ascend' | 'descend' | null>(initialSort.order);
|
||||
const [currentPage, setCurrentPage] = useState(1);
|
||||
const [tablePageSize, setTablePageSize] = useState(25);
|
||||
// Derived, not mirrored into state by an effect: an effect lags one render
|
||||
// behind the settings arriving, and that lag is what made the page fetch the
|
||||
// list once with the placeholder size and again with the real one.
|
||||
const [pageSizeChoice, setPageSizeChoice] = useState<number | null>(null);
|
||||
const settingsPageSize = settingsReady ? (pageSize > 0 ? pageSize : DISABLED_PAGE_SIZE) : null;
|
||||
// Last visit's resolved size stands in until the settings land, so the list
|
||||
// request goes out with the page mount instead of queueing behind them. If the
|
||||
// admin has since changed the setting the authoritative value replaces it and
|
||||
// costs one refetch — only on the load that follows the change. Null means
|
||||
// nothing is known yet, which is the one case worth waiting for.
|
||||
const resolvedPageSize = pageSizeChoice ?? settingsPageSize ?? initial.pageSize;
|
||||
const tablePageSize = resolvedPageSize ?? DEFAULT_TABLE_PAGE_SIZE;
|
||||
// debouncedSearch lags behind the input so we don't spam the server on every
|
||||
// keystroke; the search box still feels instant locally.
|
||||
const [debouncedSearch, setDebouncedSearch] = useState(searchKey);
|
||||
|
||||
useEffect(() => {
|
||||
localStorage.setItem(FILTER_STATE_KEY, JSON.stringify({ searchKey, filters, sort: sortValueFor(sortColumn, sortOrder) }));
|
||||
}, [searchKey, filters, sortColumn, sortOrder]);
|
||||
localStorage.setItem(FILTER_STATE_KEY, JSON.stringify({
|
||||
searchKey,
|
||||
filters,
|
||||
sort: sortValueFor(sortColumn, sortOrder),
|
||||
// Only ever persist a size we actually resolved, never the render fallback.
|
||||
pageSize: resolvedPageSize,
|
||||
}));
|
||||
}, [searchKey, filters, sortColumn, sortOrder, resolvedPageSize]);
|
||||
|
||||
useEffect(() => {
|
||||
const handle = window.setTimeout(() => setDebouncedSearch(searchKey), 300);
|
||||
@@ -303,6 +342,10 @@ export default function ClientsPage() {
|
||||
}, [filters.nodeIds, filters.inboundIds, inbounds]);
|
||||
|
||||
useEffect(() => {
|
||||
// With no remembered size and no settings yet, any query we build would be a
|
||||
// guess, and issuing it costs a full server round trip that is thrown away as
|
||||
// soon as the real size arrives.
|
||||
if (resolvedPageSize === null) return;
|
||||
setQuery({
|
||||
page: currentPage,
|
||||
pageSize: tablePageSize,
|
||||
@@ -321,13 +364,21 @@ export default function ClientsPage() {
|
||||
sort: sortColumn || undefined,
|
||||
order: sortOrder || undefined,
|
||||
});
|
||||
}, [setQuery, currentPage, tablePageSize, debouncedSearch, filters, effectiveInboundCsv, sortColumn, sortOrder]);
|
||||
}, [setQuery, resolvedPageSize, currentPage, tablePageSize, debouncedSearch, filters, effectiveInboundCsv, sortColumn, sortOrder]);
|
||||
|
||||
const activeCount = activeFilterCount(filters);
|
||||
|
||||
useEffect(() => {
|
||||
setTablePageSize(pageSize > 0 ? pageSize : DISABLED_PAGE_SIZE);
|
||||
}, [pageSize]);
|
||||
// Row handlers take an email and look the row up here at call time. Keying
|
||||
// them on the record object instead would defeat the memoised cells: every
|
||||
// traffic push replaces the row object of every client whose counters moved,
|
||||
// so the memo would miss on exactly the rows that are busy. Reading through
|
||||
// the ref also means a modal opened mid-poll shows current usage.
|
||||
const rowsByEmail = useRef(new Map<string, ClientRecord>());
|
||||
rowsByEmail.current = useMemo(() => {
|
||||
const map = new Map<string, ClientRecord>();
|
||||
for (const c of clients) map.set(c.email, c);
|
||||
return map;
|
||||
}, [clients]);
|
||||
|
||||
const onlineSet = useMemo(() => new Set(onlines || []), [onlines]);
|
||||
const inboundsById = useMemo(() => {
|
||||
@@ -454,7 +505,9 @@ export default function ClientsPage() {
|
||||
setFormOpen(true);
|
||||
}
|
||||
|
||||
async function onEdit(row: ClientRecord) {
|
||||
const onEdit = useCallback(async (email: string) => {
|
||||
const row = rowsByEmail.current.get(email);
|
||||
if (!row) return;
|
||||
setFormMode('edit');
|
||||
// Paged list omits per-client secrets to keep the row payload tiny;
|
||||
// edit needs them, so fetch the full record first.
|
||||
@@ -465,9 +518,11 @@ export default function ClientsPage() {
|
||||
setEditingAttachedIds([...ids]);
|
||||
setEditingExternalLinks(Array.isArray(full?.externalLinks) ? [...full.externalLinks] : []);
|
||||
setFormOpen(true);
|
||||
}
|
||||
}, [hydrate]);
|
||||
|
||||
function onDelete(row: ClientRecord) {
|
||||
const onDelete = useCallback((email: string) => {
|
||||
const row = rowsByEmail.current.get(email);
|
||||
if (!row) return;
|
||||
modal.confirm({
|
||||
title: t('pages.clients.deleteConfirmTitle', { email: row.email }),
|
||||
content: t('pages.clients.deleteConfirmContent'),
|
||||
@@ -479,9 +534,10 @@ export default function ClientsPage() {
|
||||
if (msg?.success) messageApi.success(t('pages.clients.toasts.deleted'));
|
||||
},
|
||||
});
|
||||
}
|
||||
}, [modal, t, remove, messageApi]);
|
||||
|
||||
function onResetTraffic(row: ClientRecord) {
|
||||
const onResetTraffic = useCallback((email: string) => {
|
||||
const row = rowsByEmail.current.get(email);
|
||||
if (!row?.email) {
|
||||
messageApi.warning(t('pages.clients.resetNotPossible'));
|
||||
return;
|
||||
@@ -496,19 +552,33 @@ export default function ClientsPage() {
|
||||
if (msg?.success) messageApi.success(t('pages.clients.toasts.trafficReset'));
|
||||
},
|
||||
});
|
||||
}
|
||||
}, [modal, t, resetTraffic, messageApi]);
|
||||
|
||||
async function onShowInfo(row: ClientRecord) {
|
||||
const onShowInfo = useCallback(async (email: string) => {
|
||||
const row = rowsByEmail.current.get(email);
|
||||
if (!row) return;
|
||||
const full = await hydrate(row.email);
|
||||
setInfoClient(full ? { ...row, ...full.client, inboundIds: full.inboundIds } : row);
|
||||
setInfoOpen(true);
|
||||
}
|
||||
}, [hydrate]);
|
||||
|
||||
async function onShowQr(row: ClientRecord) {
|
||||
const onShowQr = useCallback(async (email: string) => {
|
||||
const row = rowsByEmail.current.get(email);
|
||||
if (!row) return;
|
||||
const full = await hydrate(row.email);
|
||||
setQrClient(full ? { ...row, ...full.client, inboundIds: full.inboundIds } : row);
|
||||
setQrOpen(true);
|
||||
}
|
||||
}, [hydrate]);
|
||||
|
||||
const [refreshing, setRefreshing] = useState(false);
|
||||
const onRefreshClick = useCallback(async () => {
|
||||
setRefreshing(true);
|
||||
try {
|
||||
await refresh();
|
||||
} finally {
|
||||
setRefreshing(false);
|
||||
}
|
||||
}, [refresh]);
|
||||
|
||||
const openText = useCallback((opts: { title: string; content: string; fileName?: string }) => {
|
||||
setTextTitle(opts.title);
|
||||
@@ -743,7 +813,7 @@ export default function ClientsPage() {
|
||||
|
||||
const onTableChange: NonNullable<TableProps<ClientRecord>['onChange']> = (pag) => {
|
||||
if (pag?.current) setCurrentPage(pag.current);
|
||||
if (pag?.pageSize) setTablePageSize(pag.pageSize);
|
||||
if (pag?.pageSize) setPageSizeChoice(pag.pageSize);
|
||||
};
|
||||
|
||||
const columns = useMemo<ColumnsType<ClientRecord>>(() => [
|
||||
@@ -752,23 +822,14 @@ export default function ClientsPage() {
|
||||
key: 'actions',
|
||||
width: 200,
|
||||
render: (_v, record) => (
|
||||
<Space size={4}>
|
||||
<Tooltip title={t('pages.clients.qrCode')}>
|
||||
<Button size="small" type="text" style={{ fontSize: 16 }} icon={<QrcodeOutlined />} aria-label={t('pages.clients.qrCode')} onClick={() => onShowQr(record)} />
|
||||
</Tooltip>
|
||||
<Tooltip title={t('pages.clients.clientInfo')}>
|
||||
<Button size="small" type="text" style={{ fontSize: 16 }} icon={<InfoCircleOutlined />} aria-label={t('pages.clients.clientInfo')} onClick={() => onShowInfo(record)} />
|
||||
</Tooltip>
|
||||
<Tooltip title={t('pages.inbounds.resetTraffic')}>
|
||||
<Button size="small" type="text" style={{ fontSize: 16 }} icon={<RetweetOutlined />} aria-label={t('pages.inbounds.resetTraffic')} onClick={() => onResetTraffic(record)} />
|
||||
</Tooltip>
|
||||
<Tooltip title={t('edit')}>
|
||||
<Button size="small" type="text" style={{ fontSize: 16 }} icon={<EditOutlined />} aria-label={t('edit')} onClick={() => onEdit(record)} />
|
||||
</Tooltip>
|
||||
<Tooltip title={t('delete')}>
|
||||
<Button size="small" type="text" danger style={{ fontSize: 16 }} icon={<DeleteOutlined />} aria-label={t('delete')} onClick={() => onDelete(record)} />
|
||||
</Tooltip>
|
||||
</Space>
|
||||
<ClientRowActions
|
||||
email={record.email}
|
||||
onShowQr={onShowQr}
|
||||
onShowInfo={onShowInfo}
|
||||
onResetTraffic={onResetTraffic}
|
||||
onEdit={onEdit}
|
||||
onDelete={onDelete}
|
||||
/>
|
||||
),
|
||||
},
|
||||
{
|
||||
@@ -850,42 +911,13 @@ export default function ClientsPage() {
|
||||
key: 'inboundIds',
|
||||
width: 170,
|
||||
render: (_v, record) => {
|
||||
const ids = record.inboundIds || [];
|
||||
if (ids.length === 0) return <span style={{ color: 'rgba(0,0,0,0.45)' }}>—</span>;
|
||||
const visible = ids.slice(0, INBOUND_CHIP_LIMIT);
|
||||
const overflow = ids.slice(INBOUND_CHIP_LIMIT);
|
||||
const chip = (id: number, compact: boolean) => {
|
||||
const ib = inboundsById[id];
|
||||
const proto = (ib?.protocol || '').toLowerCase();
|
||||
const color = INBOUND_PROTOCOL_COLORS[proto] ?? 'default';
|
||||
const compactLabel = formatInboundLabel(ib?.tag, ib?.remark);
|
||||
return (
|
||||
<Tooltip key={id} title={inboundLabel(id)}>
|
||||
<Tag color={color} style={{ margin: 2 }}>
|
||||
{compact ? compactLabel : inboundLabel(id)}
|
||||
</Tag>
|
||||
</Tooltip>
|
||||
);
|
||||
};
|
||||
return (
|
||||
<>
|
||||
{visible.map((id) => chip(id, true))}
|
||||
{overflow.length > 0 && (
|
||||
<Popover
|
||||
trigger="click"
|
||||
placement="bottomRight"
|
||||
content={
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 4, maxWidth: 280, maxHeight: 280, overflowY: 'auto' }}>
|
||||
{overflow.map((id) => chip(id, false))}
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<Tag color="default" style={{ margin: 2, cursor: 'pointer' }}>
|
||||
+{overflow.length}
|
||||
</Tag>
|
||||
</Popover>
|
||||
)}
|
||||
</>
|
||||
<ClientInboundChips
|
||||
ids={record.inboundIds || EMPTY_INBOUND_IDS}
|
||||
inboundsById={inboundsById}
|
||||
protocolColors={INBOUND_PROTOCOL_COLORS}
|
||||
chipLimit={INBOUND_CHIP_LIMIT}
|
||||
/>
|
||||
);
|
||||
},
|
||||
},
|
||||
@@ -994,7 +1026,7 @@ export default function ClientsPage() {
|
||||
status="error"
|
||||
title={t('somethingWentWrong')}
|
||||
subTitle={fetchError}
|
||||
extra={<Button type="primary" loading={loading} onClick={refresh}>{t('refresh')}</Button>}
|
||||
extra={<Button type="primary" loading={refreshing} onClick={onRefreshClick}>{t('refresh')}</Button>}
|
||||
/>
|
||||
) : (
|
||||
<Row gutter={[isMobile ? 8 : 16, isMobile ? 8 : 12]}>
|
||||
@@ -1007,37 +1039,37 @@ export default function ClientsPage() {
|
||||
<Col xs={12} sm={8} md={4}>
|
||||
<Popover
|
||||
title={t('online')}
|
||||
open={summary.online.length ? undefined : false}
|
||||
content={<div className="client-email-list">{summary.online.map((e) => <div key={e}>{e}</div>)}</div>}
|
||||
open={summary.onlineCount ? undefined : false}
|
||||
content={<ClientEmailList emails={summary.online} total={summary.onlineCount} />}
|
||||
>
|
||||
<Statistic title={t('online')} value={String(summary.online.length)} prefix={<span className="dot dot-blue" />} />
|
||||
<Statistic title={t('online')} value={String(summary.onlineCount)} prefix={<span className="dot dot-blue" />} />
|
||||
</Popover>
|
||||
</Col>
|
||||
<Col xs={12} sm={8} md={4}>
|
||||
<Popover
|
||||
title={t('depleted')}
|
||||
open={summary.depleted.length ? undefined : false}
|
||||
content={<div className="client-email-list">{summary.depleted.map((e) => <div key={e}>{e}</div>)}</div>}
|
||||
open={summary.depletedCount ? undefined : false}
|
||||
content={<ClientEmailList emails={summary.depleted} total={summary.depletedCount} />}
|
||||
>
|
||||
<Statistic title={t('depleted')} value={String(summary.depleted.length)} prefix={<span className="dot dot-red" />} />
|
||||
<Statistic title={t('depleted')} value={String(summary.depletedCount)} prefix={<span className="dot dot-red" />} />
|
||||
</Popover>
|
||||
</Col>
|
||||
<Col xs={12} sm={8} md={4}>
|
||||
<Popover
|
||||
title={t('depletingSoon')}
|
||||
open={summary.expiring.length ? undefined : false}
|
||||
content={<div className="client-email-list">{summary.expiring.map((e) => <div key={e}>{e}</div>)}</div>}
|
||||
open={summary.expiringCount ? undefined : false}
|
||||
content={<ClientEmailList emails={summary.expiring} total={summary.expiringCount} />}
|
||||
>
|
||||
<Statistic title={t('depletingSoon')} value={String(summary.expiring.length)} prefix={<span className="dot dot-orange" />} />
|
||||
<Statistic title={t('depletingSoon')} value={String(summary.expiringCount)} prefix={<span className="dot dot-orange" />} />
|
||||
</Popover>
|
||||
</Col>
|
||||
<Col xs={12} sm={8} md={4}>
|
||||
<Popover
|
||||
title={t('disabled')}
|
||||
open={summary.deactive.length ? undefined : false}
|
||||
content={<div className="client-email-list">{summary.deactive.map((e) => <div key={e}>{e}</div>)}</div>}
|
||||
open={summary.deactiveCount ? undefined : false}
|
||||
content={<ClientEmailList emails={summary.deactive} total={summary.deactiveCount} />}
|
||||
>
|
||||
<Statistic title={t('disabled')} value={String(summary.deactive.length)} prefix={<span className="dot dot-gray" />} />
|
||||
<Statistic title={t('disabled')} value={String(summary.deactiveCount)} prefix={<span className="dot dot-gray" />} />
|
||||
</Popover>
|
||||
</Col>
|
||||
<Col xs={12} sm={8} md={4}>
|
||||
@@ -1364,7 +1396,7 @@ export default function ClientsPage() {
|
||||
showTotal={(n) => `${n}`}
|
||||
onChange={(p, s) => {
|
||||
setCurrentPage(p);
|
||||
if (s && s !== tablePageSize) setTablePageSize(s);
|
||||
if (s && s !== tablePageSize) setPageSizeChoice(s);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
@@ -1391,8 +1423,8 @@ export default function ClientsPage() {
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
aria-label={t('pages.clients.clientInfo')}
|
||||
onClick={() => onShowInfo(row)}
|
||||
onKeyDown={activateOnKey(() => onShowInfo(row))}
|
||||
onClick={() => onShowInfo(row.email)}
|
||||
onKeyDown={activateOnKey(() => onShowInfo(row.email))}
|
||||
/>
|
||||
</Tooltip>
|
||||
<Switch
|
||||
@@ -1409,23 +1441,23 @@ export default function ClientsPage() {
|
||||
{
|
||||
key: 'qr',
|
||||
label: <><QrcodeOutlined /> {t('pages.clients.qrCode')}</>,
|
||||
onClick: () => onShowQr(row),
|
||||
onClick: () => onShowQr(row.email),
|
||||
},
|
||||
{
|
||||
key: 'reset',
|
||||
label: <><RetweetOutlined /> {t('pages.inbounds.resetTraffic')}</>,
|
||||
onClick: () => onResetTraffic(row),
|
||||
onClick: () => onResetTraffic(row.email),
|
||||
},
|
||||
{
|
||||
key: 'edit',
|
||||
label: <><EditOutlined /> {t('edit')}</>,
|
||||
onClick: () => onEdit(row),
|
||||
onClick: () => onEdit(row.email),
|
||||
},
|
||||
{
|
||||
key: 'delete',
|
||||
danger: true,
|
||||
label: <><DeleteOutlined /> {t('delete')}</>,
|
||||
onClick: () => onDelete(row),
|
||||
onClick: () => onDelete(row.email),
|
||||
},
|
||||
],
|
||||
}}
|
||||
|
||||
@@ -0,0 +1,154 @@
|
||||
import { memo } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Button, Popover, Space, Tag, Tooltip } from 'antd';
|
||||
import {
|
||||
DeleteOutlined,
|
||||
EditOutlined,
|
||||
InfoCircleOutlined,
|
||||
QrcodeOutlined,
|
||||
RetweetOutlined,
|
||||
} from '@ant-design/icons';
|
||||
|
||||
import { formatInboundLabel } from '@/lib/inbounds/label';
|
||||
import type { InboundOption } from '@/hooks/useClients';
|
||||
|
||||
const ICON_BUTTON_STYLE = { fontSize: 16 } as const;
|
||||
|
||||
interface ClientRowActionsProps {
|
||||
email: string;
|
||||
onShowQr: (email: string) => void;
|
||||
onShowInfo: (email: string) => void;
|
||||
onResetTraffic: (email: string) => void;
|
||||
onEdit: (email: string) => void;
|
||||
onDelete: (email: string) => void;
|
||||
}
|
||||
|
||||
// Five Tooltip-wrapped buttons per row, none of which depend on traffic. Left
|
||||
// inline they re-ran rc-tooltip's alignment machinery for every visible row on
|
||||
// every traffic push — 125 Tooltips on a 25-row page, five seconds apart.
|
||||
// Keyed on the email rather than the row object, because a push replaces the row
|
||||
// object of every client whose counters moved; the page resolves the live row.
|
||||
export const ClientRowActions = memo(function ClientRowActions({
|
||||
email,
|
||||
onShowQr,
|
||||
onShowInfo,
|
||||
onResetTraffic,
|
||||
onEdit,
|
||||
onDelete,
|
||||
}: ClientRowActionsProps) {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<Space size={4}>
|
||||
<Tooltip title={t('pages.clients.qrCode')}>
|
||||
<Button
|
||||
size="small"
|
||||
type="text"
|
||||
style={ICON_BUTTON_STYLE}
|
||||
icon={<QrcodeOutlined />}
|
||||
aria-label={t('pages.clients.qrCode')}
|
||||
onClick={() => onShowQr(email)}
|
||||
/>
|
||||
</Tooltip>
|
||||
<Tooltip title={t('pages.clients.clientInfo')}>
|
||||
<Button
|
||||
size="small"
|
||||
type="text"
|
||||
style={ICON_BUTTON_STYLE}
|
||||
icon={<InfoCircleOutlined />}
|
||||
aria-label={t('pages.clients.clientInfo')}
|
||||
onClick={() => onShowInfo(email)}
|
||||
/>
|
||||
</Tooltip>
|
||||
<Tooltip title={t('pages.inbounds.resetTraffic')}>
|
||||
<Button
|
||||
size="small"
|
||||
type="text"
|
||||
style={ICON_BUTTON_STYLE}
|
||||
icon={<RetweetOutlined />}
|
||||
aria-label={t('pages.inbounds.resetTraffic')}
|
||||
onClick={() => onResetTraffic(email)}
|
||||
/>
|
||||
</Tooltip>
|
||||
<Tooltip title={t('edit')}>
|
||||
<Button
|
||||
size="small"
|
||||
type="text"
|
||||
style={ICON_BUTTON_STYLE}
|
||||
icon={<EditOutlined />}
|
||||
aria-label={t('edit')}
|
||||
onClick={() => onEdit(email)}
|
||||
/>
|
||||
</Tooltip>
|
||||
<Tooltip title={t('delete')}>
|
||||
<Button
|
||||
size="small"
|
||||
type="text"
|
||||
danger
|
||||
style={ICON_BUTTON_STYLE}
|
||||
icon={<DeleteOutlined />}
|
||||
aria-label={t('delete')}
|
||||
onClick={() => onDelete(email)}
|
||||
/>
|
||||
</Tooltip>
|
||||
</Space>
|
||||
);
|
||||
});
|
||||
|
||||
const CHIP_STYLE = { margin: 2 } as const;
|
||||
const OVERFLOW_CHIP_STYLE = { margin: 2, cursor: 'pointer' } as const;
|
||||
const OVERFLOW_LIST_STYLE = {
|
||||
display: 'flex',
|
||||
flexDirection: 'column' as const,
|
||||
gap: 4,
|
||||
maxWidth: 280,
|
||||
maxHeight: 280,
|
||||
overflowY: 'auto' as const,
|
||||
};
|
||||
|
||||
interface ClientInboundChipsProps {
|
||||
ids: number[];
|
||||
inboundsById: Record<number, InboundOption>;
|
||||
protocolColors: Record<string, string>;
|
||||
chipLimit: number;
|
||||
}
|
||||
|
||||
// Attachments never change on a traffic push either, so the same memoisation
|
||||
// applies: one Tooltip per visible chip plus a Popover for the overflow.
|
||||
export const ClientInboundChips = memo(function ClientInboundChips({
|
||||
ids,
|
||||
inboundsById,
|
||||
protocolColors,
|
||||
chipLimit,
|
||||
}: ClientInboundChipsProps) {
|
||||
if (ids.length === 0) return <span className="cell-empty">—</span>;
|
||||
|
||||
const label = (id: number) => {
|
||||
const ib = inboundsById[id];
|
||||
return formatInboundLabel(ib?.tag, ib?.remark);
|
||||
};
|
||||
const chip = (id: number) => {
|
||||
const proto = (inboundsById[id]?.protocol || '').toLowerCase();
|
||||
return (
|
||||
<Tooltip key={id} title={label(id)}>
|
||||
<Tag color={protocolColors[proto] ?? 'default'} style={CHIP_STYLE}>{label(id)}</Tag>
|
||||
</Tooltip>
|
||||
);
|
||||
};
|
||||
|
||||
const visible = ids.slice(0, chipLimit);
|
||||
const overflow = ids.slice(chipLimit);
|
||||
return (
|
||||
<>
|
||||
{visible.map(chip)}
|
||||
{overflow.length > 0 && (
|
||||
<Popover
|
||||
trigger="click"
|
||||
placement="bottomRight"
|
||||
content={<div style={OVERFLOW_LIST_STYLE}>{overflow.map(chip)}</div>}
|
||||
>
|
||||
<Tag color="default" style={OVERFLOW_CHIP_STYLE}>+{overflow.length}</Tag>
|
||||
</Popover>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user