260303_01_ENH: 카테고리 파트 구조 정리
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import CategoryPage from "@/components/lge-dashboard/sub-page/CategoryPage";
|
||||
import CategoryPage from "../sub-page/CategoryPage";
|
||||
|
||||
const ESPage = () => {
|
||||
return <CategoryPage/>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import CategoryPage from "@/components/lge-dashboard/sub-page/CategoryPage";
|
||||
import CategoryPage from "../sub-page/CategoryPage";
|
||||
|
||||
const KitchenPage = () => {
|
||||
return <CategoryPage/>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import CategoryPage from "@/components/lge-dashboard/sub-page/CategoryPage";
|
||||
import CategoryPage from "../sub-page/CategoryPage";
|
||||
|
||||
const LivingPage = () => {
|
||||
return <CategoryPage/>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import CategoryPage from "@/components/lge-dashboard/sub-page/CategoryPage";
|
||||
import CategoryPage from "../sub-page/CategoryPage";
|
||||
|
||||
const MSPage = () => {
|
||||
return <CategoryPage/>
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
'use client'
|
||||
|
||||
import {useMemo} from "react";
|
||||
import {useLayoutFilter} from "@/components/layout/LayoutFilterContext";
|
||||
import {CategoryTargetData} from "@/config/filter.types";
|
||||
import Profile from "./category-page/Profile";
|
||||
import PenetrationChange from "./category-page/PenetrationChange";
|
||||
import {BannerRow, CategoryResolvedField, StatisticsRequest} from "@/types/lg";
|
||||
import {useDebouncedValue} from "@/hooks/useDebouncedValue";
|
||||
import {CategoryFilterValue} from "@/components/layout/CategoryFilter";
|
||||
import {useMemo} from "react";
|
||||
import {buildCategoryFilter, buildPageModeConfig} from "@/lib/lg-dashboard";
|
||||
import {BANNER_GROUP_KEY} from "@/const/lgConst";
|
||||
import {useBannerStatisticsQuery} from "@/hooks/useLgStatisticsQuery";
|
||||
import CategoryDetail from "@/components/lge-dashboard/sub-page/category-page/CategoryDetail";
|
||||
import Profile from "./category-page/Profile";
|
||||
import PenetrationChange from "./category-page/PenetrationChange";
|
||||
import CategoryDetail from "./category-page/CategoryDetail";
|
||||
import {useBannerStatisticsQuery} from "@/query/statistics";
|
||||
|
||||
export type CategoryPageProps = {
|
||||
fields: CategoryResolvedField[];
|
||||
@@ -1,4 +1,4 @@
|
||||
import {CategoryPageProps} from "@/components/lge-dashboard/sub-page/CategoryPage";
|
||||
import {CategoryPageProps} from "../../sub-page/CategoryPage";
|
||||
import {useLayoutFilter} from "@/components/layout/LayoutFilterContext";
|
||||
import {useDebouncedValue} from "@/hooks/useDebouncedValue";
|
||||
import {CategoryFilterValue} from "@/components/layout/CategoryFilter";
|
||||
@@ -3,7 +3,7 @@
|
||||
import BannerSummary from "@/components/lge-dashboard/combo/BannerSummary";
|
||||
import {useMemo} from "react";
|
||||
import {BannerRow} from "@/types/lg";
|
||||
import {CategoryPageProps} from "@/components/lge-dashboard/sub-page/CategoryPage";
|
||||
import {CategoryPageProps} from "../../sub-page/CategoryPage";
|
||||
import {LAST_YEAR} from "@/const/lgConst";
|
||||
|
||||
const PenetrationChange = ({
|
||||
@@ -9,7 +9,7 @@ import {useDebouncedValue} from "@/hooks/useDebouncedValue";
|
||||
import { calcGapBannerRow } from "@/lib/lg-dashboard";
|
||||
import {YEARS} from "@/const/lgConst";
|
||||
import {CategoryTargetType} from "@/config/filter.types";
|
||||
import {CategoryPageProps} from "@/components/lge-dashboard/sub-page/CategoryPage";
|
||||
import {CategoryPageProps} from "../../sub-page/CategoryPage";
|
||||
|
||||
const Profile = ({
|
||||
dataMap
|
||||
@@ -37,7 +37,7 @@ import {toNumOr0} from "@/lib/utils";
|
||||
import {LifeStageGroup, LifeStageRow, ProductKey, StatisticsRequest} from "@/types/lg";
|
||||
import {useDebouncedValue} from "@/hooks/useDebouncedValue";
|
||||
import {SelectedMap} from "@/types/common";
|
||||
import {useBannerStatisticsQuery, useProductStatisticsQuery} from "@/hooks/useLgStatisticsQuery";
|
||||
import {useBannerStatisticsQuery, useProductStatisticsQuery} from "@/query/statistics";
|
||||
|
||||
const LGPenetrationPage = () => {
|
||||
const {filterValue, registerExcelExporter} = useLayoutFilter();
|
||||
|
||||
@@ -27,7 +27,7 @@ import {buildHeader_ProductKeyMap, exportDashboardExcel} from "@/lib/lg-export-e
|
||||
import {useDebouncedValue} from "@/hooks/useDebouncedValue";
|
||||
import {SelectedMap} from "@/types/common";
|
||||
import {ProductKey, StatisticsRequest} from "@/types/lg";
|
||||
import {useProductStatisticsQuery} from "@/hooks/useLgStatisticsQuery";
|
||||
import {useProductStatisticsQuery} from "@/query/statistics";
|
||||
import {toNumOr0} from "@/lib/utils";
|
||||
|
||||
const LGPurchasePage = () => {
|
||||
|
||||
@@ -27,7 +27,7 @@ import {
|
||||
} from "@/lib/lg-dashboard";
|
||||
import {buildHeader_ProductKeyMap, exportDashboardExcel, Section} from "@/lib/lg-export-excel";
|
||||
import {StatisticsRequest} from "@/types/lg";
|
||||
import {useProductStatisticsQuery} from "@/hooks/useLgStatisticsQuery";
|
||||
import {useProductStatisticsQuery} from "@/query/statistics";
|
||||
import {useDebouncedValue} from "@/hooks/useDebouncedValue";
|
||||
import {toNumOr0} from "@/lib/utils";
|
||||
import {SelectedMap} from "@/types/common";
|
||||
|
||||
@@ -23,7 +23,7 @@ import {buildHeader_ProductKeyMap, exportDashboardExcel} from "@/lib/lg-export-e
|
||||
import {useDebouncedValue} from "@/hooks/useDebouncedValue";
|
||||
import {SelectedMap} from "@/types/common";
|
||||
import {StatisticsRequest} from "@/types/lg";
|
||||
import {useProductStatisticsQuery} from "@/hooks/useLgStatisticsQuery";
|
||||
import {useProductStatisticsQuery} from "@/query/statistics";
|
||||
|
||||
const PurchasePage = () => {
|
||||
const { filterValue, registerExcelExporter } = useLayoutFilter();
|
||||
|
||||
@@ -134,7 +134,7 @@ const DataTable = <T extends Record<string, unknown>>({
|
||||
const isTargetKey = (k: keyof T) => {
|
||||
if (!signStyle) return false;
|
||||
if (keys && keys.length) return keys.includes(k);
|
||||
// keys 미지정이면 numeric 컬럼 전체
|
||||
// keys.ts 미지정이면 numeric 컬럼 전체
|
||||
const col = columns.find((c) => c.key === k);
|
||||
return !!col?.numeric;
|
||||
};
|
||||
|
||||
@@ -672,7 +672,7 @@ export function buildHeader_DataColumn<T>(cols: DataColumn<T>[]): HeaderBlock {
|
||||
* (3) BANNER_GROUP + BANNER_KEY_MAP:
|
||||
* - A1: "" (rowspan2)
|
||||
* - B1: "전체" (rowspan2) key=total
|
||||
* - C1~: group(label) (colSpan = keys.length)
|
||||
* - C1~: group(label) (colSpan = keys.ts.length)
|
||||
* - 2행: 각 key의 라벨(BANNER_KEY_MAP[key])
|
||||
*/
|
||||
export function buildHeader_Banner<K extends string>(
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import type { StatisticsRequest, ProductResponse, BannerResponse } from "@/types/lg";
|
||||
import {fetchBannerStatistics, fetchProductStatistics} from "@/lib/lg-dashboard";
|
||||
import type {ProductResponse, StatisticsRequest} from "@/types/lg";
|
||||
|
||||
const sortRecord = <T,>(obj?: Record<string, T> | null): Record<string, T> => {
|
||||
if (!obj) return {};
|
||||
@@ -20,7 +18,6 @@ const sortNumberArrayRecord = (obj?: Record<string, number[]> | null): Record<st
|
||||
);
|
||||
};
|
||||
|
||||
// queryKey에 넣을 “안정적인 req”
|
||||
const normalizeReqForKey = (req: StatisticsRequest) => ({
|
||||
variableIdMap: sortRecord(req.variableIdMap),
|
||||
bannerIdList: [...(req.bannerIdList ?? [])].sort(),
|
||||
@@ -32,28 +29,4 @@ export const productStatisticsKey = (req: StatisticsRequest) =>
|
||||
["statistics", "product", normalizeReqForKey(req)] as const;
|
||||
|
||||
export const bannerStatisticsKey = (req: StatisticsRequest) =>
|
||||
["statistics", "banner", normalizeReqForKey(req)] as const;
|
||||
|
||||
export function useProductStatisticsQuery(req: StatisticsRequest, enabled = true) {
|
||||
return useQuery<ProductResponse>({
|
||||
queryKey: productStatisticsKey(req),
|
||||
queryFn: () => fetchProductStatistics(req),
|
||||
enabled,
|
||||
staleTime: 60_000,
|
||||
gcTime: 10 * 60_000,
|
||||
});
|
||||
}
|
||||
|
||||
export function useBannerStatisticsQuery(req: StatisticsRequest, enabled = true) {
|
||||
return useQuery<BannerResponse>({
|
||||
queryKey: bannerStatisticsKey(req),
|
||||
queryFn: () => fetchBannerStatistics(req),
|
||||
enabled,
|
||||
/*
|
||||
refetchOnMount: "always",
|
||||
staleTime: 0,
|
||||
*/
|
||||
staleTime: 60_000,
|
||||
gcTime: 10 * 60_000,
|
||||
});
|
||||
}
|
||||
["statistics", "banner", normalizeReqForKey(req)] as const;
|
||||
28
src/query/statistics.ts
Normal file
28
src/query/statistics.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import {BannerResponse, ProductResponse, StatisticsRequest} from "@/types/lg";
|
||||
import {useQuery} from "@tanstack/react-query";
|
||||
import {bannerStatisticsKey, productStatisticsKey} from "@/query/keys";
|
||||
import {fetchBannerStatistics, fetchProductStatistics} from "@/lib/lg-dashboard";
|
||||
|
||||
export function useProductStatisticsQuery(req: StatisticsRequest, enabled = true) {
|
||||
return useQuery<ProductResponse>({
|
||||
queryKey: productStatisticsKey(req),
|
||||
queryFn: () => fetchProductStatistics(req),
|
||||
enabled,
|
||||
staleTime: 60_000,
|
||||
gcTime: 10 * 60_000,
|
||||
});
|
||||
}
|
||||
|
||||
export function useBannerStatisticsQuery(req: StatisticsRequest, enabled = true) {
|
||||
return useQuery<BannerResponse>({
|
||||
queryKey: bannerStatisticsKey(req),
|
||||
queryFn: () => fetchBannerStatistics(req),
|
||||
enabled,
|
||||
/*
|
||||
refetchOnMount: "always",
|
||||
staleTime: 0,
|
||||
*/
|
||||
staleTime: 60_000,
|
||||
gcTime: 10 * 60_000,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user