260202_03_ENH: 페이지 깜빡임 최소화 및 카테고리에서 전체로 이동 시 페이지 렌더링 2회 되는 부분 수정
This commit is contained in:
@@ -67,6 +67,8 @@ const MainLayout = ({ children }: MainLayoutProps) => {
|
|||||||
const [totalValue, setTotalValue] = useState<SelectedMap>(() => buildDefaultTotalValue());
|
const [totalValue, setTotalValue] = useState<SelectedMap>(() => buildDefaultTotalValue());
|
||||||
const [categoryValue, setCategoryValue] = useState<CategoryFilterValue>(() => buildDefaultCategoryValue(categoryFilterItems));
|
const [categoryValue, setCategoryValue] = useState<CategoryFilterValue>(() => buildDefaultCategoryValue(categoryFilterItems));
|
||||||
|
|
||||||
|
const prevIsTotalRef = useRef<boolean>(isTotal);
|
||||||
|
|
||||||
const movePage = (path: string) => {
|
const movePage = (path: string) => {
|
||||||
router.push(path);
|
router.push(path);
|
||||||
};
|
};
|
||||||
@@ -86,30 +88,38 @@ const MainLayout = ({ children }: MainLayoutProps) => {
|
|||||||
scrollRef.current?.scrollTo({ top: 0, behavior: "smooth" });
|
scrollRef.current?.scrollTo({ top: 0, behavior: "smooth" });
|
||||||
};
|
};
|
||||||
|
|
||||||
const ctx = useMemo<ExcelExportContext>(() => {
|
|
||||||
return isTotal
|
|
||||||
? { isTotal: true, filterValue: totalValue }
|
|
||||||
: { isTotal: false, filterValue: categoryValue };
|
|
||||||
}, [isTotal, totalValue, categoryValue]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isTotal){
|
const prevIsTotal = prevIsTotalRef.current;
|
||||||
console.log("istotal category", buildDefaultCategoryValue(PRODUCTS_FILTER_ITEM[0]));
|
|
||||||
setCategoryValue(buildDefaultCategoryValue(PRODUCTS_FILTER_ITEM[0]))
|
// 1) category -> total : 아무것도 안 함 (여기서 setCategoryValue 하면 1번 더 렌더됨)
|
||||||
|
if (isTotal) {
|
||||||
|
prevIsTotalRef.current = isTotal;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(categoryValue.product != categoryFilterItems.items[0]){
|
// 2) total -> category : 들어오는 순간에만 초기화
|
||||||
setCategoryValue((prev) => {
|
if (prevIsTotal) {
|
||||||
return { ...prev, product: categoryFilterItems.items[0] };
|
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]);
|
}, [isTotal, categoryFilterItems]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="h-screen flex flex-col bg-transparent overflow-hidden">
|
<div className="h-screen flex flex-col bg-transparent overflow-hidden">
|
||||||
<LayoutFilterProvider value={ctx} >
|
<LayoutFilterProvider
|
||||||
|
value={isTotal? { isTotal: true, filterValue: totalValue } : { isTotal: false, filterValue: categoryValue }}
|
||||||
|
>
|
||||||
<Header
|
<Header
|
||||||
activeTopId={activeTop.id}
|
activeTopId={activeTop.id}
|
||||||
onNavigate={movePage}
|
onNavigate={movePage}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import {ChartData, DataColumn, DataTable, HorizontalBar, LeftChartTable, SignStyle} from "@/components/lge-dashboard";
|
import {ChartData, DataColumn, DataTable, HorizontalBar, LeftChartTable, SignStyle} from "@/components/lge-dashboard";
|
||||||
import {BannerKey, ServerBannerRow} from "@/types/lg";
|
import {BannerKey, ServerBannerRow} from "@/types/lg";
|
||||||
import {formatRowLabel, isSampleRow} from "@/lib/lg-dashboard";
|
import {formatRowLabel, wrapSampleRow} from "@/lib/lg-dashboard";
|
||||||
import {useMemo} from "react";
|
import {useMemo} from "react";
|
||||||
import {BANNER_GROUP, BANNER_KEY_MAP, GRID_Y_NOT_PADDING} from "@/const/lgConst";
|
import {BANNER_GROUP, BANNER_KEY_MAP, GRID_Y_NOT_PADDING} from "@/const/lgConst";
|
||||||
import {formatNumber, parseNumber} from "@/lib/utils";
|
import {parseNumber} from "@/lib/utils";
|
||||||
|
|
||||||
|
|
||||||
type SectionSpec = {
|
type SectionSpec = {
|
||||||
@@ -68,7 +68,6 @@ type BannerSummaryProps = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const BannerSummary = ({ data, useChart }: BannerSummaryProps) => {
|
const BannerSummary = ({ data, useChart }: BannerSummaryProps) => {
|
||||||
|
|
||||||
const buildChartData = (rows: ServerBannerRow[], bannerKeys: BannerKey[]): ChartData => {
|
const buildChartData = (rows: ServerBannerRow[], bannerKeys: BannerKey[]): ChartData => {
|
||||||
const categories = rows
|
const categories = rows
|
||||||
.filter((r) => r.rowLabel !== "사례수")
|
.filter((r) => r.rowLabel !== "사례수")
|
||||||
@@ -86,26 +85,7 @@ const BannerSummary = ({ data, useChart }: BannerSummaryProps) => {
|
|||||||
return { categories, series };
|
return { categories, series };
|
||||||
};
|
};
|
||||||
|
|
||||||
const rows = useMemo<ServerBannerRow[]>(() => {
|
const rows = useMemo<ServerBannerRow[]>(() => wrapSampleRow(data), [data]);
|
||||||
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 signStyleGap: SignStyle<ServerBannerRow> = {
|
const signStyleGap: SignStyle<ServerBannerRow> = {
|
||||||
rowSelector: (row) => row.rowLabel === "gap",
|
rowSelector: (row) => row.rowLabel === "gap",
|
||||||
|
|||||||
@@ -9,7 +9,12 @@ import BannerButtons from "@/components/lge-dashboard/BannerButtons";
|
|||||||
import {totalFilters} from "@/config/filter.data";
|
import {totalFilters} from "@/config/filter.data";
|
||||||
import {useMemo, useState} from "react";
|
import {useMemo, useState} from "react";
|
||||||
import {BannerGroupKey, CategoryChartMode, ServerBannerRow} from "@/types/lg";
|
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 {BANNER_GROUP, BANNER_KEY_MAP, LAST_YEAR} from "@/const/lgConst";
|
||||||
import {createDefaultGrid, createDefaultLegend, reverseCategories} from "@/lib/chart-options";
|
import {createDefaultGrid, createDefaultLegend, reverseCategories} from "@/lib/chart-options";
|
||||||
|
|
||||||
@@ -84,7 +89,8 @@ const CategoryByData = ({
|
|||||||
const v = selectedBanner.variable;
|
const v = selectedBanner.variable;
|
||||||
return isBannerGroupKey(v) ? buildColumns(v) : [];
|
return isBannerGroupKey(v) ? buildColumns(v) : [];
|
||||||
}, [selectedBanner.variable]);
|
}, [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 (
|
return (
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
@@ -3,13 +3,12 @@
|
|||||||
import {useMemo} from "react";
|
import {useMemo} from "react";
|
||||||
import {useLayoutFilter} from "@/components/layout/LayoutFilterContext";
|
import {useLayoutFilter} from "@/components/layout/LayoutFilterContext";
|
||||||
import {CategoryByData} from "@/components/lge-dashboard";
|
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 {PageData, ServerBannerRow} from "@/types/lg";
|
||||||
import {buildGapRow} from "@/lib/lg-dashboard";
|
import {buildGapRow} from "@/lib/lg-dashboard";
|
||||||
|
|
||||||
const Brand = () => {
|
const Brand = () => {
|
||||||
const { filterValue } = useLayoutFilter();
|
const { filterValue } = useLayoutFilter();
|
||||||
console.log(filterValue);
|
|
||||||
|
|
||||||
const tableDataArray = useMemo<PageData<ServerBannerRow>[]>(() => {
|
const tableDataArray = useMemo<PageData<ServerBannerRow>[]>(() => {
|
||||||
const cleaned = apiBrandShareByYear.filter(
|
const cleaned = apiBrandShareByYear.filter(
|
||||||
|
|||||||
@@ -2,19 +2,15 @@
|
|||||||
|
|
||||||
import {useLayoutFilter} from "@/components/layout/LayoutFilterContext";
|
import {useLayoutFilter} from "@/components/layout/LayoutFilterContext";
|
||||||
import BannerSummary from "@/components/lge-dashboard/combo/BannerSummary";
|
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 {ServerBannerRow} from "@/types/lg";
|
||||||
import {apiYearIndex} from "@/config/sample.data";
|
import {apiOwnershipSummary, apiPurchaseRateKpis, apiYearIndex} from "@/config/sample.data";
|
||||||
|
|
||||||
const PenetrationChange = () => {
|
const PenetrationChange = () => {
|
||||||
const { filterValue } = useLayoutFilter();
|
const { filterValue } = useLayoutFilter();
|
||||||
console.log(filterValue);
|
console.log(filterValue);
|
||||||
|
|
||||||
const [penetrationChangeData, setPenetrationChangeData] = useState<ServerBannerRow[]>([]);
|
const penetrationChangeData = useMemo<ServerBannerRow[]>(() => apiYearIndex, []);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setPenetrationChangeData(apiYearIndex)
|
|
||||||
},[])
|
|
||||||
|
|
||||||
return(
|
return(
|
||||||
<BannerSummary data={penetrationChangeData} useChart={true} />
|
<BannerSummary data={penetrationChangeData} useChart={true} />
|
||||||
|
|||||||
@@ -2,37 +2,29 @@
|
|||||||
|
|
||||||
import {useLayoutFilter} from "@/components/layout/LayoutFilterContext";
|
import {useLayoutFilter} from "@/components/layout/LayoutFilterContext";
|
||||||
import BannerSummary from "@/components/lge-dashboard/combo/BannerSummary";
|
import BannerSummary from "@/components/lge-dashboard/combo/BannerSummary";
|
||||||
import {useEffect, useMemo, useState} from "react";
|
import { useMemo } from "react";
|
||||||
import {ServerBannerRow} from "@/types/lg";
|
import {ServerBannerRow} from "@/types/lg";
|
||||||
import {apiOwnershipSummary, apiPurchaseRateKpis} from "@/config/sample.data";
|
import {apiOwnershipSummary, apiPurchaseRateKpis} from "@/config/sample.data";
|
||||||
|
|
||||||
const Profile = () => {
|
const Profile = () => {
|
||||||
const { isTotal, filterValue } = useLayoutFilter();
|
const { isTotal, filterValue } = useLayoutFilter();
|
||||||
const [profileData, setProfileData] = useState<ServerBannerRow[]>([]);
|
|
||||||
|
|
||||||
const typeLabel = useMemo(() => {
|
const profileData = useMemo<ServerBannerRow[]>(() => {
|
||||||
if (isTotal) return null; // SelectedMap 경로
|
if (isTotal) return [];
|
||||||
return filterValue.type.label; // CategoryFilterValue 경로로 TS가 좁혀짐
|
|
||||||
}, [isTotal, filterValue]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
const typeLabel = filterValue.type.label;
|
||||||
if (!typeLabel) return;
|
|
||||||
|
|
||||||
switch (typeLabel) {
|
switch (typeLabel) {
|
||||||
case "보유":
|
case "보유":
|
||||||
setProfileData(apiOwnershipSummary);
|
return apiOwnershipSummary;
|
||||||
break;
|
|
||||||
case "구매":
|
case "구매":
|
||||||
setProfileData(apiPurchaseRateKpis);
|
return apiPurchaseRateKpis;
|
||||||
break;
|
|
||||||
case "향후 구매":
|
case "향후 구매":
|
||||||
setProfileData(apiPurchaseRateKpis);
|
return apiPurchaseRateKpis;
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
setProfileData([]);
|
return [];
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}, [typeLabel]);
|
}, [isTotal, filterValue]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<BannerSummary data={profileData} useChart={false} />
|
<BannerSummary data={profileData} useChart={false} />
|
||||||
|
|||||||
@@ -41,6 +41,12 @@ const signText = (
|
|||||||
return zeroText;
|
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 = <T extends Record<string, unknown>>({
|
const DataTable = <T extends Record<string, unknown>>({
|
||||||
columns,
|
columns,
|
||||||
rows,
|
rows,
|
||||||
@@ -177,7 +183,7 @@ const DataTable = <T extends Record<string, unknown>>({
|
|||||||
return (
|
return (
|
||||||
<tr key={rIdx}>
|
<tr key={rIdx}>
|
||||||
{columns.map((c) => {
|
{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");
|
const align = c.align ?? (c.numeric ? "right" : "center");
|
||||||
|
|
||||||
// headRowSpan=2 컬럼은 thead 2행에서 제외되므로, tbody는 항상 렌더
|
// headRowSpan=2 컬럼은 thead 2행에서 제외되므로, tbody는 항상 렌더
|
||||||
@@ -205,13 +211,9 @@ const DataTable = <T extends Record<string, unknown>>({
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 일반 셀
|
// 일반 셀
|
||||||
const content = c.render
|
const content: React.ReactNode = c.render
|
||||||
? c.render(row)
|
? c.render(row)
|
||||||
: raw === null || raw === undefined
|
: toCellContent(raw);
|
||||||
? ""
|
|
||||||
: typeof raw === "string" || typeof raw === "number"
|
|
||||||
? raw
|
|
||||||
: String(raw);
|
|
||||||
|
|
||||||
if (c.rowHead) {
|
if (c.rowHead) {
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -404,10 +404,12 @@ export const apiOwnershipTriggerByYear: ServerBannerRow[] = [
|
|||||||
* 25/26 결제수단
|
* 25/26 결제수단
|
||||||
* -------------------------- */
|
* -------------------------- */
|
||||||
export const apiPaymentMethodByYear: ServerBannerRow[] = [
|
export const apiPaymentMethodByYear: ServerBannerRow[] = [
|
||||||
|
bannerRow(25, "사례수", 650),
|
||||||
bannerRow(25, "일시불", 60),
|
bannerRow(25, "일시불", 60),
|
||||||
bannerRow(25, "할부", 30),
|
bannerRow(25, "할부", 30),
|
||||||
bannerRow(25, "렌탈", 10),
|
bannerRow(25, "렌탈", 10),
|
||||||
|
|
||||||
|
bannerRow(26, "사례수", 650),
|
||||||
bannerRow(26, "일시불", 58),
|
bannerRow(26, "일시불", 58),
|
||||||
bannerRow(26, "할부", 32),
|
bannerRow(26, "할부", 32),
|
||||||
bannerRow(26, "렌탈", 10),
|
bannerRow(26, "렌탈", 10),
|
||||||
@@ -425,9 +427,11 @@ export const apiPurchaseRateKpis: ServerBannerRow[] = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
export const apiPurchaseChannelSummaryByYear: ServerBannerRow[] = [
|
export const apiPurchaseChannelSummaryByYear: ServerBannerRow[] = [
|
||||||
|
bannerRow(25, "사례수", 650),
|
||||||
bannerRow(25, "오프라인", 60),
|
bannerRow(25, "오프라인", 60),
|
||||||
bannerRow(25, "온라인/홈쇼핑", 40),
|
bannerRow(25, "온라인/홈쇼핑", 40),
|
||||||
|
|
||||||
|
bannerRow(26, "사례수", 650),
|
||||||
bannerRow(26, "오프라인", 59),
|
bannerRow(26, "오프라인", 59),
|
||||||
bannerRow(26, "온라인/홈쇼핑", 41),
|
bannerRow(26, "온라인/홈쇼핑", 41),
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import {BannerGroupKey, ServerBannerRow} from "@/types/lg";
|
import {BannerGroupKey, ServerBannerRow} from "@/types/lg";
|
||||||
import {ChartData} from "@/components/lge-dashboard";
|
import {ChartData} from "@/components/lge-dashboard";
|
||||||
import {BANNER_GROUP} from "@/const/lgConst";
|
import {BANNER_GROUP} from "@/const/lgConst";
|
||||||
|
import {formatNumber} from "@/lib/utils";
|
||||||
|
|
||||||
export const isSampleRow = (raw: string) => raw.replace(/\s+/g, "") === "사례수";
|
export const isSampleRow = (raw: string) => raw.replace(/\s+/g, "") === "사례수";
|
||||||
|
|
||||||
@@ -45,6 +46,35 @@ export function formatRowLabel(
|
|||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const wrapSampleRow = <T extends Record<string, unknown> & { 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])
|
* @param years - 연도 배열 (예: [2024, 2025, 2026])
|
||||||
|
|||||||
Reference in New Issue
Block a user