diff --git a/solution/frontend/src/api/generated/model/index.ts b/solution/frontend/src/api/generated/model/index.ts index 28698a6..53e0c3a 100644 --- a/solution/frontend/src/api/generated/model/index.ts +++ b/solution/frontend/src/api/generated/model/index.ts @@ -401,6 +401,10 @@ export * from "./resVerifyCandidates"; export * from "./resVerifyCandidatesMsg"; export * from "./resVerifyCandidatesReason"; export * from "./resVerifyCandidatesSource"; +export * from "./resVisitStats"; +export * from "./resVisitStatsDateFrom"; +export * from "./resVisitStatsDateTo"; +export * from "./resVisitStatsMsg"; export * from "./resWeather"; export * from "./resWeatherMsg"; export * from "./resWeatherWeather"; @@ -424,6 +428,7 @@ export * from "./siteVersionData"; export * from "./siteVersionDataBuildError"; export * from "./siteVersionDataBuiltAt"; export * from "./siteVersionDataCreatedAt"; +export * from "./siteVisitStatsParams"; export * from "./sourceType"; export * from "./testPost"; export * from "./unitData"; @@ -433,6 +438,15 @@ export * from "./validationError"; export * from "./validationErrorCtx"; export * from "./validationErrorLocItem"; export * from "./verifyCandidatesParams"; +export * from "./visitDaily"; +export * from "./visitDeviceRow"; +export * from "./visitPathRow"; +export * from "./visitReferrerRow"; +export * from "./visitSiteRow"; +export * from "./visitStatsParams"; +export * from "./visitSummary"; +export * from "./visitSummaryLastAt"; +export * from "./visitUtmRow"; export * from "./weatherData"; export * from "./weatherDataTimezone"; export * from "./weatherDataWindSpeed"; diff --git a/solution/frontend/src/api/generated/model/resVisitStats.ts b/solution/frontend/src/api/generated/model/resVisitStats.ts new file mode 100644 index 0000000..47382be --- /dev/null +++ b/solution/frontend/src/api/generated/model/resVisitStats.ts @@ -0,0 +1,35 @@ +/** + * Generated by orval v7.21.0 ๐Ÿบ + * Do not edit manually. + * Web4Ai API + * OpenAPI spec version: 0.1.0 + */ +import type { ErrorInfo } from "./errorInfo"; +import type { ResVisitStatsMsg } from "./resVisitStatsMsg"; +import type { ResVisitStatsDateFrom } from "./resVisitStatsDateFrom"; +import type { ResVisitStatsDateTo } from "./resVisitStatsDateTo"; +import type { VisitSummary } from "./visitSummary"; +import type { VisitDaily } from "./visitDaily"; +import type { VisitSiteRow } from "./visitSiteRow"; +import type { VisitPathRow } from "./visitPathRow"; +import type { VisitReferrerRow } from "./visitReferrerRow"; +import type { VisitUtmRow } from "./visitUtmRow"; +import type { VisitDeviceRow } from "./visitDeviceRow"; + +/** + * ์ „์ฒด(sites)์™€ ์‚ฌ์ดํŠธ๋ณ„(pagesยทutm)์ด ๊ฐ™์€ ๋ชจ๋ธ์„ ์“ด๋‹ค โ€” ํ•ด๋‹น ์—†๋Š” ์นธ์€ ๋น„์–ด ์žˆ๋‹ค. + */ +export interface ResVisitStats { + result?: ErrorInfo; + msg?: ResVisitStatsMsg; + date_from?: ResVisitStatsDateFrom; + date_to?: ResVisitStatsDateTo; + realtime?: number; + summary?: VisitSummary; + daily?: VisitDaily[]; + sites?: VisitSiteRow[]; + pages?: VisitPathRow[]; + referrers?: VisitReferrerRow[]; + utm?: VisitUtmRow[]; + devices?: VisitDeviceRow[]; +} diff --git a/solution/frontend/src/api/generated/model/resVisitStatsDateFrom.ts b/solution/frontend/src/api/generated/model/resVisitStatsDateFrom.ts new file mode 100644 index 0000000..14719d4 --- /dev/null +++ b/solution/frontend/src/api/generated/model/resVisitStatsDateFrom.ts @@ -0,0 +1,8 @@ +/** + * Generated by orval v7.21.0 ๐Ÿบ + * Do not edit manually. + * Web4Ai API + * OpenAPI spec version: 0.1.0 + */ + +export type ResVisitStatsDateFrom = string | null; diff --git a/solution/frontend/src/api/generated/model/resVisitStatsDateTo.ts b/solution/frontend/src/api/generated/model/resVisitStatsDateTo.ts new file mode 100644 index 0000000..c51781d --- /dev/null +++ b/solution/frontend/src/api/generated/model/resVisitStatsDateTo.ts @@ -0,0 +1,8 @@ +/** + * Generated by orval v7.21.0 ๐Ÿบ + * Do not edit manually. + * Web4Ai API + * OpenAPI spec version: 0.1.0 + */ + +export type ResVisitStatsDateTo = string | null; diff --git a/solution/frontend/src/api/generated/model/resVisitStatsMsg.ts b/solution/frontend/src/api/generated/model/resVisitStatsMsg.ts new file mode 100644 index 0000000..cdb6b40 --- /dev/null +++ b/solution/frontend/src/api/generated/model/resVisitStatsMsg.ts @@ -0,0 +1,8 @@ +/** + * Generated by orval v7.21.0 ๐Ÿบ + * Do not edit manually. + * Web4Ai API + * OpenAPI spec version: 0.1.0 + */ + +export type ResVisitStatsMsg = string | null; diff --git a/solution/frontend/src/api/generated/model/siteVisitStatsParams.ts b/solution/frontend/src/api/generated/model/siteVisitStatsParams.ts new file mode 100644 index 0000000..b9e6332 --- /dev/null +++ b/solution/frontend/src/api/generated/model/siteVisitStatsParams.ts @@ -0,0 +1,17 @@ +/** + * Generated by orval v7.21.0 ๐Ÿบ + * Do not edit manually. + * Web4Ai API + * OpenAPI spec version: 0.1.0 + */ + +export type SiteVisitStatsParams = { + /** + * KST ๋‚ ์งœ, ๊ธฐ๋ณธ to-6์ผ + */ + from?: string | null; + /** + * KST ๋‚ ์งœ, ๊ธฐ๋ณธ ์˜ค๋Š˜ + */ + to?: string | null; +}; diff --git a/solution/frontend/src/api/generated/model/visitDaily.ts b/solution/frontend/src/api/generated/model/visitDaily.ts new file mode 100644 index 0000000..357da4c --- /dev/null +++ b/solution/frontend/src/api/generated/model/visitDaily.ts @@ -0,0 +1,12 @@ +/** + * Generated by orval v7.21.0 ๐Ÿบ + * Do not edit manually. + * Web4Ai API + * OpenAPI spec version: 0.1.0 + */ + +export interface VisitDaily { + day: string; + views: number; + visitors: number; +} diff --git a/solution/frontend/src/api/generated/model/visitDeviceRow.ts b/solution/frontend/src/api/generated/model/visitDeviceRow.ts new file mode 100644 index 0000000..d903099 --- /dev/null +++ b/solution/frontend/src/api/generated/model/visitDeviceRow.ts @@ -0,0 +1,11 @@ +/** + * Generated by orval v7.21.0 ๐Ÿบ + * Do not edit manually. + * Web4Ai API + * OpenAPI spec version: 0.1.0 + */ + +export interface VisitDeviceRow { + device: string; + views: number; +} diff --git a/solution/frontend/src/api/generated/model/visitPathRow.ts b/solution/frontend/src/api/generated/model/visitPathRow.ts new file mode 100644 index 0000000..6b580a3 --- /dev/null +++ b/solution/frontend/src/api/generated/model/visitPathRow.ts @@ -0,0 +1,12 @@ +/** + * Generated by orval v7.21.0 ๐Ÿบ + * Do not edit manually. + * Web4Ai API + * OpenAPI spec version: 0.1.0 + */ + +export interface VisitPathRow { + path: string; + views: number; + visitors: number; +} diff --git a/solution/frontend/src/api/generated/model/visitReferrerRow.ts b/solution/frontend/src/api/generated/model/visitReferrerRow.ts new file mode 100644 index 0000000..5ea8e84 --- /dev/null +++ b/solution/frontend/src/api/generated/model/visitReferrerRow.ts @@ -0,0 +1,11 @@ +/** + * Generated by orval v7.21.0 ๐Ÿบ + * Do not edit manually. + * Web4Ai API + * OpenAPI spec version: 0.1.0 + */ + +export interface VisitReferrerRow { + domain: string; + views: number; +} diff --git a/solution/frontend/src/api/generated/model/visitSiteRow.ts b/solution/frontend/src/api/generated/model/visitSiteRow.ts new file mode 100644 index 0000000..f70f7c7 --- /dev/null +++ b/solution/frontend/src/api/generated/model/visitSiteRow.ts @@ -0,0 +1,14 @@ +/** + * Generated by orval v7.21.0 ๐Ÿบ + * Do not edit manually. + * Web4Ai API + * OpenAPI spec version: 0.1.0 + */ + +export interface VisitSiteRow { + site_id: string; + place_id: string; + name: string; + views: number; + visitors: number; +} diff --git a/solution/frontend/src/api/generated/model/visitStatsParams.ts b/solution/frontend/src/api/generated/model/visitStatsParams.ts new file mode 100644 index 0000000..82ae878 --- /dev/null +++ b/solution/frontend/src/api/generated/model/visitStatsParams.ts @@ -0,0 +1,17 @@ +/** + * Generated by orval v7.21.0 ๐Ÿบ + * Do not edit manually. + * Web4Ai API + * OpenAPI spec version: 0.1.0 + */ + +export type VisitStatsParams = { + /** + * KST ๋‚ ์งœ, ๊ธฐ๋ณธ to-6์ผ + */ + from?: string | null; + /** + * KST ๋‚ ์งœ, ๊ธฐ๋ณธ ์˜ค๋Š˜ + */ + to?: string | null; +}; diff --git a/solution/frontend/src/api/generated/model/visitSummary.ts b/solution/frontend/src/api/generated/model/visitSummary.ts new file mode 100644 index 0000000..90a2ab2 --- /dev/null +++ b/solution/frontend/src/api/generated/model/visitSummary.ts @@ -0,0 +1,13 @@ +/** + * Generated by orval v7.21.0 ๐Ÿบ + * Do not edit manually. + * Web4Ai API + * OpenAPI spec version: 0.1.0 + */ +import type { VisitSummaryLastAt } from "./visitSummaryLastAt"; + +export interface VisitSummary { + views?: number; + visitors?: number; + last_at?: VisitSummaryLastAt; +} diff --git a/solution/frontend/src/api/generated/model/visitSummaryLastAt.ts b/solution/frontend/src/api/generated/model/visitSummaryLastAt.ts new file mode 100644 index 0000000..9c9c5a2 --- /dev/null +++ b/solution/frontend/src/api/generated/model/visitSummaryLastAt.ts @@ -0,0 +1,8 @@ +/** + * Generated by orval v7.21.0 ๐Ÿบ + * Do not edit manually. + * Web4Ai API + * OpenAPI spec version: 0.1.0 + */ + +export type VisitSummaryLastAt = string | null; diff --git a/solution/frontend/src/api/generated/model/visitUtmRow.ts b/solution/frontend/src/api/generated/model/visitUtmRow.ts new file mode 100644 index 0000000..8387ec8 --- /dev/null +++ b/solution/frontend/src/api/generated/model/visitUtmRow.ts @@ -0,0 +1,11 @@ +/** + * Generated by orval v7.21.0 ๐Ÿบ + * Do not edit manually. + * Web4Ai API + * OpenAPI spec version: 0.1.0 + */ + +export interface VisitUtmRow { + source: string; + views: number; +} diff --git a/solution/frontend/src/api/generated/ops/ops.ts b/solution/frontend/src/api/generated/ops/ops.ts index 8234ab8..78a32b9 100644 --- a/solution/frontend/src/api/generated/ops/ops.ts +++ b/solution/frontend/src/api/generated/ops/ops.ts @@ -25,7 +25,10 @@ import type { ResCrawlerStats, ResOpsSites, ResOpsUsers, + ResVisitStats, SiteCrawlerStatsParams, + SiteVisitStatsParams, + VisitStatsParams, } from ".././model"; import { customFetch } from "../../mutator/custom-fetch"; @@ -646,3 +649,310 @@ export function useSiteCrawlerStats< return query; } + +/** + * @summary ์ „์ฒด ๋ฐฉ๋ฌธ ํ†ต๊ณ„(๊ฐœ๋ฐœ์ž ์ „์šฉ) + */ +export const visitStats = ( + params?: VisitStatsParams, + options?: SecondParameter, + signal?: AbortSignal, +) => { + return customFetch( + { url: `/v1/ops/stats/visits`, method: "GET", params, signal }, + options, + ); +}; + +export const getVisitStatsQueryKey = (params?: VisitStatsParams) => { + return [`/v1/ops/stats/visits`, ...(params ? [params] : [])] as const; +}; + +export const getVisitStatsQueryOptions = < + TData = Awaited>, + TError = HTTPValidationError, +>( + params?: VisitStatsParams, + options?: { + query?: Partial< + UseQueryOptions>, TError, TData> + >; + request?: SecondParameter; + }, +) => { + const { query: queryOptions, request: requestOptions } = options ?? {}; + + const queryKey = queryOptions?.queryKey ?? getVisitStatsQueryKey(params); + + const queryFn: QueryFunction>> = ({ + signal, + }) => visitStats(params, requestOptions, signal); + + return { queryKey, queryFn, ...queryOptions } as UseQueryOptions< + Awaited>, + TError, + TData + > & { queryKey: DataTag }; +}; + +export type VisitStatsQueryResult = NonNullable< + Awaited> +>; +export type VisitStatsQueryError = HTTPValidationError; + +export function useVisitStats< + TData = Awaited>, + TError = HTTPValidationError, +>( + params: undefined | VisitStatsParams, + options: { + query: Partial< + UseQueryOptions>, TError, TData> + > & + Pick< + DefinedInitialDataOptions< + Awaited>, + TError, + Awaited> + >, + "initialData" + >; + request?: SecondParameter; + }, + queryClient?: QueryClient, +): DefinedUseQueryResult & { + queryKey: DataTag; +}; +export function useVisitStats< + TData = Awaited>, + TError = HTTPValidationError, +>( + params?: VisitStatsParams, + options?: { + query?: Partial< + UseQueryOptions>, TError, TData> + > & + Pick< + UndefinedInitialDataOptions< + Awaited>, + TError, + Awaited> + >, + "initialData" + >; + request?: SecondParameter; + }, + queryClient?: QueryClient, +): UseQueryResult & { + queryKey: DataTag; +}; +export function useVisitStats< + TData = Awaited>, + TError = HTTPValidationError, +>( + params?: VisitStatsParams, + options?: { + query?: Partial< + UseQueryOptions>, TError, TData> + >; + request?: SecondParameter; + }, + queryClient?: QueryClient, +): UseQueryResult & { + queryKey: DataTag; +}; +/** + * @summary ์ „์ฒด ๋ฐฉ๋ฌธ ํ†ต๊ณ„(๊ฐœ๋ฐœ์ž ์ „์šฉ) + */ + +export function useVisitStats< + TData = Awaited>, + TError = HTTPValidationError, +>( + params?: VisitStatsParams, + options?: { + query?: Partial< + UseQueryOptions>, TError, TData> + >; + request?: SecondParameter; + }, + queryClient?: QueryClient, +): UseQueryResult & { + queryKey: DataTag; +} { + const queryOptions = getVisitStatsQueryOptions(params, options); + + const query = useQuery(queryOptions, queryClient) as UseQueryResult< + TData, + TError + > & { queryKey: DataTag }; + + query.queryKey = queryOptions.queryKey; + + return query; +} + +/** + * @summary ์‚ฌ์ดํŠธ๋ณ„ ๋ฐฉ๋ฌธ ํ†ต๊ณ„(๊ฐœ๋ฐœ์ž ์ „์šฉ) + */ +export const siteVisitStats = ( + placeId: string, + params?: SiteVisitStatsParams, + options?: SecondParameter, + signal?: AbortSignal, +) => { + return customFetch( + { + url: `/v1/ops/sites/${placeId}/stats/visits`, + method: "GET", + params, + signal, + }, + options, + ); +}; + +export const getSiteVisitStatsQueryKey = ( + placeId?: string, + params?: SiteVisitStatsParams, +) => { + return [ + `/v1/ops/sites/${placeId}/stats/visits`, + ...(params ? [params] : []), + ] as const; +}; + +export const getSiteVisitStatsQueryOptions = < + TData = Awaited>, + TError = HTTPValidationError, +>( + placeId: string, + params?: SiteVisitStatsParams, + options?: { + query?: Partial< + UseQueryOptions>, TError, TData> + >; + request?: SecondParameter; + }, +) => { + const { query: queryOptions, request: requestOptions } = options ?? {}; + + const queryKey = + queryOptions?.queryKey ?? getSiteVisitStatsQueryKey(placeId, params); + + const queryFn: QueryFunction>> = ({ + signal, + }) => siteVisitStats(placeId, params, requestOptions, signal); + + return { + queryKey, + queryFn, + enabled: !!placeId, + ...queryOptions, + } as UseQueryOptions< + Awaited>, + TError, + TData + > & { queryKey: DataTag }; +}; + +export type SiteVisitStatsQueryResult = NonNullable< + Awaited> +>; +export type SiteVisitStatsQueryError = HTTPValidationError; + +export function useSiteVisitStats< + TData = Awaited>, + TError = HTTPValidationError, +>( + placeId: string, + params: undefined | SiteVisitStatsParams, + options: { + query: Partial< + UseQueryOptions>, TError, TData> + > & + Pick< + DefinedInitialDataOptions< + Awaited>, + TError, + Awaited> + >, + "initialData" + >; + request?: SecondParameter; + }, + queryClient?: QueryClient, +): DefinedUseQueryResult & { + queryKey: DataTag; +}; +export function useSiteVisitStats< + TData = Awaited>, + TError = HTTPValidationError, +>( + placeId: string, + params?: SiteVisitStatsParams, + options?: { + query?: Partial< + UseQueryOptions>, TError, TData> + > & + Pick< + UndefinedInitialDataOptions< + Awaited>, + TError, + Awaited> + >, + "initialData" + >; + request?: SecondParameter; + }, + queryClient?: QueryClient, +): UseQueryResult & { + queryKey: DataTag; +}; +export function useSiteVisitStats< + TData = Awaited>, + TError = HTTPValidationError, +>( + placeId: string, + params?: SiteVisitStatsParams, + options?: { + query?: Partial< + UseQueryOptions>, TError, TData> + >; + request?: SecondParameter; + }, + queryClient?: QueryClient, +): UseQueryResult & { + queryKey: DataTag; +}; +/** + * @summary ์‚ฌ์ดํŠธ๋ณ„ ๋ฐฉ๋ฌธ ํ†ต๊ณ„(๊ฐœ๋ฐœ์ž ์ „์šฉ) + */ + +export function useSiteVisitStats< + TData = Awaited>, + TError = HTTPValidationError, +>( + placeId: string, + params?: SiteVisitStatsParams, + options?: { + query?: Partial< + UseQueryOptions>, TError, TData> + >; + request?: SecondParameter; + }, + queryClient?: QueryClient, +): UseQueryResult & { + queryKey: DataTag; +} { + const queryOptions = getSiteVisitStatsQueryOptions(placeId, params, options); + + const query = useQuery(queryOptions, queryClient) as UseQueryResult< + TData, + TError + > & { queryKey: DataTag }; + + query.queryKey = queryOptions.queryKey; + + return query; +} diff --git a/solution/frontend/src/features/ops-stats/CrawlerStatsPanel.tsx b/solution/frontend/src/features/ops-stats/CrawlerStatsPanel.tsx index 4d7567d..9b8b693 100644 --- a/solution/frontend/src/features/ops-stats/CrawlerStatsPanel.tsx +++ b/solution/frontend/src/features/ops-stats/CrawlerStatsPanel.tsx @@ -31,7 +31,7 @@ export function RangeTabs({value, onChange}: {value: RangeDays; onChange: (days: ); } -function Stat({label, value}: {label: string; value: ReactNode}) { +export function Stat({label, value}: {label: string; value: ReactNode}) { return ( @@ -42,7 +42,7 @@ function Stat({label, value}: {label: string; value: ReactNode}) { ); } -function Section({title, children}: {title: string; children: ReactNode}) { +export function Section({title, children}: {title: string; children: ReactNode}) { return ( @@ -53,7 +53,7 @@ function Section({title, children}: {title: string; children: ReactNode}) { ); } -function Table({head, rows}: {head: string[]; rows: ReactNode[][]}) { +export function Table({head, rows}: {head: string[]; rows: ReactNode[][]}) { if (rows.length === 0) return

๊ธฐ๋ก์ด ์—†์Šต๋‹ˆ๋‹ค.

; return (
diff --git a/solution/frontend/src/features/ops-stats/KindTabs.tsx b/solution/frontend/src/features/ops-stats/KindTabs.tsx new file mode 100644 index 0000000..4edfa1f --- /dev/null +++ b/solution/frontend/src/features/ops-stats/KindTabs.tsx @@ -0,0 +1,29 @@ +import {cn} from '@/lib/utils'; + +export type StatsKind = 'visits' | 'crawlers'; + +const KINDS: ReadonlyArray = [ + ['visits', '๋ฐฉ๋ฌธ'], + ['crawlers', 'ํฌ๋กค๋ง'], +]; + +/** ํ†ต๊ณ„ ์ข…๋ฅ˜ โ€” ์‚ฌ๋žŒ ๋ฐฉ๋ฌธ๊ณผ ๋ด‡ ํฌ๋กค๋ง์€ ์„ธ๋Š” ๋ฐฉ๋ฒ•์ด ๋‹ฌ๋ผ ํ•œ ํ™”๋ฉด์— ์„ž์ง€ ์•Š๋Š”๋‹ค. */ +export function KindTabs({kind, onChange}: {kind: StatsKind; onChange: (kind: StatsKind) => void}) { + return ( +
+ {KINDS.map(([value, label]) => ( + + ))} +
+ ); +} diff --git a/solution/frontend/src/features/ops-stats/OverallStats.tsx b/solution/frontend/src/features/ops-stats/OverallStats.tsx new file mode 100644 index 0000000..67c420d --- /dev/null +++ b/solution/frontend/src/features/ops-stats/OverallStats.tsx @@ -0,0 +1,15 @@ +import {useState} from 'react'; +import {KindTabs, type StatsKind} from './KindTabs'; +import {OverallCrawlerStats} from './OverallCrawlerStats'; +import {OverallVisitStats} from './OverallVisitStats'; + +/** ์‚ฌ์ดํŠธ๊ด€๋ฆฌ "์ „์ฒด ํ†ต๊ณ„" ํƒญ ๋ณธ๋ฌธ โ€” ๋ฐฉ๋ฌธ๊ณผ ํฌ๋กค๋ง์„ ํ•˜์œ„ ํƒญ์œผ๋กœ ๊ฐ€๋ฅธ๋‹ค. */ +export function OverallStats() { + const [kind, setKind] = useState('visits'); + return ( +
+ + {kind === 'visits' ? : } +
+ ); +} diff --git a/solution/frontend/src/features/ops-stats/OverallVisitStats.tsx b/solution/frontend/src/features/ops-stats/OverallVisitStats.tsx new file mode 100644 index 0000000..cf40734 --- /dev/null +++ b/solution/frontend/src/features/ops-stats/OverallVisitStats.tsx @@ -0,0 +1,39 @@ +import {useState} from 'react'; +import {keepPreviousData} from '@tanstack/react-query'; +import {Loader2} from 'lucide-react'; +import {useVisitStats} from '@/api'; +import {EmptyState} from '@/components/layout/AppShell'; +import {RangeTabs} from './CrawlerStatsPanel'; +import {rangeParams, type RangeDays} from './range'; +import {VisitStatsPanel} from './VisitStatsPanel'; + +/** ์‹ค์‹œ๊ฐ„ ์ˆซ์ž๋Š” 30์ดˆ๋งˆ๋‹ค ๋‹ค์‹œ ๋ถ€๋ฅธ๋‹ค โ€” "์ง€๊ธˆ ๋ช‡ ๋ช…" ์€ ํ™”๋ฉด์„ ์—ด์–ด ๋‘” ์ฑ„ ๋ณด๋Š” ์ˆซ์ž๋‹ค. */ +const REFRESH_MS = 30_000; + +export function OverallVisitStats() { + const [days, setDays] = useState(7); + const {data, isLoading, isError, error} = useVisitStats(rangeParams(days), { + query: {placeholderData: keepPreviousData, refetchInterval: REFRESH_MS}, + }); + + return ( +
+
+

๋ฐฉ๋ฌธ (์ „์ฒด ์‚ฌ์ดํŠธ)

+ +
+ {isLoading && ( +
+ +
+ )} + {(isError || data?.result?.success === false) && ( + + )} + {data?.result?.success && } +
+ ); +} diff --git a/solution/frontend/src/features/ops-stats/VisitDailyChart.tsx b/solution/frontend/src/features/ops-stats/VisitDailyChart.tsx new file mode 100644 index 0000000..3524b03 --- /dev/null +++ b/solution/frontend/src/features/ops-stats/VisitDailyChart.tsx @@ -0,0 +1,28 @@ +import {Bar, CartesianGrid, ComposedChart, Legend, Line, ResponsiveContainer, Tooltip, XAxis, YAxis} from 'recharts'; +import type {VisitDaily} from '@/api'; +import {daysBetween} from './range'; + +const LABEL: Record = {views: 'ํŽ˜์ด์ง€๋ทฐ', visitors: '๋ฐฉ๋ฌธ์ž'}; + +/** recharts ๋Š” ์ด ํŒŒ์ผ์—๋งŒ ๋‘”๋‹ค โ€” VisitStatsPanel ์ด lazy() ๋กœ ๋ถ€๋ฅธ๋‹ค. */ +export default function VisitDailyChart({daily, from, to}: {daily: VisitDaily[]; from: string; to: string}) { + const byDay = new Map(daily.map((d) => [d.day, d])); + const rows = daysBetween(from, to).map((day) => ({ + day, + views: byDay.get(day)?.views ?? 0, + visitors: byDay.get(day)?.visitors ?? 0, + })); + return ( + + + + day.slice(5)} fontSize={11} /> + + [value, LABEL[String(name)] ?? name]} /> + LABEL[String(value)] ?? value} wrapperStyle={{fontSize: 11}} /> + + + + + ); +} diff --git a/solution/frontend/src/features/ops-stats/VisitStatsPanel.tsx b/solution/frontend/src/features/ops-stats/VisitStatsPanel.tsx new file mode 100644 index 0000000..1f4614b --- /dev/null +++ b/solution/frontend/src/features/ops-stats/VisitStatsPanel.tsx @@ -0,0 +1,82 @@ +import {lazy, Suspense} from 'react'; +import {Link} from 'react-router'; +import {Loader2, Users} from 'lucide-react'; +import type {ResVisitStats} from '@/api'; +import {EmptyState} from '@/components/layout/AppShell'; +import {Section, Stat, Table} from './CrawlerStatsPanel'; +import {formatKst} from './labels'; + +const VisitDailyChart = lazy(() => import('./VisitDailyChart')); + +const DEVICE_LABEL: Record = {desktop: '๋ฐ์Šคํฌํ†ฑ', mobile: '๋ชจ๋ฐ”์ผ', tablet: 'ํƒœ๋ธ”๋ฆฟ'}; + +/** ๋ฐฉ๋ฌธ ํƒญ ๋ณธ๋ฌธ. ์ „์ฒด: ์‚ฌ์ดํŠธ ์ˆœ์œ„ / ์‚ฌ์ดํŠธ๋ณ„: ํŽ˜์ด์ง€ยท์บ ํŽ˜์ธ. ์œ ์ž…ยท๊ธฐ๊ธฐ๋Š” ๊ณตํ†ต. */ +export function VisitStatsPanel({data, scope}: {data: ResVisitStats; scope: 'overall' | 'site'}) { + const summary = data.summary; + const realtime = data.realtime ?? 0; + // ๊ธฐ๊ฐ„ ์•ˆ์— ๊ธฐ๋ก์ด ์—†์–ด๋„ ์ง€๊ธˆ ๋“ค์–ด์™€ ์žˆ๋Š” ์‚ฌ๋žŒ์ด ์žˆ์œผ๋ฉด ๊ทธ ์ˆซ์ž๋Š” ๋ณด์—ฌ ์ค€๋‹ค. + if (!summary?.views && !realtime) { + return ; + } + return ( +
+
+ + + + {formatKst(summary?.last_at)}} /> +
+ +
+ {data.date_from && data.date_to && ( + }> + + + )} +
+ + {scope === 'overall' ? ( +
+ [ + + {s.name} + , + s.views, + s.visitors, + ])} + /> + + ) : ( + <> +
+
[ + + {p.path} + , + p.views, + p.visitors, + ])} + /> + +
+
[u.source, u.views])} /> + + + )} + +
+
[r.domain, r.views])} /> + +
+
[DEVICE_LABEL[d.device] ?? d.device, d.views])} + /> + + + ); +} diff --git a/solution/frontend/src/pages/OpsSiteStatsPage.tsx b/solution/frontend/src/pages/OpsSiteStatsPage.tsx index 4ca36fc..56e33a1 100644 --- a/solution/frontend/src/pages/OpsSiteStatsPage.tsx +++ b/solution/frontend/src/pages/OpsSiteStatsPage.tsx @@ -2,22 +2,34 @@ import {useState} from 'react'; import {Link, Navigate, useParams} from 'react-router'; import {keepPreviousData} from '@tanstack/react-query'; import {ArrowLeft, Loader2} from 'lucide-react'; -import {UserRole, useSiteCrawlerStats} from '@/api'; +import {UserRole, useSiteCrawlerStats, useSiteVisitStats} from '@/api'; import {AppShell, EmptyState, PageContainer} from '@/components/layout/AppShell'; import {CrawlerStatsPanel, RangeTabs} from '@/features/ops-stats/CrawlerStatsPanel'; +import {KindTabs, type StatsKind} from '@/features/ops-stats/KindTabs'; import {rangeParams, type RangeDays} from '@/features/ops-stats/range'; +import {VisitStatsPanel} from '@/features/ops-stats/VisitStatsPanel'; import {useAuthStore} from '@/stores/auth'; -/** ์‚ฌ์ดํŠธ๋ณ„ ํ†ต๊ณ„ โ€” ๊ฐœ๋ฐœ์ž(DEVELOPER) ์ „์šฉ. 2๋‹จ๊ณ„์—์„œ "๋ฐฉ๋ฌธ" ํƒญ์ด ๋ถ™๋Š”๋‹ค. */ +/** ์‹ค์‹œ๊ฐ„ ๋ฐฉ๋ฌธ์ž๋Š” 30์ดˆ๋งˆ๋‹ค ๋‹ค์‹œ ๋ถ€๋ฅธ๋‹ค(์ „์ฒด ํ†ต๊ณ„์™€ ๊ฐ™์€ ์ฃผ๊ธฐ). */ +const REFRESH_MS = 30_000; + +/** ์‚ฌ์ดํŠธ๋ณ„ ํ†ต๊ณ„ โ€” ๊ฐœ๋ฐœ์ž(DEVELOPER) ์ „์šฉ. */ export function OpsSiteStatsPage() { const {placeId = ''} = useParams(); const isRestoring = useAuthStore((s) => s.isRestoring); const role = useAuthStore((s) => s.user?.role); const [days, setDays] = useState(7); - // enabled: OpsSitesPage ์™€ ๊ฐ™์€ ์ด์œ  โ€” role ํ™•์ • ์ „ ์š”์ฒญ์ด 403 ํ† ์ŠคํŠธ๋ฅผ ๋จผ์ € ๋„์šด๋‹ค. - const {data, isLoading, isError, error} = useSiteCrawlerStats(placeId, rangeParams(days), { - query: {placeholderData: keepPreviousData, enabled: role === UserRole.DEVELOPER && !!placeId}, + const [kind, setKind] = useState('visits'); + // enabled: OpsSitesPage ์™€ ๊ฐ™์€ ์ด์œ  โ€” role ํ™•์ • ์ „ ์š”์ฒญ์ด 403 ํ† ์ŠคํŠธ๋ฅผ ๋จผ์ € ๋„์šด๋‹ค. ๋ณด์ด๋Š” ํƒญ๋งŒ ๋ถ€๋ฅธ๋‹ค. + const ready = role === UserRole.DEVELOPER && !!placeId; + const params = rangeParams(days); + const visits = useSiteVisitStats(placeId, params, { + query: {placeholderData: keepPreviousData, enabled: ready && kind === 'visits', refetchInterval: REFRESH_MS}, }); + const crawlers = useSiteCrawlerStats(placeId, params, { + query: {placeholderData: keepPreviousData, enabled: ready && kind === 'crawlers'}, + }); + const current = kind === 'visits' ? visits : crawlers; if (isRestoring) return null; if (role !== UserRole.DEVELOPER) return ; @@ -26,7 +38,7 @@ export function OpsSiteStatsPage() {
-

ํฌ๋กค๋ง

+
- {isLoading && ( + {current.isLoading && (
)} - {(isError || data?.result?.success === false) && ( + {(current.isError || current.data?.result?.success === false) && ( )} - {data?.result?.success && } + {kind === 'visits' && visits.data?.result?.success && } + {kind === 'crawlers' && crawlers.data?.result?.success && ( + + )}
); diff --git a/solution/frontend/src/pages/OpsSitesPage.tsx b/solution/frontend/src/pages/OpsSitesPage.tsx index 80526e4..1b8ed69 100644 --- a/solution/frontend/src/pages/OpsSitesPage.tsx +++ b/solution/frontend/src/pages/OpsSitesPage.tsx @@ -8,7 +8,7 @@ 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 {OverallStats} from '@/features/ops-stats/OverallStats'; import {SitesTabs, type SitesTab} from '@/features/ops-stats/SitesTabs'; import {notify, notifyApiError} from '@/lib/notify'; import {PUBLISH_HOST} from '@/lib/site'; @@ -96,7 +96,7 @@ export function OpsSitesPage() { - + );