260225_01_ENH: 실제 Data 통계 API와 연결 및 일부 페이지 축소
This commit is contained in:
@@ -17,34 +17,65 @@ import {
|
||||
type TopChartTableRow,
|
||||
VerticalBar,
|
||||
} from "@/components/lge-dashboard";
|
||||
import { apiTrendBuy } from "@/config/sample.data";
|
||||
import { useLayoutFilter } from "@/components/layout/LayoutFilterContext";
|
||||
import { formatRowLabel } from "@/lib/lg-dashboard";
|
||||
import {calcGapProductRow, formatRowLabel, normalizeFilterCondition, withGapRow} from "@/lib/lg-dashboard";
|
||||
import {buildHeader_ProductKeyMap, exportDashboardExcel} from "@/lib/lg-export-excel";
|
||||
import {useDebouncedValue} from "@/hooks/useDebouncedValue";
|
||||
import {SelectedMap} from "@/types/common";
|
||||
import {StatisticsRequest} from "@/types/lg";
|
||||
import {useProductStatisticsQuery} from "@/hooks/useLgStatisticsQuery";
|
||||
|
||||
const PurchasePage = () => {
|
||||
const { filterValue, registerExcelExporter } = useLayoutFilter();
|
||||
console.log(filterValue);
|
||||
const debouncedFilterValue = useDebouncedValue<SelectedMap>(filterValue as SelectedMap, 500);
|
||||
|
||||
const req = useMemo<StatisticsRequest>(() => {
|
||||
return {
|
||||
variableIdMap: { purchase: "KQA3_2"},
|
||||
bannerIdList: ["product"],
|
||||
filterCondition: normalizeFilterCondition(debouncedFilterValue),
|
||||
option: { useCache: true, lastYear: false, decimalPoint: 0 },
|
||||
};
|
||||
}, [debouncedFilterValue]);
|
||||
|
||||
const { data, isError, error } = useProductStatisticsQuery(req);
|
||||
|
||||
if(isError){
|
||||
console.error(error);
|
||||
}
|
||||
|
||||
const purchaseRows =
|
||||
data?.statisticsDataMap?.purchase
|
||||
.filter((r) => r.rowLabel == `해당년도`)
|
||||
.map((row) => {
|
||||
return {
|
||||
...row,
|
||||
rowLabel: row.year,
|
||||
}
|
||||
}) ?? [];
|
||||
|
||||
const purchaseRowsWithGap = useMemo(() => {
|
||||
return withGapRow(purchaseRows, calcGapProductRow);
|
||||
}, [purchaseRows]);
|
||||
|
||||
const purchaseTableRows = useMemo<TopChartTableRow[]>(() => {
|
||||
return apiTrendBuy.map((row) => ({
|
||||
return purchaseRowsWithGap.map((row) => ({
|
||||
label: formatRowLabel(row.rowLabel),
|
||||
total: row.total,
|
||||
values: PRODUCT_KEYS.map((k) => (row as any)[k] ?? null),
|
||||
}));
|
||||
}, []);
|
||||
}, [purchaseRowsWithGap]);
|
||||
|
||||
const purchaseChartData = useMemo<ChartData>(() => {
|
||||
return {
|
||||
categories: [...PRODUCTS],
|
||||
series: apiTrendBuy
|
||||
.filter((r) => r.rowLabel.endsWith("년"))
|
||||
series: purchaseRows
|
||||
.map((r) => ({
|
||||
name: r.rowLabel,
|
||||
data: PRODUCT_KEYS.map((k) => (r as any)[k] ?? null),
|
||||
})),
|
||||
};
|
||||
}, []);
|
||||
}, [purchaseRows]);
|
||||
|
||||
const description = useMemo(() => {
|
||||
return "Q. 다음 중 귀댁에서 보유하고 계신 가전/전자 제품은 무엇입니까? 모두 선택해주세요.<br/>" +
|
||||
@@ -63,12 +94,12 @@ const PurchasePage = () => {
|
||||
fileName: `${SITE_TITLE}(구매율).xlsx`,
|
||||
sheetName: "구매율",
|
||||
sections: [
|
||||
{ title: "구매율", header: excelHeader, rows: apiTrendBuy, rowGap: 1 },
|
||||
{ title: "구매율", header: excelHeader, rows: purchaseRowsWithGap, rowGap: 1 },
|
||||
],
|
||||
});
|
||||
});
|
||||
return () => registerExcelExporter(null);
|
||||
}, [registerExcelExporter]);
|
||||
}, [registerExcelExporter, purchaseRowsWithGap]);
|
||||
|
||||
return (
|
||||
<div>
|
||||
|
||||
Reference in New Issue
Block a user