260331_02_ENH: 그룹 헤더 다단도 가능하게 수정

This commit is contained in:
2026-03-31 11:08:30 +09:00
parent e51c6ba810
commit d58c0b4dd4
13 changed files with 577 additions and 622 deletions

View File

@@ -6,8 +6,9 @@ import {
StatisticsRequest
} from "@/types/lg.types";
import {ChartData} from "@/components/lge-dashboard";
import type { DataColumn } from "@/components/lge-dashboard/types";
import {API_DECIMAL_POINT, GAP_WORDING, VIEW_DECIMAL_POINT} from "@/const/lg-common.const";
import {BANNER_GROUP, BANNER_KEYS} from "@/const/lg-banner.const";
import {BANNER_GROUP, BANNER_KEYS, type BannerGroupDefinition, type BannerGroupNode, flattenBannerGroupKeys} from "@/const/lg-banner.const";
import {PRODUCT_KEYS} from "@/const/lg-product.const";
import {CATEGORY_PAGE_FIELDS} from "@/config/lg-page.config";
import {formatNumber} from "@/lib/utils";
@@ -316,6 +317,47 @@ export const buildGapRow = (
export const isBannerGroupKey = (v: string): v is BannerGroupKey => v in BANNER_GROUP;
export function buildBannerGroupColumns<T extends Record<string, unknown>>(
group: BannerGroupDefinition,
keyLabelMap: Record<string, string>,
options: {
width?: number | string;
numeric?: boolean;
resolveLeafMeta?: (key: string, index: number, total: number) => {
headerClassName?: string;
cellClassName?: string;
};
} = {}
): DataColumn<T>[] {
const leafKeys = flattenBannerGroupKeys(group.children);
let leafIndex = 0;
const visit = (nodes: readonly BannerGroupNode[]): DataColumn<T>[] =>
nodes.map((node) => {
if (node.type === "leaf") {
const currentLeafIndex = leafIndex++;
const meta = options.resolveLeafMeta?.(node.key, currentLeafIndex, leafKeys.length);
return {
key: node.key as keyof T,
header: keyLabelMap[node.key] ?? String(node.key),
numeric: options.numeric,
width: options.width,
headerClassName: meta?.headerClassName,
cellClassName: meta?.cellClassName,
};
}
return {
id: node.id,
header: node.label,
children: visit(node.children),
};
});
return visit(group.children);
}
export const fetchProductStatistics = (req: StatisticsRequest) =>
nextApi.post<ProductResponse>("/statistics/product", req);