260331_02_ENH: 그룹 헤더 다단도 가능하게 수정
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user