[feat] solution/frontend: 사이트관리 크롤러 통계 — 전체 통계 탭과 사이트별 페이지, recharts 지연 로드
- 사이트관리에 "목록 / 전체 통계" 탭(?tab=stats)과 각 행의 "통계" 버튼(/ops/sites/:placeId/stats) - 크롤링 화면: 요약 카드 → 일별 누적 막대(용도 4분류+기타) → 봇별 → (전체) 사이트 순위·robots/sitemap· 기타 UA, (사이트별) 많이 읽힌 페이지·최근 50건. 기간 7/30/90일 - recharts 는 CrawlerDailyChart 한 파일에만 두고 lazy() 로 부른다 — 빌드 확인: 그 청크에만 있고 사장님 화면의 첫 로딩 스크립트에는 없다 - OpsSitesPage 는 기존 목록 코드를 다시 들여쓰지 않으려고, stats 탭이면 앞에서 바로 return 하고 탭 UI 는 SitesTabs 로 분리했다(+29/-3) - orval 로 API 클라이언트 재생성 — 줄바꿈(LF/CRLF)만 바뀐 생성 파일 약 90개는 되돌리고 실제 변경분만 담았다 lint(typegen·tsc·eslint)·build 통과. 화면 레이아웃·차트는 브라우저로 직접 보지 못했다(확장 미연결) — nginx 경유 API 호출과 SPA 라우트 200 까지만 확인.
This commit is contained in:
1 parent
d9c9952230
commit
cae3de5586
33 files changed
+1470
-75
No files matched your search
@@ -1,13 +1,15 @@
|
||||
import {useState} from 'react';
|
||||
import {Link, Navigate} from 'react-router';
|
||||
import {Link, Navigate, useSearchParams} from 'react-router';
|
||||
import {keepPreviousData} from '@tanstack/react-query';
|
||||
import {Building2, ChevronLeft, ChevronRight, ExternalLink, Loader2, Newspaper, Pencil, Search, Trash2, X} from 'lucide-react';
|
||||
import {BarChart3, Building2, ChevronLeft, ChevronRight, ExternalLink, Loader2, Newspaper, Pencil, Search, Trash2, X} from 'lucide-react';
|
||||
import {PlaceCategory, publishUrlString, SiteStatus} from '@o2o/shared';
|
||||
import {changeStatus, deletePlace, PublishAction, UserRole, useListSites, type OpsSiteData} from '@/api';
|
||||
import {AppShell, EmptyState, PageContainer} from '@/components/layout/AppShell';
|
||||
import {Badge} from '@/components/ui/badge';
|
||||
import {Button} from '@/components/ui/button';
|
||||
import {Input} from '@/components/ui/input';
|
||||
import {OverallCrawlerStats} from '@/features/ops-stats/OverallCrawlerStats';
|
||||
import {SitesTabs, type SitesTab} from '@/features/ops-stats/SitesTabs';
|
||||
import {notify, notifyApiError} from '@/lib/notify';
|
||||
import {PUBLISH_HOST} from '@/lib/site';
|
||||
import {cn} from '@/lib/utils';
|
||||
@@ -45,11 +47,15 @@ export function OpsSitesPage() {
|
||||
const [search, setSearch] = useState('');
|
||||
const [category, setCategory] = useState<number | null>(null);
|
||||
const [busyId, setBusyId] = useState<string | null>(null);
|
||||
// 탭을 URL 에 둔다 — 사이트별 통계에서 뒤로 오면 보던 탭으로 돌아온다.
|
||||
const [params, setParams] = useSearchParams();
|
||||
const tab: SitesTab = params.get('tab') === 'stats' ? 'stats' : 'list';
|
||||
const changeTab = (next: SitesTab) => setParams(next === 'list' ? {} : {tab: next});
|
||||
const size = 20;
|
||||
// enabled: role 이 확정되기 전엔 요청하지 않는다 — 어차피 백엔드가 403 으로 막지만, 사장님 화면에서 실패 토스트가 먼저 뜨는 것과 새로고침 때 잠깐의 오탐 리다이렉트를 막는다.
|
||||
const {data, isLoading, isError, error, refetch} = useListSites(
|
||||
{page, size, search: search || undefined, category: category ?? undefined},
|
||||
{query: {placeholderData: keepPreviousData, enabled: role === UserRole.DEVELOPER}},
|
||||
{query: {placeholderData: keepPreviousData, enabled: role === UserRole.DEVELOPER && tab === 'list'}},
|
||||
);
|
||||
|
||||
// RequireAuth 와 같은 이유 — 복구가 끝나기 전에 판단하면 새로고침마다 리다이렉트가 한 번 번쩍인다.
|
||||
@@ -85,6 +91,17 @@ export function OpsSitesPage() {
|
||||
if (isRestoring) return null;
|
||||
if (role !== UserRole.DEVELOPER) return <Navigate to="/sites" replace />;
|
||||
|
||||
if (tab === 'stats') {
|
||||
return (
|
||||
<AppShell>
|
||||
<PageContainer title="사이트관리" description="전 계정 사이트 발행 현황입니다. 회사 스코프 없이 전부 보입니다.">
|
||||
<SitesTabs tab={tab} onChange={changeTab} />
|
||||
<OverallCrawlerStats />
|
||||
</PageContainer>
|
||||
</AppShell>
|
||||
);
|
||||
}
|
||||
|
||||
const rows = data?.sites ?? [];
|
||||
const total = data?.total ?? 0;
|
||||
const lastPage = Math.max(1, Math.ceil(total / size));
|
||||
@@ -121,6 +138,7 @@ export function OpsSitesPage() {
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<SitesTabs tab={tab} onChange={changeTab} />
|
||||
<div className="mb-3 flex flex-wrap gap-1.5">
|
||||
{[null, ...Object.keys(CATEGORY_LABEL).map(Number)].map((value) => (
|
||||
<button
|
||||
@@ -193,6 +211,13 @@ export function OpsSitesPage() {
|
||||
<Newspaper className="size-3.5" />
|
||||
미니블로그
|
||||
</Link>
|
||||
<Link
|
||||
to={`/ops/sites/${row.place_id}/stats`}
|
||||
className="inline-flex h-8 items-center gap-1.5 rounded-md border border-border px-2.5 text-xs font-medium transition-colors hover:bg-muted"
|
||||
>
|
||||
<BarChart3 className="size-3.5" />
|
||||
통계
|
||||
</Link>
|
||||
{url ? (
|
||||
<a
|
||||
href={url}
|
||||
|
||||
Reference in new issue
Block a user