260205_01_ENH: 페이지 별 엑셀 다운로드 적용
This commit is contained in:
@@ -1,9 +1,22 @@
|
||||
import {ChartData, DataColumn, DataTable, HorizontalBar, LeftChartTable, SignStyle} from "@/components/lge-dashboard";
|
||||
import {BannerKey, ServerBannerRow} from "@/types/lg";
|
||||
import {formatRowLabel, wrapSampleRow} from "@/lib/lg-dashboard";
|
||||
import {useMemo} from "react";
|
||||
import {BANNER_GROUP, BANNER_KEY_MAP, GRID_Y_NOT_PADDING} from "@/const/lgConst";
|
||||
import {useEffect, useMemo} from "react";
|
||||
import {
|
||||
BANNER_GROUP,
|
||||
BANNER_KEY_MAP,
|
||||
GRID_Y_NOT_PADDING,
|
||||
LAST_YEAR,
|
||||
} from "@/const/lgConst";
|
||||
import {parseNumber} from "@/lib/utils";
|
||||
import {
|
||||
buildHeader_DataColumn,
|
||||
exportDashboardExcel,
|
||||
Section
|
||||
} from "@/lib/lg-export-excel";
|
||||
import {useLayoutFilter} from "@/components/layout/LayoutFilterContext";
|
||||
import {CategoryTypeValue} from "@/components/layout/CategoryFilter";
|
||||
import {CategoryTargetData} from "@/config/filter.types";
|
||||
|
||||
|
||||
type SectionSpec = {
|
||||
@@ -37,6 +50,7 @@ const buildColumns = (spec: SectionSpec): DataColumn<ServerBannerRow>[] => {
|
||||
key: "total",
|
||||
header: "전체",
|
||||
numeric: true,
|
||||
headRowSpan: 2,
|
||||
headerClassName: SEP_R,
|
||||
cellClassName: SEP_R,
|
||||
width: 80,
|
||||
@@ -68,25 +82,27 @@ type BannerSummaryProps = {
|
||||
};
|
||||
|
||||
const BannerSummary = ({ data, useChart }: BannerSummaryProps) => {
|
||||
const {filterValue, registerExcelExporter } = useLayoutFilter();
|
||||
|
||||
const buildChartData = (rows: ServerBannerRow[], bannerKeys: BannerKey[]): ChartData => {
|
||||
const categories = rows
|
||||
.filter((r) => !r.rowLabel.includes("사례수"))
|
||||
.map((r) => formatRowLabel(r.rowLabel));
|
||||
.map((r) => formatRowLabel(r.rowLabel))
|
||||
.reverse();
|
||||
|
||||
const series = [
|
||||
{
|
||||
name:"전체",
|
||||
data: rows
|
||||
.filter((r) => !r.rowLabel.includes("사례수"))
|
||||
.map((r) => parseNumber(r.total) ?? null),
|
||||
.map((r) => parseNumber(r.total) ?? null)
|
||||
.reverse(),
|
||||
}
|
||||
];
|
||||
|
||||
return { categories, series };
|
||||
};
|
||||
|
||||
const rows = useMemo<ServerBannerRow[]>(() => wrapSampleRow(data), [data]);
|
||||
|
||||
const signStyleGap: SignStyle<ServerBannerRow> = {
|
||||
rowSelector: (row) => row.rowLabel === "gap",
|
||||
display: "arrow",
|
||||
@@ -95,31 +111,73 @@ const BannerSummary = ({ data, useChart }: BannerSummaryProps) => {
|
||||
zeroText: "-",
|
||||
};
|
||||
|
||||
|
||||
const sectionRows = useMemo(() => {
|
||||
return SECTIONS.map((spec) => {
|
||||
const specTitle = spec.title;
|
||||
|
||||
const bannerKeys = getSectionBannerKeys(spec);
|
||||
const columns = buildColumns(spec);
|
||||
|
||||
// rows가 spec마다 다르면 여기서 가져오도록 구성
|
||||
const rows = wrapSampleRow(data);
|
||||
const chartData = buildChartData(rows, bannerKeys);
|
||||
|
||||
return {
|
||||
spec,
|
||||
specTitle,
|
||||
bannerKeys,
|
||||
columns,
|
||||
rows,
|
||||
chartData,
|
||||
};
|
||||
});
|
||||
}, [data]);
|
||||
|
||||
useEffect(() => {
|
||||
registerExcelExporter(async (payload) => {
|
||||
const targetString =filterValue.target === CategoryTargetData.PROFILE? "Profile" : "보급률 변화"
|
||||
const sheetName = `${filterValue.product}_${(filterValue.type as CategoryTypeValue).label}_${targetString}`
|
||||
|
||||
type AnyRow = Record<string, any>;
|
||||
const sections: Section<AnyRow>[] =
|
||||
sectionRows.map((sectionRow) => ({
|
||||
title: sectionRow.specTitle,
|
||||
header: buildHeader_DataColumn(sectionRow.columns),
|
||||
rows: sectionRow.rows as AnyRow[],
|
||||
rowGap: 1,
|
||||
}))
|
||||
;
|
||||
|
||||
await exportDashboardExcel({
|
||||
fileName: `20${LAST_YEAR}년도 가전 보급률 Dashboard(${sheetName}).xlsx`,
|
||||
sheetName: sheetName,
|
||||
sections: sections,
|
||||
});
|
||||
});
|
||||
return () => registerExcelExporter(null);
|
||||
}, [registerExcelExporter]);
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-6">
|
||||
{SECTIONS.map((spec) => {
|
||||
const bannerKeys = getSectionBannerKeys(spec);
|
||||
|
||||
const columns = buildColumns(spec);
|
||||
const chartData = buildChartData(rows, bannerKeys);
|
||||
|
||||
{sectionRows.map((sectionRow) => {
|
||||
return (
|
||||
useChart ?
|
||||
<LeftChartTable<ServerBannerRow>
|
||||
key={spec.title}
|
||||
title={spec.title}
|
||||
columns={columns}
|
||||
rows={rows}
|
||||
key={sectionRow.specTitle}
|
||||
title={sectionRow.specTitle}
|
||||
columns={sectionRow.columns}
|
||||
rows={sectionRow.rows}
|
||||
signStyle={signStyleGap}
|
||||
chart={
|
||||
<HorizontalBar
|
||||
data={chartData}
|
||||
data={sectionRow.chartData}
|
||||
height="100%"
|
||||
showFocusLabel="none"
|
||||
legend={{ show: false }}
|
||||
grid={GRID_Y_NOT_PADDING}
|
||||
xAxis={{ type: "value", show: false }}
|
||||
yAxis={{ type: "category", data: chartData.categories, show: false }}
|
||||
yAxis={{ type: "category", data: sectionRow.chartData.categories, show: false }}
|
||||
/>
|
||||
}
|
||||
chartCell={{ key: "total", startRowIndex: 1 }}
|
||||
@@ -127,10 +185,10 @@ const BannerSummary = ({ data, useChart }: BannerSummaryProps) => {
|
||||
/>
|
||||
:
|
||||
<DataTable<ServerBannerRow>
|
||||
key={spec.title}
|
||||
title={spec.title}
|
||||
columns={columns}
|
||||
rows={rows}
|
||||
key={sectionRow.specTitle}
|
||||
title={sectionRow.specTitle}
|
||||
columns={sectionRow.columns}
|
||||
rows={sectionRow.rows}
|
||||
signStyle={signStyleGap}
|
||||
/>
|
||||
);
|
||||
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
} from "@/components/lge-dashboard";
|
||||
import BannerButtons from "@/components/lge-dashboard/BannerButtons";
|
||||
import {totalFilters} from "@/config/filter.data";
|
||||
import {useMemo, useState} from "react";
|
||||
import {useEffect, useMemo, useState} from "react";
|
||||
import {BannerGroupKey, CategoryChartMode, ServerBannerRow} from "@/types/lg";
|
||||
import {
|
||||
buildRowLabelSeriesChartData,
|
||||
@@ -17,6 +17,8 @@ import {
|
||||
} from "@/lib/lg-dashboard";
|
||||
import {BANNER_GROUP, BANNER_KEY_MAP, LAST_YEAR} from "@/const/lgConst";
|
||||
import {createDefaultGrid, createDefaultLegend, reverseCategories} from "@/lib/chart-options";
|
||||
import {useLayoutFilter} from "@/components/layout/LayoutFilterContext";
|
||||
import {CategoryTypeValue} from "@/components/layout/CategoryFilter";
|
||||
|
||||
type CategoryByDataProps = {
|
||||
title?: string;
|
||||
@@ -90,7 +92,7 @@ const CategoryByData = ({
|
||||
return isBannerGroupKey(v) ? buildColumns(v) : [];
|
||||
}, [selectedBanner.variable]);
|
||||
|
||||
const tableData = useMemo(() => wrapSampleRow(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 (
|
||||
<div>
|
||||
|
||||
@@ -1,54 +1,13 @@
|
||||
import GaugeCardTable from "./GaugeCardTable";
|
||||
import {GaugeColumn} from "@/components/lge-dashboard";
|
||||
import {useMemo} from "react";
|
||||
import {apiLifeStageByProduct} from "@/config/sample.data";
|
||||
import {LifeStageRow} from "@/types/lg";
|
||||
import {asNum, norm} from "@/lib/utils";
|
||||
import {LIFE_STAGE_COLUMNS} from "@/const/lgConst";
|
||||
import {LifeStageGroup} from "@/types/lg";
|
||||
|
||||
const LifeStageDiv = () => {
|
||||
const LIFE_STAGE_COLUMNS: GaugeColumn<LifeStageRow>[] = [
|
||||
{ key: "item", header: "", rowHead: true, renderLabel: (r) => r.item },
|
||||
type lifeStageDivProps = {
|
||||
lifeStageRowsByGroup:LifeStageGroup[];
|
||||
}
|
||||
|
||||
{ key: "total", header: "전체", max: 100, align: "left", cellType:"number"},
|
||||
{ key: "single", header: "미혼", max: 100 , align: "left"},
|
||||
|
||||
{ key: "noKids", header: "무자녀", group: "기혼", max: 100 , align: "left"},
|
||||
{ key: "preschoolKids", header: "미취학", group: "기혼", max: 100 , align: "left"},
|
||||
{ key: "schoolKids", header: "취학자녀", group: "기혼", max: 100 , align: "left"},
|
||||
{ key: "adultKids", header: "성인자녀", group: "기혼", max: 100 , align: "left"},
|
||||
|
||||
{ key: "independentSenior", header: "독립\n시니어", max: 100 , align: "left"},
|
||||
];
|
||||
|
||||
const LIFE_STAGE_GROUPS = [
|
||||
{ title: "대형가전 군", items: ["냉장고", "세탁기", "건조기", "에어컨", "TV", "김치 냉장고", "식기세척기", "의류 관리기"] },
|
||||
{ title: "소형가전 군", items: ["청소기", "공기 청정기", "정수기"] },
|
||||
{ title: "신가전 군", items: ["로봇 청소기", "음식물처리기"] },
|
||||
] as const;
|
||||
|
||||
const lifeStageRowsByGroup = useMemo(() => {
|
||||
const pick = (label: string) => apiLifeStageByProduct.find((r) => norm(r.rowLabel) === norm(label));
|
||||
|
||||
return LIFE_STAGE_GROUPS.map((g) => {
|
||||
const rows: LifeStageRow[] = g.items.map((label) => {
|
||||
const r = pick(label);
|
||||
|
||||
return {
|
||||
item: label,
|
||||
total: asNum((r as any)?.total), // 서버에 all이 없으면 null로 남음
|
||||
single: asNum((r as any)?.single),
|
||||
noKids: asNum((r as any)?.noKids),
|
||||
preschoolKids: asNum((r as any)?.preschoolKids),
|
||||
schoolKids: asNum((r as any)?.schoolKids),
|
||||
adultKids: asNum((r as any)?.adultKids),
|
||||
independentSenior: asNum((r as any)?.independentSenior),
|
||||
};
|
||||
});
|
||||
|
||||
return { title: g.title, rows };
|
||||
});
|
||||
}, []);
|
||||
|
||||
const LifeStageDiv = ({lifeStageRowsByGroup}:lifeStageDivProps) => {
|
||||
return (
|
||||
<div className="mt-6">
|
||||
<div className="flex justify-end gap-6 text-xs text-muted-foreground mb-2">
|
||||
|
||||
Reference in New Issue
Block a user