- 사이트관리에 "목록 / 전체 통계" 탭(?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 까지만 확인.
35 lines
1.7 KiB
TypeScript
35 lines
1.7 KiB
TypeScript
import {Bar, BarChart, CartesianGrid, Legend, ResponsiveContainer, Tooltip, XAxis, YAxis} from 'recharts';
|
|
import type {CrawlerDaily} from '@/api';
|
|
import {PURPOSE_COLOR, PURPOSES, purposeLabel} from './labels';
|
|
import {daysBetween} from './range';
|
|
|
|
// recharts 는 행 하나를 {day, search: n, training: n, …} 로 받는다.
|
|
type Row = Record<string, string | number>;
|
|
|
|
function pivot(daily: CrawlerDaily[], from: string, to: string): Row[] {
|
|
const rows = new Map<string, Row>(daysBetween(from, to).map((day) => [day, {day}]));
|
|
for (const {day, purpose, hits} of daily) {
|
|
const row = rows.get(day);
|
|
if (row) row[purpose] = Number(row[purpose] ?? 0) + hits;
|
|
}
|
|
return [...rows.values()];
|
|
}
|
|
|
|
/** recharts 를 이 파일에만 둔다 — CrawlerStatsPanel 이 lazy() 로 불러 사장님 화면 번들에 안 들어간다. */
|
|
export default function CrawlerDailyChart({daily, from, to}: {daily: CrawlerDaily[]; from: string; to: string}) {
|
|
return (
|
|
<ResponsiveContainer width="100%" height={240}>
|
|
<BarChart data={pivot(daily, from, to)} margin={{top: 8, right: 8, bottom: 0, left: 0}}>
|
|
<CartesianGrid strokeDasharray="3 3" vertical={false} />
|
|
<XAxis dataKey="day" tickFormatter={(day: string) => day.slice(5)} fontSize={11} />
|
|
<YAxis allowDecimals={false} fontSize={11} width={32} />
|
|
<Tooltip formatter={(value, name) => [value, purposeLabel(String(name))]} />
|
|
<Legend formatter={(value) => purposeLabel(String(value))} wrapperStyle={{fontSize: 11}} />
|
|
{PURPOSES.map((purpose) => (
|
|
<Bar key={purpose} dataKey={purpose} stackId="hits" fill={PURPOSE_COLOR[purpose]} />
|
|
))}
|
|
</BarChart>
|
|
</ResponsiveContainer>
|
|
);
|
|
}
|