feat: Удалить логику блокировок и обновить логику загрузки данных в менеджерах ASNs, Domains и IPRanges, улучшив фильтрацию и пагинацию для локального отображения
Publish Fast Tabler Docker image / build-and-push-fast (push) Successful in 1m55s
Publish Fast Tabler Docker image / build-and-push-fast (push) Successful in 1m55s
This commit is contained in:
@@ -96,29 +96,15 @@ function DomainsNewManager() {
|
||||
const [wsUrl, setWsUrl] = useState('');
|
||||
|
||||
useEffect(() => {
|
||||
// Acquire soft lock
|
||||
const owner = localStorage.getItem('uiOwner') || `ui-${Math.random().toString(36).slice(2,8)}`;
|
||||
localStorage.setItem('uiOwner', owner);
|
||||
const resource = 'domains-new';
|
||||
const acquire = async () => {
|
||||
try { await api.post(`/locks/${resource}`, { owner, ttlSeconds: 180 }); } catch {}
|
||||
};
|
||||
acquire();
|
||||
const interval = setInterval(acquire, 60_000);
|
||||
(async () => { try { const r = await api.get('/ws/url'); setWsUrl(String(r.data?.url || '')); } catch {} })();
|
||||
return () => {
|
||||
clearInterval(interval);
|
||||
api.delete(`/locks/${resource}`).catch(() => {});
|
||||
};
|
||||
}, []);
|
||||
|
||||
const fetchItems = async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const effectiveQ = searchTerm ? searchTerm : (filterCommunity ? filterCommunity : '');
|
||||
const response = await api.get(`/domains-new`, { params: { q: effectiveQ, offset: Math.max(0, (currentPage - 1) * pageSize), limit: pageSize, format: 'std' } });
|
||||
const response = await api.get(`/domains-new`, { params: { offset: 0, limit: 0, format: 'std' } });
|
||||
const payload = Array.isArray(response.data?.items) ? response.data.items : [];
|
||||
const total = Number(response.data?.total ?? (Array.isArray(response.data) ? response.data.length : 0));
|
||||
const total = payload.length;
|
||||
setItems(payload);
|
||||
setOriginalItems(payload);
|
||||
setTotalItems(Number.isFinite(total) ? total : 0);
|
||||
@@ -136,13 +122,7 @@ function DomainsNewManager() {
|
||||
};
|
||||
|
||||
// Подгрузка при изменении страницы/поиска/фильтра
|
||||
useEffect(() => {
|
||||
if (!didInit.current) { didInit.current = true; fetchItems(); return; }
|
||||
if (searchTimer.current) clearTimeout(searchTimer.current);
|
||||
searchTimer.current = setTimeout(() => { fetchItems(); }, 350);
|
||||
return () => { if (searchTimer.current) clearTimeout(searchTimer.current); };
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [currentPage, searchTerm, filterCommunity]);
|
||||
useEffect(() => { if (!didInit.current) { didInit.current = true; fetchItems(); } }, []);
|
||||
|
||||
const handleAddItem = () => {
|
||||
const domainOk = isValidDomain(newItem.domain);
|
||||
@@ -374,14 +354,15 @@ function DomainsNewManager() {
|
||||
return 0;
|
||||
});
|
||||
|
||||
// Дополнительная локальная фильтрация по community только если одновременно задан поиск (сервер фильтрует по q)
|
||||
const filteredByCommunity = searchTerm && filterCommunity
|
||||
? sortedItems.filter(i => i.community === filterCommunity)
|
||||
: sortedItems;
|
||||
|
||||
// Пагинация теперь серверная: на странице уже items
|
||||
const paginatedItems = filteredByCommunity;
|
||||
const totalPages = Math.max(1, Math.ceil((totalItems || paginatedItems.length) / pageSize));
|
||||
// Локальная фильтрация и пагинация
|
||||
const filtered = sortedItems.filter(i => {
|
||||
const byCommunity = !filterCommunity || i.community === filterCommunity;
|
||||
const term = String(searchTerm || '').toLowerCase();
|
||||
const bySearch = !term || String(i.domain).toLowerCase().includes(term);
|
||||
return byCommunity && bySearch;
|
||||
});
|
||||
const totalPages = Math.max(1, Math.ceil(filtered.length / pageSize));
|
||||
const paginatedItems = filtered.slice((currentPage - 1) * pageSize, (currentPage) * pageSize);
|
||||
|
||||
// Для фильтра - список всех уникальных community
|
||||
const allCommunities = Array.from(new Set(items.map(i => i.community)));
|
||||
|
||||
Reference in New Issue
Block a user