260303_01_ENH: 카테고리 파트 구조 정리
This commit is contained in:
@@ -1,57 +0,0 @@
|
||||
'use client'
|
||||
import {useLayoutFilter} from "@/components/layout/LayoutFilterContext";
|
||||
import {CategoryTargetData} from "@/config/filter.types";
|
||||
import Profile from "./category-page/Profile";
|
||||
import PenetrationChange from "./category-page/PenetrationChange";
|
||||
import {BannerRow, CategoryResolvedField, StatisticsRequest} from "@/types/lg";
|
||||
import {useDebouncedValue} from "@/hooks/useDebouncedValue";
|
||||
import {CategoryFilterValue} from "@/components/layout/CategoryFilter";
|
||||
import {useMemo} from "react";
|
||||
import {buildCategoryFilter, buildPageModeConfig} from "@/lib/lg-dashboard";
|
||||
import {BANNER_GROUP_KEY} from "@/const/lgConst";
|
||||
import {useBannerStatisticsQuery} from "@/hooks/useLgStatisticsQuery";
|
||||
import CategoryDetail from "@/components/lge-dashboard/sub-page/category-page/CategoryDetail";
|
||||
|
||||
export type CategoryPageProps = {
|
||||
fields: CategoryResolvedField[];
|
||||
variableIdMap: Record<string, string>;
|
||||
dataMap:Record<string, BannerRow[]> | undefined;
|
||||
}
|
||||
|
||||
const PAGE_COMPONENTS: Partial<Record<CategoryTargetData, React.ComponentType<CategoryPageProps>>> = {
|
||||
[CategoryTargetData.PROFILE]: Profile,
|
||||
[CategoryTargetData.PENETRATION_CHANGE]: PenetrationChange,
|
||||
[CategoryTargetData.BRAND]: CategoryDetail,
|
||||
[CategoryTargetData.TYPE_SPEC]: CategoryDetail,
|
||||
[CategoryTargetData.BEHAVIOR]: CategoryDetail,
|
||||
[CategoryTargetData.PURCHASE_CHANNEL]: CategoryDetail,
|
||||
[CategoryTargetData.PAYMENT_METHOD]: CategoryDetail,
|
||||
};
|
||||
|
||||
const CategoryPage = () => {
|
||||
const { isTotal, filterValue } = useLayoutFilter();
|
||||
const debouncedFilterValue = useDebouncedValue<CategoryFilterValue>(filterValue as CategoryFilterValue, 500);
|
||||
|
||||
const { fields, variableIdMap } = useMemo(() => {
|
||||
return buildPageModeConfig(debouncedFilterValue);
|
||||
}, [debouncedFilterValue]);
|
||||
|
||||
const req = useMemo<StatisticsRequest>(() => {
|
||||
return {
|
||||
variableIdMap,
|
||||
bannerIdList: BANNER_GROUP_KEY,
|
||||
filterCondition: buildCategoryFilter(debouncedFilterValue),
|
||||
option: { useCache: true, lastYear: false, decimalPoint: 0 },
|
||||
};
|
||||
}, [variableIdMap, debouncedFilterValue]);
|
||||
|
||||
const { data } = useBannerStatisticsQuery(req);
|
||||
const dataMap = data?.statisticsDataMap;
|
||||
const target = debouncedFilterValue.target;
|
||||
const Comp = PAGE_COMPONENTS[target.value]
|
||||
|
||||
if(isTotal) return null;
|
||||
return Comp ? <Comp fields={fields} variableIdMap={variableIdMap} dataMap={dataMap} /> : null;
|
||||
}
|
||||
|
||||
export default CategoryPage;
|
||||
@@ -1,85 +0,0 @@
|
||||
import {CategoryPageProps} from "@/components/lge-dashboard/sub-page/CategoryPage";
|
||||
import {useLayoutFilter} from "@/components/layout/LayoutFilterContext";
|
||||
import {useDebouncedValue} from "@/hooks/useDebouncedValue";
|
||||
import {CategoryFilterValue} from "@/components/layout/CategoryFilter";
|
||||
import {useEffect, useMemo} from "react";
|
||||
import {BannerRow, PageData} from "@/types/lg";
|
||||
import {buildHeader_Banner, exportDashboardExcel, Section} from "@/lib/lg-export-excel";
|
||||
import {BANNER_GROUP, BANNER_KEY_MAP, SITE_TITLE, YEARS} from "@/const/lgConst";
|
||||
import {CategoryByData} from "@/components/lge-dashboard";
|
||||
|
||||
const CategoryDetail = ({
|
||||
fields,
|
||||
dataMap
|
||||
}:CategoryPageProps) => {
|
||||
const {filterValue, registerExcelExporter} = useLayoutFilter();
|
||||
const debouncedFilterValue = useDebouncedValue<CategoryFilterValue>(filterValue as CategoryFilterValue, 500);
|
||||
|
||||
const tableDataArray = useMemo<PageData<BannerRow>[]>(() => {
|
||||
const tempTableDataArray = fields.map((f) => {
|
||||
const dataLength = dataMap?.[f.requestKeyResolved].filter((row) => row.rowLabel !=`사례수`).length;
|
||||
|
||||
return {
|
||||
title: typeof f.title === "string"? f.title : f.title[debouncedFilterValue.type.value],
|
||||
chartMode:f.chartMode,
|
||||
chartLegend:f.chartLegend,
|
||||
chartTopMargin:f.chartTopMargin,
|
||||
data: dataLength && dataLength > 0 ? dataMap[f.requestKeyResolved] : []
|
||||
};
|
||||
});
|
||||
|
||||
//사례수만 있는 테이블은 아예 제외
|
||||
return tempTableDataArray.filter((tableData) => tableData.data.length > 0);
|
||||
}, [debouncedFilterValue, fields, dataMap]);
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
registerExcelExporter(async () => {
|
||||
const product = debouncedFilterValue.product;
|
||||
const type = debouncedFilterValue.type.label;
|
||||
const target = debouncedFilterValue.target.label.replaceAll('/', '_');
|
||||
|
||||
const sheetName = `${product}_${type}_${target}`
|
||||
const h3 = buildHeader_Banner(BANNER_GROUP, BANNER_KEY_MAP);
|
||||
|
||||
type AnyRow = Record<string, any>;
|
||||
const sections: Section<AnyRow>[] = tableDataArray.flatMap((tableData) => {
|
||||
const years = [YEARS.at(-1), YEARS.at(-2)];
|
||||
|
||||
return years.map((year) => ({
|
||||
title: `${tableData.title}_${year}년`,
|
||||
header: h3,
|
||||
rows: tableData.data.filter((d) => d.year === year) as AnyRow[],
|
||||
rowGap: 1,
|
||||
}));
|
||||
});
|
||||
|
||||
await exportDashboardExcel({
|
||||
fileName: `${SITE_TITLE}(${sheetName}).xlsx`,
|
||||
sheetName: sheetName,
|
||||
sections: sections,
|
||||
});
|
||||
});
|
||||
return () => registerExcelExporter(null);
|
||||
}, [registerExcelExporter, debouncedFilterValue, tableDataArray]);
|
||||
|
||||
return (
|
||||
<div>
|
||||
{tableDataArray.map((tableData) => (
|
||||
<CategoryByData
|
||||
key={`cbd-${tableData.title.replaceAll(/\s+/g, "_")}`}
|
||||
selectedYear={filterValue.year}
|
||||
title={tableData.title}
|
||||
chartMode={tableData.chartMode}
|
||||
chartLegend={tableData.chartLegend}
|
||||
chartTopMargin={tableData.chartTopMargin}
|
||||
allTableData={tableData.data}
|
||||
chartHeight={tableData.chartHeight}
|
||||
chartWidth={tableData.chartWidth}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default CategoryDetail;
|
||||
@@ -1,40 +0,0 @@
|
||||
'use client'
|
||||
|
||||
import BannerSummary from "@/components/lge-dashboard/combo/BannerSummary";
|
||||
import {useMemo} from "react";
|
||||
import {BannerRow} from "@/types/lg";
|
||||
import {CategoryPageProps} from "@/components/lge-dashboard/sub-page/CategoryPage";
|
||||
import {LAST_YEAR} from "@/const/lgConst";
|
||||
|
||||
const PenetrationChange = ({
|
||||
dataMap
|
||||
}:CategoryPageProps) => {
|
||||
|
||||
const penetrationChangeData = useMemo<BannerRow[]>(() => {
|
||||
if (dataMap === undefined) return [];
|
||||
|
||||
const tempProfileData: BannerRow[] = [];
|
||||
Object.keys(dataMap).forEach(requestKey => {
|
||||
const data = dataMap[requestKey];
|
||||
tempProfileData.push(
|
||||
...data.filter((r) => r.rowLabel === `사례수` && r.year === LAST_YEAR),
|
||||
...data.filter((r) => r.rowLabel === `보유`)
|
||||
.map((row) => {
|
||||
return {
|
||||
...row,
|
||||
rowLabel: row.year,
|
||||
}
|
||||
}));
|
||||
});
|
||||
|
||||
console.log(tempProfileData)
|
||||
|
||||
return tempProfileData;
|
||||
}, [dataMap]);
|
||||
|
||||
return(
|
||||
<BannerSummary data={penetrationChangeData} useChart={true} useYear={false} />
|
||||
);
|
||||
}
|
||||
|
||||
export default PenetrationChange
|
||||
@@ -1,79 +0,0 @@
|
||||
'use client'
|
||||
|
||||
import {useLayoutFilter} from "@/components/layout/LayoutFilterContext";
|
||||
import BannerSummary from "@/components/lge-dashboard/combo/BannerSummary";
|
||||
import {useMemo} from "react";
|
||||
import {BannerRow} from "@/types/lg";
|
||||
import {CategoryFilterValue} from "@/components/layout/CategoryFilter";
|
||||
import {useDebouncedValue} from "@/hooks/useDebouncedValue";
|
||||
import { calcGapBannerRow } from "@/lib/lg-dashboard";
|
||||
import {YEARS} from "@/const/lgConst";
|
||||
import {CategoryTargetType} from "@/config/filter.types";
|
||||
import {CategoryPageProps} from "@/components/lge-dashboard/sub-page/CategoryPage";
|
||||
|
||||
const Profile = ({
|
||||
dataMap
|
||||
}:CategoryPageProps) => {
|
||||
const { filterValue } = useLayoutFilter();
|
||||
const debouncedFilterValue = useDebouncedValue<CategoryFilterValue>(filterValue as CategoryFilterValue, 500);
|
||||
|
||||
const profileData = useMemo<BannerRow[]>(() => {
|
||||
if (dataMap === undefined) return [];
|
||||
|
||||
const targetMap = {
|
||||
[CategoryTargetType.PENETRATION]: "보유",
|
||||
[CategoryTargetType.PURCHASE]: "해당년도",
|
||||
[CategoryTargetType.INTENDED]: "향후구매",
|
||||
}
|
||||
|
||||
const tempProfileData: BannerRow[] = [];
|
||||
Object.keys(dataMap).forEach(requestKey => {
|
||||
const data = dataMap[requestKey];
|
||||
|
||||
if(requestKey.toLowerCase().endsWith("count")){
|
||||
tempProfileData.push(
|
||||
...data.filter((r) => r.rowLabel == `MEAN`)
|
||||
.map((row) => {
|
||||
return {
|
||||
...row,
|
||||
rowLabel: "보유대수",
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
else{
|
||||
const target = debouncedFilterValue.type.value;
|
||||
|
||||
tempProfileData.push(...data.filter((r) => r.rowLabel == `사례수`));
|
||||
|
||||
const targetData =
|
||||
data.filter((r) => r.rowLabel == targetMap[target])
|
||||
.map((row) => {
|
||||
return {
|
||||
...row,
|
||||
rowLabel: row.year,
|
||||
}
|
||||
})
|
||||
|
||||
tempProfileData.push(...targetData);
|
||||
|
||||
YEARS.forEach((year, idx) => {
|
||||
const after = targetData.find((r) => r.year == year)
|
||||
const before = idx == 0? undefined : targetData.find((r) => r.year == YEARS[idx-1]);
|
||||
|
||||
if (after && before) {
|
||||
tempProfileData.push(calcGapBannerRow(after, before));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return tempProfileData.sort((a, b) => Number(a.rowLabel === "보유대수") - Number(b.rowLabel === "보유대수"));
|
||||
}, [debouncedFilterValue, dataMap]);
|
||||
|
||||
return (
|
||||
<BannerSummary data={profileData} useChart={false} useYear={true} />
|
||||
);
|
||||
}
|
||||
|
||||
export default Profile;
|
||||
@@ -134,7 +134,7 @@ const DataTable = <T extends Record<string, unknown>>({
|
||||
const isTargetKey = (k: keyof T) => {
|
||||
if (!signStyle) return false;
|
||||
if (keys && keys.length) return keys.includes(k);
|
||||
// keys 미지정이면 numeric 컬럼 전체
|
||||
// keys.ts 미지정이면 numeric 컬럼 전체
|
||||
const col = columns.find((c) => c.key === k);
|
||||
return !!col?.numeric;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user