[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
@@ -18,11 +18,14 @@ import type {
|
||||
} from "@tanstack/react-query";
|
||||
|
||||
import type {
|
||||
CrawlerStatsParams,
|
||||
HTTPValidationError,
|
||||
ListSitesParams,
|
||||
ListUsersParams,
|
||||
ResCrawlerStats,
|
||||
ResOpsSites,
|
||||
ResOpsUsers,
|
||||
SiteCrawlerStatsParams,
|
||||
} from ".././model";
|
||||
|
||||
import { customFetch } from "../../mutator/custom-fetch";
|
||||
@@ -312,3 +315,334 @@ export function useListUsers<
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
/**
|
||||
* @summary 전체 크롤러 통계(개발자 전용)
|
||||
*/
|
||||
export const crawlerStats = (
|
||||
params?: CrawlerStatsParams,
|
||||
options?: SecondParameter<typeof customFetch>,
|
||||
signal?: AbortSignal,
|
||||
) => {
|
||||
return customFetch<ResCrawlerStats>(
|
||||
{ url: `/v1/ops/stats/crawlers`, method: "GET", params, signal },
|
||||
options,
|
||||
);
|
||||
};
|
||||
|
||||
export const getCrawlerStatsQueryKey = (params?: CrawlerStatsParams) => {
|
||||
return [`/v1/ops/stats/crawlers`, ...(params ? [params] : [])] as const;
|
||||
};
|
||||
|
||||
export const getCrawlerStatsQueryOptions = <
|
||||
TData = Awaited<ReturnType<typeof crawlerStats>>,
|
||||
TError = HTTPValidationError,
|
||||
>(
|
||||
params?: CrawlerStatsParams,
|
||||
options?: {
|
||||
query?: Partial<
|
||||
UseQueryOptions<Awaited<ReturnType<typeof crawlerStats>>, TError, TData>
|
||||
>;
|
||||
request?: SecondParameter<typeof customFetch>;
|
||||
},
|
||||
) => {
|
||||
const { query: queryOptions, request: requestOptions } = options ?? {};
|
||||
|
||||
const queryKey = queryOptions?.queryKey ?? getCrawlerStatsQueryKey(params);
|
||||
|
||||
const queryFn: QueryFunction<Awaited<ReturnType<typeof crawlerStats>>> = ({
|
||||
signal,
|
||||
}) => crawlerStats(params, requestOptions, signal);
|
||||
|
||||
return { queryKey, queryFn, ...queryOptions } as UseQueryOptions<
|
||||
Awaited<ReturnType<typeof crawlerStats>>,
|
||||
TError,
|
||||
TData
|
||||
> & { queryKey: DataTag<QueryKey, TData, TError> };
|
||||
};
|
||||
|
||||
export type CrawlerStatsQueryResult = NonNullable<
|
||||
Awaited<ReturnType<typeof crawlerStats>>
|
||||
>;
|
||||
export type CrawlerStatsQueryError = HTTPValidationError;
|
||||
|
||||
export function useCrawlerStats<
|
||||
TData = Awaited<ReturnType<typeof crawlerStats>>,
|
||||
TError = HTTPValidationError,
|
||||
>(
|
||||
params: undefined | CrawlerStatsParams,
|
||||
options: {
|
||||
query: Partial<
|
||||
UseQueryOptions<Awaited<ReturnType<typeof crawlerStats>>, TError, TData>
|
||||
> &
|
||||
Pick<
|
||||
DefinedInitialDataOptions<
|
||||
Awaited<ReturnType<typeof crawlerStats>>,
|
||||
TError,
|
||||
Awaited<ReturnType<typeof crawlerStats>>
|
||||
>,
|
||||
"initialData"
|
||||
>;
|
||||
request?: SecondParameter<typeof customFetch>;
|
||||
},
|
||||
queryClient?: QueryClient,
|
||||
): DefinedUseQueryResult<TData, TError> & {
|
||||
queryKey: DataTag<QueryKey, TData, TError>;
|
||||
};
|
||||
export function useCrawlerStats<
|
||||
TData = Awaited<ReturnType<typeof crawlerStats>>,
|
||||
TError = HTTPValidationError,
|
||||
>(
|
||||
params?: CrawlerStatsParams,
|
||||
options?: {
|
||||
query?: Partial<
|
||||
UseQueryOptions<Awaited<ReturnType<typeof crawlerStats>>, TError, TData>
|
||||
> &
|
||||
Pick<
|
||||
UndefinedInitialDataOptions<
|
||||
Awaited<ReturnType<typeof crawlerStats>>,
|
||||
TError,
|
||||
Awaited<ReturnType<typeof crawlerStats>>
|
||||
>,
|
||||
"initialData"
|
||||
>;
|
||||
request?: SecondParameter<typeof customFetch>;
|
||||
},
|
||||
queryClient?: QueryClient,
|
||||
): UseQueryResult<TData, TError> & {
|
||||
queryKey: DataTag<QueryKey, TData, TError>;
|
||||
};
|
||||
export function useCrawlerStats<
|
||||
TData = Awaited<ReturnType<typeof crawlerStats>>,
|
||||
TError = HTTPValidationError,
|
||||
>(
|
||||
params?: CrawlerStatsParams,
|
||||
options?: {
|
||||
query?: Partial<
|
||||
UseQueryOptions<Awaited<ReturnType<typeof crawlerStats>>, TError, TData>
|
||||
>;
|
||||
request?: SecondParameter<typeof customFetch>;
|
||||
},
|
||||
queryClient?: QueryClient,
|
||||
): UseQueryResult<TData, TError> & {
|
||||
queryKey: DataTag<QueryKey, TData, TError>;
|
||||
};
|
||||
/**
|
||||
* @summary 전체 크롤러 통계(개발자 전용)
|
||||
*/
|
||||
|
||||
export function useCrawlerStats<
|
||||
TData = Awaited<ReturnType<typeof crawlerStats>>,
|
||||
TError = HTTPValidationError,
|
||||
>(
|
||||
params?: CrawlerStatsParams,
|
||||
options?: {
|
||||
query?: Partial<
|
||||
UseQueryOptions<Awaited<ReturnType<typeof crawlerStats>>, TError, TData>
|
||||
>;
|
||||
request?: SecondParameter<typeof customFetch>;
|
||||
},
|
||||
queryClient?: QueryClient,
|
||||
): UseQueryResult<TData, TError> & {
|
||||
queryKey: DataTag<QueryKey, TData, TError>;
|
||||
} {
|
||||
const queryOptions = getCrawlerStatsQueryOptions(params, options);
|
||||
|
||||
const query = useQuery(queryOptions, queryClient) as UseQueryResult<
|
||||
TData,
|
||||
TError
|
||||
> & { queryKey: DataTag<QueryKey, TData, TError> };
|
||||
|
||||
query.queryKey = queryOptions.queryKey;
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
/**
|
||||
* @summary 사이트별 크롤러 통계(개발자 전용)
|
||||
*/
|
||||
export const siteCrawlerStats = (
|
||||
placeId: string,
|
||||
params?: SiteCrawlerStatsParams,
|
||||
options?: SecondParameter<typeof customFetch>,
|
||||
signal?: AbortSignal,
|
||||
) => {
|
||||
return customFetch<ResCrawlerStats>(
|
||||
{
|
||||
url: `/v1/ops/sites/${placeId}/stats/crawlers`,
|
||||
method: "GET",
|
||||
params,
|
||||
signal,
|
||||
},
|
||||
options,
|
||||
);
|
||||
};
|
||||
|
||||
export const getSiteCrawlerStatsQueryKey = (
|
||||
placeId?: string,
|
||||
params?: SiteCrawlerStatsParams,
|
||||
) => {
|
||||
return [
|
||||
`/v1/ops/sites/${placeId}/stats/crawlers`,
|
||||
...(params ? [params] : []),
|
||||
] as const;
|
||||
};
|
||||
|
||||
export const getSiteCrawlerStatsQueryOptions = <
|
||||
TData = Awaited<ReturnType<typeof siteCrawlerStats>>,
|
||||
TError = HTTPValidationError,
|
||||
>(
|
||||
placeId: string,
|
||||
params?: SiteCrawlerStatsParams,
|
||||
options?: {
|
||||
query?: Partial<
|
||||
UseQueryOptions<
|
||||
Awaited<ReturnType<typeof siteCrawlerStats>>,
|
||||
TError,
|
||||
TData
|
||||
>
|
||||
>;
|
||||
request?: SecondParameter<typeof customFetch>;
|
||||
},
|
||||
) => {
|
||||
const { query: queryOptions, request: requestOptions } = options ?? {};
|
||||
|
||||
const queryKey =
|
||||
queryOptions?.queryKey ?? getSiteCrawlerStatsQueryKey(placeId, params);
|
||||
|
||||
const queryFn: QueryFunction<
|
||||
Awaited<ReturnType<typeof siteCrawlerStats>>
|
||||
> = ({ signal }) => siteCrawlerStats(placeId, params, requestOptions, signal);
|
||||
|
||||
return {
|
||||
queryKey,
|
||||
queryFn,
|
||||
enabled: !!placeId,
|
||||
...queryOptions,
|
||||
} as UseQueryOptions<
|
||||
Awaited<ReturnType<typeof siteCrawlerStats>>,
|
||||
TError,
|
||||
TData
|
||||
> & { queryKey: DataTag<QueryKey, TData, TError> };
|
||||
};
|
||||
|
||||
export type SiteCrawlerStatsQueryResult = NonNullable<
|
||||
Awaited<ReturnType<typeof siteCrawlerStats>>
|
||||
>;
|
||||
export type SiteCrawlerStatsQueryError = HTTPValidationError;
|
||||
|
||||
export function useSiteCrawlerStats<
|
||||
TData = Awaited<ReturnType<typeof siteCrawlerStats>>,
|
||||
TError = HTTPValidationError,
|
||||
>(
|
||||
placeId: string,
|
||||
params: undefined | SiteCrawlerStatsParams,
|
||||
options: {
|
||||
query: Partial<
|
||||
UseQueryOptions<
|
||||
Awaited<ReturnType<typeof siteCrawlerStats>>,
|
||||
TError,
|
||||
TData
|
||||
>
|
||||
> &
|
||||
Pick<
|
||||
DefinedInitialDataOptions<
|
||||
Awaited<ReturnType<typeof siteCrawlerStats>>,
|
||||
TError,
|
||||
Awaited<ReturnType<typeof siteCrawlerStats>>
|
||||
>,
|
||||
"initialData"
|
||||
>;
|
||||
request?: SecondParameter<typeof customFetch>;
|
||||
},
|
||||
queryClient?: QueryClient,
|
||||
): DefinedUseQueryResult<TData, TError> & {
|
||||
queryKey: DataTag<QueryKey, TData, TError>;
|
||||
};
|
||||
export function useSiteCrawlerStats<
|
||||
TData = Awaited<ReturnType<typeof siteCrawlerStats>>,
|
||||
TError = HTTPValidationError,
|
||||
>(
|
||||
placeId: string,
|
||||
params?: SiteCrawlerStatsParams,
|
||||
options?: {
|
||||
query?: Partial<
|
||||
UseQueryOptions<
|
||||
Awaited<ReturnType<typeof siteCrawlerStats>>,
|
||||
TError,
|
||||
TData
|
||||
>
|
||||
> &
|
||||
Pick<
|
||||
UndefinedInitialDataOptions<
|
||||
Awaited<ReturnType<typeof siteCrawlerStats>>,
|
||||
TError,
|
||||
Awaited<ReturnType<typeof siteCrawlerStats>>
|
||||
>,
|
||||
"initialData"
|
||||
>;
|
||||
request?: SecondParameter<typeof customFetch>;
|
||||
},
|
||||
queryClient?: QueryClient,
|
||||
): UseQueryResult<TData, TError> & {
|
||||
queryKey: DataTag<QueryKey, TData, TError>;
|
||||
};
|
||||
export function useSiteCrawlerStats<
|
||||
TData = Awaited<ReturnType<typeof siteCrawlerStats>>,
|
||||
TError = HTTPValidationError,
|
||||
>(
|
||||
placeId: string,
|
||||
params?: SiteCrawlerStatsParams,
|
||||
options?: {
|
||||
query?: Partial<
|
||||
UseQueryOptions<
|
||||
Awaited<ReturnType<typeof siteCrawlerStats>>,
|
||||
TError,
|
||||
TData
|
||||
>
|
||||
>;
|
||||
request?: SecondParameter<typeof customFetch>;
|
||||
},
|
||||
queryClient?: QueryClient,
|
||||
): UseQueryResult<TData, TError> & {
|
||||
queryKey: DataTag<QueryKey, TData, TError>;
|
||||
};
|
||||
/**
|
||||
* @summary 사이트별 크롤러 통계(개발자 전용)
|
||||
*/
|
||||
|
||||
export function useSiteCrawlerStats<
|
||||
TData = Awaited<ReturnType<typeof siteCrawlerStats>>,
|
||||
TError = HTTPValidationError,
|
||||
>(
|
||||
placeId: string,
|
||||
params?: SiteCrawlerStatsParams,
|
||||
options?: {
|
||||
query?: Partial<
|
||||
UseQueryOptions<
|
||||
Awaited<ReturnType<typeof siteCrawlerStats>>,
|
||||
TError,
|
||||
TData
|
||||
>
|
||||
>;
|
||||
request?: SecondParameter<typeof customFetch>;
|
||||
},
|
||||
queryClient?: QueryClient,
|
||||
): UseQueryResult<TData, TError> & {
|
||||
queryKey: DataTag<QueryKey, TData, TError>;
|
||||
} {
|
||||
const queryOptions = getSiteCrawlerStatsQueryOptions(
|
||||
placeId,
|
||||
params,
|
||||
options,
|
||||
);
|
||||
|
||||
const query = useQuery(queryOptions, queryClient) as UseQueryResult<
|
||||
TData,
|
||||
TError
|
||||
> & { queryKey: DataTag<QueryKey, TData, TError> };
|
||||
|
||||
query.queryKey = queryOptions.queryKey;
|
||||
|
||||
return query;
|
||||
}
|
||||
Reference in new issue
Block a user