260720_01_ENH: 보유 대수 소수점 2자리까지 풀음, profile(전체) 추가
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { ChartData, DataColumn, DataTable, HorizontalBar, LeftChartTable, SignStyle } from "@/components/lge-dashboard";
|
||||
import { ChartData, DataColumn, DataTable, HorizontalBar, LeftChartTable, MergedTableCell, SignStyle } from "@/components/lge-dashboard";
|
||||
import { BannerKey, BannerRow } from "@/types/lg.types";
|
||||
import { buildBannerGroupColumns, formatRowLabel, isGapRow, wrapSampleRow } from "@/lib/lg-dashboard";
|
||||
import { useEffect, useMemo } from "react";
|
||||
@@ -30,13 +30,24 @@ const SEP_R = "lg-table__sep-r";
|
||||
const getSectionBannerKeys = (spec: SectionSpec): BannerKey[] =>
|
||||
spec.groupKeys.flatMap((gk) => flattenBannerGroupKeys(BANNER_GROUP[gk].children));
|
||||
|
||||
const buildColumns = (spec: SectionSpec, selectedYear: string): DataColumn<BannerRow>[] => {
|
||||
const buildColumns = (spec: SectionSpec, selectedYear: string, isProfileAll:boolean): DataColumn<BannerRow>[] => {
|
||||
const columns: DataColumn<BannerRow>[] = [
|
||||
...(isProfileAll
|
||||
? [
|
||||
{
|
||||
key: "year" as const,
|
||||
header: "",
|
||||
rowHead: true,
|
||||
headerClassName: "lg-table__no-border-r",
|
||||
width: 60,
|
||||
},
|
||||
]
|
||||
: []),
|
||||
{
|
||||
key: "rowLabel",
|
||||
header: `${selectedYear}년`,
|
||||
header: selectedYear ? `${selectedYear}년` : "",
|
||||
headerClassName: "lg-table__no-border-l",
|
||||
rowHead: true,
|
||||
cellClassName: "lg-table__rowhead",
|
||||
width: 120,
|
||||
},
|
||||
{
|
||||
@@ -71,14 +82,47 @@ const buildColumns = (spec: SectionSpec, selectedYear: string): DataColumn<Banne
|
||||
return columns;
|
||||
};
|
||||
|
||||
const buildYearMergedCells = (rows: BannerRow[]): MergedTableCell<BannerRow>[] => {
|
||||
const mergedCells: MergedTableCell<BannerRow>[] = [];
|
||||
let startRowIndex = 0;
|
||||
|
||||
while (startRowIndex < rows.length) {
|
||||
const year = rows[startRowIndex].year;
|
||||
let endRowIndex = startRowIndex + 1;
|
||||
|
||||
while (endRowIndex < rows.length && rows[endRowIndex].year === year) {
|
||||
endRowIndex += 1;
|
||||
}
|
||||
|
||||
mergedCells.push({
|
||||
key: "year",
|
||||
content: formatRowLabel(year),
|
||||
startRowIndex,
|
||||
rowSpan: endRowIndex - startRowIndex,
|
||||
className: "font-bold text-center",
|
||||
});
|
||||
|
||||
startRowIndex = endRowIndex;
|
||||
}
|
||||
|
||||
return mergedCells;
|
||||
};
|
||||
|
||||
type BannerSummaryProps = {
|
||||
data: BannerRow[];
|
||||
useChart: boolean;
|
||||
useYear: boolean;
|
||||
isProfileAll?: boolean;
|
||||
getCellClassName?: (row: BannerRow, column: DataColumn<BannerRow>, rowIndex: number) => string | undefined;
|
||||
};
|
||||
|
||||
const BannerSummary = ({ data, useChart, useYear, getCellClassName }: BannerSummaryProps) => {
|
||||
const BannerSummary = ({
|
||||
data,
|
||||
useChart,
|
||||
useYear,
|
||||
isProfileAll = false,
|
||||
getCellClassName
|
||||
}: BannerSummaryProps) => {
|
||||
const { filterValue, registerExcelExporter } = useLayoutFilter();
|
||||
const debouncedFilterValue = useDebouncedValue<CategoryFilterValue>(filterValue as CategoryFilterValue);
|
||||
|
||||
@@ -113,7 +157,7 @@ const BannerSummary = ({ data, useChart, useYear, getCellClassName }: BannerSumm
|
||||
return SECTIONS.map((spec) => {
|
||||
const specTitle = spec.title;
|
||||
const bannerKeys = getSectionBannerKeys(spec);
|
||||
const columns = buildColumns(spec, useYear ? debouncedFilterValue.year : "");
|
||||
const columns = buildColumns(spec, useYear ? debouncedFilterValue.year : "", isProfileAll);
|
||||
|
||||
// rows가 spec마다 다르면 여기서 가져오도록 구성
|
||||
const rows = wrapSampleRow(useYear ? data.filter((d) => d.year === debouncedFilterValue.year) : data).map((row) => {
|
||||
@@ -121,6 +165,7 @@ const BannerSummary = ({ data, useChart, useYear, getCellClassName }: BannerSumm
|
||||
return row;
|
||||
});
|
||||
const chartData = buildChartData(rows);
|
||||
const mergedCells = isProfileAll ? buildYearMergedCells(rows) : undefined;
|
||||
|
||||
return {
|
||||
spec,
|
||||
@@ -129,15 +174,28 @@ const BannerSummary = ({ data, useChart, useYear, getCellClassName }: BannerSumm
|
||||
columns,
|
||||
rows,
|
||||
chartData,
|
||||
mergedCells,
|
||||
};
|
||||
});
|
||||
}, [data, useYear, debouncedFilterValue.year]);
|
||||
}, [data, useYear, debouncedFilterValue.year, isProfileAll]);
|
||||
|
||||
const getTargetString = (target: CategoryTargetData): string => {
|
||||
switch (target) {
|
||||
case CategoryTargetData.PROFILE_ALL:
|
||||
return "Profile (전체)";
|
||||
case CategoryTargetData.PROFILE:
|
||||
return "Profile";
|
||||
default:
|
||||
return "보급률 변화"
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
registerExcelExporter(async () => {
|
||||
const product = debouncedFilterValue.product;
|
||||
const type = debouncedFilterValue.type.label;
|
||||
const target = debouncedFilterValue.target.value === CategoryTargetData.PROFILE ? "Profile" : "보급률 변화";
|
||||
|
||||
const target = getTargetString(debouncedFilterValue.target.value);
|
||||
const sheetName = `${product}_${type}_${target}`;
|
||||
|
||||
type AnyRow = Record<string, any>;
|
||||
@@ -195,6 +253,7 @@ const BannerSummary = ({ data, useChart, useYear, getCellClassName }: BannerSumm
|
||||
signStyle={signStyleGap}
|
||||
unitText={""}
|
||||
starUnder30Sample={true}
|
||||
mergedCells={sectionRow.mergedCells}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -62,13 +62,15 @@ export default function LeftChartTable<T extends Record<string, unknown>>({
|
||||
starUnder30Sample={starUnder30Sample}
|
||||
unitText={unitText}
|
||||
getCellClassName={getCellClassName}
|
||||
mergedCell={{
|
||||
key: chartCell.key,
|
||||
content: chart,
|
||||
startRowIndex: chartCell.startRowIndex,
|
||||
rowSpan: chartCell.rowSpan,
|
||||
className: chartCell.className,
|
||||
}}
|
||||
mergedCells={[
|
||||
{
|
||||
key: chartCell.key,
|
||||
content: chart,
|
||||
startRowIndex: chartCell.startRowIndex,
|
||||
rowSpan: chartCell.rowSpan,
|
||||
className: chartCell.className,
|
||||
},
|
||||
]}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user