From 84560cef2d9731f59e175a4e8e687e11dc87309e Mon Sep 17 00:00:00 2001 From: kric_jspark Date: Mon, 2 Feb 2026 15:05:11 +0900 Subject: [PATCH] =?UTF-8?q?260202=5F03=5FENH:=20=ED=8E=98=EC=9D=B4?= =?UTF-8?q?=EC=A7=80=20=EA=B9=9C=EB=B9=A1=EC=9E=84=20=EC=B5=9C=EC=86=8C?= =?UTF-8?q?=ED=99=94=20=EB=B0=8F=20=EC=B9=B4=ED=85=8C=EA=B3=A0=EB=A6=AC?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EC=A0=84=EC=B2=B4=EB=A1=9C=20=EC=9D=B4?= =?UTF-8?q?=EB=8F=99=20=EC=8B=9C=20=ED=8E=98=EC=9D=B4=EC=A7=80=20=EB=A0=8C?= =?UTF-8?q?=EB=8D=94=EB=A7=81=202=ED=9A=8C=20=EB=90=98=EB=8A=94=20?= =?UTF-8?q?=EB=B6=80=EB=B6=84=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/layout/MainLayout.tsx | 36 ++++++++++++------- .../lge-dashboard/combo/BannerSummary.tsx | 26 ++------------ .../lge-dashboard/combo/CategoryByData.tsx | 10 ++++-- .../sub-page/category-page/Brand.tsx | 3 +- .../category-page/PenetrationChange.tsx | 10 ++---- .../sub-page/category-page/Profile.tsx | 26 +++++--------- .../lge-dashboard/table/DataTable.tsx | 16 +++++---- src/config/sample.data.ts | 4 +++ src/lib/lg-dashboard.ts | 30 ++++++++++++++++ 9 files changed, 90 insertions(+), 71 deletions(-) diff --git a/src/components/layout/MainLayout.tsx b/src/components/layout/MainLayout.tsx index 1f7a8e2..06dd2e8 100644 --- a/src/components/layout/MainLayout.tsx +++ b/src/components/layout/MainLayout.tsx @@ -67,6 +67,8 @@ const MainLayout = ({ children }: MainLayoutProps) => { const [totalValue, setTotalValue] = useState(() => buildDefaultTotalValue()); const [categoryValue, setCategoryValue] = useState(() => buildDefaultCategoryValue(categoryFilterItems)); + const prevIsTotalRef = useRef(isTotal); + const movePage = (path: string) => { router.push(path); }; @@ -86,30 +88,38 @@ const MainLayout = ({ children }: MainLayoutProps) => { scrollRef.current?.scrollTo({ top: 0, behavior: "smooth" }); }; - const ctx = useMemo(() => { - return isTotal - ? { isTotal: true, filterValue: totalValue } - : { isTotal: false, filterValue: categoryValue }; - }, [isTotal, totalValue, categoryValue]); useEffect(() => { - if (isTotal){ - console.log("istotal category", buildDefaultCategoryValue(PRODUCTS_FILTER_ITEM[0])); - setCategoryValue(buildDefaultCategoryValue(PRODUCTS_FILTER_ITEM[0])) + const prevIsTotal = prevIsTotalRef.current; + + // 1) category -> total : 아무것도 안 함 (여기서 setCategoryValue 하면 1번 더 렌더됨) + if (isTotal) { + prevIsTotalRef.current = isTotal; return; } - if(categoryValue.product != categoryFilterItems.items[0]){ - setCategoryValue((prev) => { - return { ...prev, product: categoryFilterItems.items[0] }; - }); + // 2) total -> category : 들어오는 순간에만 초기화 + if (prevIsTotal) { + setCategoryValue(buildDefaultCategoryValue(categoryFilterItems)); + prevIsTotalRef.current = isTotal; + return; } + // 3) category 내부 이동(카테고리 path 바뀜 등) : product만 동기화 + const nextProduct = categoryFilterItems.items[0]; + setCategoryValue((prev) => { + if (prev.product === nextProduct) return prev; + return { ...prev, product: nextProduct }; + }); + + prevIsTotalRef.current = isTotal; }, [isTotal, categoryFilterItems]); return (
- +
{ - const buildChartData = (rows: ServerBannerRow[], bannerKeys: BannerKey[]): ChartData => { const categories = rows .filter((r) => r.rowLabel !== "사례수") @@ -86,26 +85,7 @@ const BannerSummary = ({ data, useChart }: BannerSummaryProps) => { return { categories, series }; }; - const rows = useMemo(() => { - const allKeys = Array.from( - new Set(Object.values(BANNER_GROUP).flatMap((g) => g.keys)) - ) as string[]; - - return data.map((r) => { - const out: any = { ...r }; - - if (isSampleRow(r.rowLabel)) { - // total - out.total = `(${formatNumber(Number(r.total ?? 0))})`; - // banner values - allKeys.forEach((k) => { - const v = (r as any)[k]; - if (typeof v === "number") out[k] = `(${formatNumber(v)})`; - }); - } - return out as ServerBannerRow; - }); - }, [data]); + const rows = useMemo(() => wrapSampleRow(data), [data]); const signStyleGap: SignStyle = { rowSelector: (row) => row.rowLabel === "gap", diff --git a/src/components/lge-dashboard/combo/CategoryByData.tsx b/src/components/lge-dashboard/combo/CategoryByData.tsx index 36fb68a..ebc26f2 100644 --- a/src/components/lge-dashboard/combo/CategoryByData.tsx +++ b/src/components/lge-dashboard/combo/CategoryByData.tsx @@ -9,7 +9,12 @@ import BannerButtons from "@/components/lge-dashboard/BannerButtons"; import {totalFilters} from "@/config/filter.data"; import {useMemo, useState} from "react"; import {BannerGroupKey, CategoryChartMode, ServerBannerRow} from "@/types/lg"; -import {buildRowLabelSeriesChartData, buildYearSeriesChartData, isBannerGroupKey} from "@/lib/lg-dashboard"; +import { + buildRowLabelSeriesChartData, + buildYearSeriesChartData, + isBannerGroupKey, + wrapSampleRow +} from "@/lib/lg-dashboard"; import {BANNER_GROUP, BANNER_KEY_MAP, LAST_YEAR} from "@/const/lgConst"; import {createDefaultGrid, createDefaultLegend, reverseCategories} from "@/lib/chart-options"; @@ -84,7 +89,8 @@ const CategoryByData = ({ const v = selectedBanner.variable; return isBannerGroupKey(v) ? buildColumns(v) : []; }, [selectedBanner.variable]); - const tableData = useMemo(() => allTableData.filter((row) => row.year === LAST_YEAR), [allTableData, LAST_YEAR]) + + const tableData = useMemo(() => wrapSampleRow(allTableData).filter((row) => row.year === LAST_YEAR), [allTableData, LAST_YEAR]) return (
diff --git a/src/components/lge-dashboard/sub-page/category-page/Brand.tsx b/src/components/lge-dashboard/sub-page/category-page/Brand.tsx index 031ca17..cdb3468 100644 --- a/src/components/lge-dashboard/sub-page/category-page/Brand.tsx +++ b/src/components/lge-dashboard/sub-page/category-page/Brand.tsx @@ -3,13 +3,12 @@ import {useMemo} from "react"; import {useLayoutFilter} from "@/components/layout/LayoutFilterContext"; import {CategoryByData} from "@/components/lge-dashboard"; -import {apiBrandShareByYear, apiPaymentMethodByYear} from "@/config/sample.data"; +import {apiBrandShareByYear} from "@/config/sample.data"; import {PageData, ServerBannerRow} from "@/types/lg"; import {buildGapRow} from "@/lib/lg-dashboard"; const Brand = () => { const { filterValue } = useLayoutFilter(); - console.log(filterValue); const tableDataArray = useMemo[]>(() => { const cleaned = apiBrandShareByYear.filter( diff --git a/src/components/lge-dashboard/sub-page/category-page/PenetrationChange.tsx b/src/components/lge-dashboard/sub-page/category-page/PenetrationChange.tsx index 44f064c..3373a3c 100644 --- a/src/components/lge-dashboard/sub-page/category-page/PenetrationChange.tsx +++ b/src/components/lge-dashboard/sub-page/category-page/PenetrationChange.tsx @@ -2,19 +2,15 @@ import {useLayoutFilter} from "@/components/layout/LayoutFilterContext"; import BannerSummary from "@/components/lge-dashboard/combo/BannerSummary"; -import {useEffect, useState} from "react"; +import {useEffect, useMemo, useState} from "react"; import {ServerBannerRow} from "@/types/lg"; -import {apiYearIndex} from "@/config/sample.data"; +import {apiOwnershipSummary, apiPurchaseRateKpis, apiYearIndex} from "@/config/sample.data"; const PenetrationChange = () => { const { filterValue } = useLayoutFilter(); console.log(filterValue); - const [penetrationChangeData, setPenetrationChangeData] = useState([]); - - useEffect(() => { - setPenetrationChangeData(apiYearIndex) - },[]) + const penetrationChangeData = useMemo(() => apiYearIndex, []); return( diff --git a/src/components/lge-dashboard/sub-page/category-page/Profile.tsx b/src/components/lge-dashboard/sub-page/category-page/Profile.tsx index fd8ef5b..f2e96e9 100644 --- a/src/components/lge-dashboard/sub-page/category-page/Profile.tsx +++ b/src/components/lge-dashboard/sub-page/category-page/Profile.tsx @@ -2,37 +2,29 @@ import {useLayoutFilter} from "@/components/layout/LayoutFilterContext"; import BannerSummary from "@/components/lge-dashboard/combo/BannerSummary"; -import {useEffect, useMemo, useState} from "react"; +import { useMemo } from "react"; import {ServerBannerRow} from "@/types/lg"; import {apiOwnershipSummary, apiPurchaseRateKpis} from "@/config/sample.data"; const Profile = () => { const { isTotal, filterValue } = useLayoutFilter(); - const [profileData, setProfileData] = useState([]); - const typeLabel = useMemo(() => { - if (isTotal) return null; // SelectedMap 경로 - return filterValue.type.label; // CategoryFilterValue 경로로 TS가 좁혀짐 - }, [isTotal, filterValue]); + const profileData = useMemo(() => { + if (isTotal) return []; - useEffect(() => { - if (!typeLabel) return; + const typeLabel = filterValue.type.label; switch (typeLabel) { case "보유": - setProfileData(apiOwnershipSummary); - break; + return apiOwnershipSummary; case "구매": - setProfileData(apiPurchaseRateKpis); - break; + return apiPurchaseRateKpis; case "향후 구매": - setProfileData(apiPurchaseRateKpis); - break; + return apiPurchaseRateKpis; default: - setProfileData([]); - break; + return []; } - }, [typeLabel]); + }, [isTotal, filterValue]); return ( diff --git a/src/components/lge-dashboard/table/DataTable.tsx b/src/components/lge-dashboard/table/DataTable.tsx index e767f76..747abe7 100644 --- a/src/components/lge-dashboard/table/DataTable.tsx +++ b/src/components/lge-dashboard/table/DataTable.tsx @@ -41,6 +41,12 @@ const signText = ( return zeroText; }; +const toCellContent = (raw: unknown): React.ReactNode => { + if (raw == null) return ""; + if (typeof raw === "string" || typeof raw === "number") return raw; + return String(raw); +}; + const DataTable = >({ columns, rows, @@ -177,7 +183,7 @@ const DataTable = >({ return ( {columns.map((c) => { - const raw = row[c.key]; + const raw: unknown = c.key ? (row[c.key] as unknown) : undefined; const align = c.align ?? (c.numeric ? "right" : "center"); // headRowSpan=2 컬럼은 thead 2행에서 제외되므로, tbody는 항상 렌더 @@ -205,13 +211,9 @@ const DataTable = >({ } // 일반 셀 - const content = c.render + const content: React.ReactNode = c.render ? c.render(row) - : raw === null || raw === undefined - ? "" - : typeof raw === "string" || typeof raw === "number" - ? raw - : String(raw); + : toCellContent(raw); if (c.rowHead) { return ( diff --git a/src/config/sample.data.ts b/src/config/sample.data.ts index 3c84e5e..e76b624 100644 --- a/src/config/sample.data.ts +++ b/src/config/sample.data.ts @@ -404,10 +404,12 @@ export const apiOwnershipTriggerByYear: ServerBannerRow[] = [ * 25/26 결제수단 * -------------------------- */ export const apiPaymentMethodByYear: ServerBannerRow[] = [ + bannerRow(25, "사례수", 650), bannerRow(25, "일시불", 60), bannerRow(25, "할부", 30), bannerRow(25, "렌탈", 10), + bannerRow(26, "사례수", 650), bannerRow(26, "일시불", 58), bannerRow(26, "할부", 32), bannerRow(26, "렌탈", 10), @@ -425,9 +427,11 @@ export const apiPurchaseRateKpis: ServerBannerRow[] = [ ]; export const apiPurchaseChannelSummaryByYear: ServerBannerRow[] = [ + bannerRow(25, "사례수", 650), bannerRow(25, "오프라인", 60), bannerRow(25, "온라인/홈쇼핑", 40), + bannerRow(26, "사례수", 650), bannerRow(26, "오프라인", 59), bannerRow(26, "온라인/홈쇼핑", 41), ] diff --git a/src/lib/lg-dashboard.ts b/src/lib/lg-dashboard.ts index 4662cd1..0bc9e7b 100644 --- a/src/lib/lg-dashboard.ts +++ b/src/lib/lg-dashboard.ts @@ -1,6 +1,7 @@ import {BannerGroupKey, ServerBannerRow} from "@/types/lg"; import {ChartData} from "@/components/lge-dashboard"; import {BANNER_GROUP} from "@/const/lgConst"; +import {formatNumber} from "@/lib/utils"; export const isSampleRow = (raw: string) => raw.replace(/\s+/g, "") === "사례수"; @@ -45,6 +46,35 @@ export function formatRowLabel( return t; } +export const wrapSampleRow = & { rowLabel: string }>( + rows: T[] +): T[] => { + return rows.map((r) => { + if (!isSampleRow(r.rowLabel)) return r; + + const out: any = { ...r }; + + Object.entries(r).forEach(([k, v]) => { + if (k == "year" || v == null) return; + + if (typeof v === "number") { + out[k] = `(${formatNumber(v)})`; + return; + } + + if (typeof v === "string") { + // 이미 괄호면 그대로 + out[k] = v.startsWith("(") && v.endsWith(")") ? v : `(${v})`; + return; + } + + out[k] = `(${String(v)})`; + }); + + return out as T; + }); +}; + /** * 연도 배열로부터 연도 -> 인덱스 맵을 생성합니다. * @param years - 연도 배열 (예: [2024, 2025, 2026])