260225_01_ENH: 실제 Data 통계 API와 연결 및 일부 페이지 축소
This commit is contained in:
@@ -11,7 +11,6 @@ import {
|
||||
type GroupedStackBarData, BottomDescription,
|
||||
} from "@/components/lge-dashboard";
|
||||
import { useLayoutFilter } from "@/components/layout/LayoutFilterContext";
|
||||
import {apiBrandByYearCategories, apiTrendCategories} from "@/config/sample.data";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
BRAND_LIST,
|
||||
@@ -19,40 +18,89 @@ import {
|
||||
PRODUCTS,
|
||||
YEARS,
|
||||
AXIS_HIDE_STYLE,
|
||||
GRID_X_NOT_PADDING, PRODUCT_KEY_MAP, LAST_YEAR, SITE_TITLE,
|
||||
GRID_X_NOT_PADDING, PRODUCT_KEY_MAP, SITE_TITLE
|
||||
} from "@/const/lgConst";
|
||||
import { formatRowLabel } from "@/lib/lg-dashboard";
|
||||
import {
|
||||
calcCagrRow, calcGapProductRow,
|
||||
formatRowLabel,
|
||||
normalizeFilterCondition, withCagrRow, withGapRow
|
||||
} from "@/lib/lg-dashboard";
|
||||
import {buildHeader_ProductKeyMap, exportDashboardExcel, Section} from "@/lib/lg-export-excel";
|
||||
import {StatisticsRequest} from "@/types/lg";
|
||||
import {useProductStatisticsQuery} from "@/hooks/useLgStatisticsQuery";
|
||||
import {useDebouncedValue} from "@/hooks/useDebouncedValue";
|
||||
import {toNumOr0} from "@/lib/utils";
|
||||
import {SelectedMap} from "@/types/common";
|
||||
|
||||
const PenetrationPage = () => {
|
||||
const { filterValue, registerExcelExporter } = useLayoutFilter();
|
||||
console.log(filterValue);
|
||||
|
||||
const debouncedFilterValue = useDebouncedValue<SelectedMap>(filterValue as SelectedMap, 500);
|
||||
const [isBrandShare, setIsBrandShare] = useState(false);
|
||||
|
||||
const chartColorByYear = Object.fromEntries(
|
||||
YEARS.map((year, i) => [
|
||||
year,
|
||||
[`--chart-cbrand-${i + 1}`,`--chart-samsung-${i + 1}`,`--chart-lg-${i + 1}`],
|
||||
])
|
||||
) as Record<(typeof YEARS)[number], string[]>;
|
||||
|
||||
const req = useMemo<StatisticsRequest>(() => {
|
||||
return {
|
||||
variableIdMap: { penetration: "KQA1", penetration_brand: "KQA3_3_NET" },
|
||||
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 penetrationRows =
|
||||
data?.statisticsDataMap?.penetration
|
||||
.filter((r) => r.rowLabel == `보유`)
|
||||
.map((row) => {
|
||||
return {
|
||||
...row,
|
||||
rowLabel: row.year,
|
||||
}
|
||||
}) ?? [];
|
||||
|
||||
const penetrationBrandRows =
|
||||
data?.statisticsDataMap?.penetration_brand
|
||||
.filter((row) => BRAND_LIST.includes(row.rowLabel)) ?? [];
|
||||
|
||||
const penetrationRowsWithGapCagr = useMemo(() => {
|
||||
const withGap = withGapRow(penetrationRows, calcGapProductRow);
|
||||
return withCagrRow(withGap, calcCagrRow);
|
||||
}, [penetrationRows]);
|
||||
|
||||
const productTableRows = useMemo<TopChartTableRow[]>(() => {
|
||||
return apiTrendCategories.map((row) => ({
|
||||
return penetrationRowsWithGapCagr.map((row) => ({
|
||||
label: formatRowLabel(row.rowLabel),
|
||||
total: row.total,
|
||||
values: PRODUCT_KEYS.map((k) => (row as any)[k] ?? null),
|
||||
}));
|
||||
}, []);
|
||||
}))
|
||||
}, [penetrationRowsWithGapCagr]);
|
||||
|
||||
const productChartData = useMemo<ChartData>(() => {
|
||||
return {
|
||||
categories: [...PRODUCTS],
|
||||
series: apiTrendCategories
|
||||
.filter((r) => r.rowLabel.endsWith("년"))
|
||||
.map((r) => ({
|
||||
name: r.rowLabel,
|
||||
data: PRODUCT_KEYS.map((k) => (r as any)[k] ?? null),
|
||||
})),
|
||||
series: penetrationRows
|
||||
.map((row) => ({
|
||||
name: row.year,
|
||||
data: PRODUCT_KEYS.map((k) => toNumOr0((row as any)[k])),
|
||||
})),
|
||||
};
|
||||
}, []);
|
||||
}, [penetrationRows]);
|
||||
|
||||
const brandShareChartData = useMemo<GroupedStackBarData>(() => {
|
||||
const rowMap = new Map<string, (typeof apiBrandByYearCategories)[number]>();
|
||||
for (const r of apiBrandByYearCategories) {
|
||||
|
||||
const rowMap = new Map<string, (typeof penetrationBrandRows)[number]>();
|
||||
for (const r of penetrationBrandRows) {
|
||||
rowMap.set(`${r.year}__${r.rowLabel}`, r);
|
||||
}
|
||||
|
||||
@@ -70,7 +118,7 @@ const PenetrationPage = () => {
|
||||
});
|
||||
|
||||
return { categories: PRODUCTS, years: YEARS, brands: BRAND_LIST, values };
|
||||
}, []);
|
||||
}, [penetrationBrandRows]);
|
||||
|
||||
const description = useMemo(() => {
|
||||
if(isBrandShare){
|
||||
@@ -78,7 +126,7 @@ const PenetrationPage = () => {
|
||||
}
|
||||
|
||||
return "Q. 다음 중 귀댁에서 보유하고 계신 가전/전자 제품은 무엇입니까? 모두 선택해주세요.<br/>" +
|
||||
"* 구독/렌탈/선물/경품/아파트 내 빌트인 제품을 모두 포함하여 선택해주세요.";
|
||||
"* 구독/렌탈/선물/경품/아파트 내 빌트인 제품을 모두 포함하여 선택해주세요.";
|
||||
}, [isBrandShare]);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -87,12 +135,12 @@ const PenetrationPage = () => {
|
||||
type AnyRow = Record<string, any>;
|
||||
|
||||
const sections: Section<AnyRow>[] = [
|
||||
{ title: "전체 보급률", header: excelHeader, rows: apiTrendCategories, rowGap: 1 },
|
||||
{ title: "전체 보급률", header: excelHeader, rows: penetrationRowsWithGapCagr, rowGap: 1 },
|
||||
...YEARS.map((year) => (
|
||||
{
|
||||
title: `브랜드 별 점유율_${year}년`,
|
||||
header: excelHeader,
|
||||
rows: apiBrandByYearCategories.filter((row) => row.year === year) as AnyRow[],
|
||||
rows: penetrationBrandRows.filter((row) => row.year === year),
|
||||
rowGap: 1,
|
||||
}
|
||||
))
|
||||
@@ -105,7 +153,7 @@ const PenetrationPage = () => {
|
||||
});
|
||||
});
|
||||
return () => registerExcelExporter(null);
|
||||
}, [registerExcelExporter]);
|
||||
}, [registerExcelExporter, penetrationRows, penetrationBrandRows]);
|
||||
|
||||
return (
|
||||
<div>
|
||||
@@ -131,11 +179,8 @@ const PenetrationPage = () => {
|
||||
xAxis={{ type: "category", data: PRODUCTS, ...AXIS_HIDE_STYLE }}
|
||||
yAxis={{ type: "value", ...AXIS_HIDE_STYLE }}
|
||||
showFocusLabel={"none"}
|
||||
yearBrandPalette={{
|
||||
"24": ["--chart-cbrand-1", "--chart-samsung-1", "--chart-lg-1"],
|
||||
"25": ["--chart-cbrand-2", "--chart-samsung-2", "--chart-lg-2"],
|
||||
"26": ["--chart-cbrand-3", "--chart-samsung-3", "--chart-lg-3"],
|
||||
}}
|
||||
yearBrandPalette={chartColorByYear}
|
||||
height={260}
|
||||
/>
|
||||
) : (
|
||||
<VerticalBar
|
||||
|
||||
Reference in New Issue
Block a user