260225_01_ENH: 실제 Data 통계 API와 연결 및 일부 페이지 축소
This commit is contained in:
19
src/components/common/ReactQueryLoadingSync.tsx
Normal file
19
src/components/common/ReactQueryLoadingSync.tsx
Normal file
@@ -0,0 +1,19 @@
|
||||
"use client";
|
||||
|
||||
import {useIsFetching} from "@tanstack/react-query";
|
||||
import {useLoading} from "@/hooks/useLoading";
|
||||
import {useEffect} from "react";
|
||||
|
||||
const ReactQueryLoadingSync = () => {
|
||||
const fetching = useIsFetching();
|
||||
const { showLoading, hideLoading } = useLoading();
|
||||
|
||||
useEffect(() => {
|
||||
if (fetching > 0) showLoading();
|
||||
else hideLoading();
|
||||
}, [fetching, showLoading, hideLoading]);
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
export default ReactQueryLoadingSync;
|
||||
@@ -1,13 +1,16 @@
|
||||
"use client";
|
||||
|
||||
import {CategoryTargetData, CategoryTargetType, TotalFilterItem} from "@/config/filter.types";
|
||||
import {
|
||||
CategoryTargetType,
|
||||
TargetChild,
|
||||
} from "@/config/filter.types";
|
||||
import {categoryTarget, categoryTargetType} from "@/config/filter.data";
|
||||
import { ChevronRight } from "lucide-react";
|
||||
import {useCallback, useMemo} from "react";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {ProductsFilterItem} from "@/types/lg";
|
||||
import {YEARS} from "@/const/lgConst";
|
||||
import {ProductKey, ProductsFilterItem} from "@/types/lg";
|
||||
import {PRODUCT_KEY_MAP, YEARS} from "@/const/lgConst";
|
||||
|
||||
export type CategoryTypeValue = {
|
||||
label: string;
|
||||
@@ -15,10 +18,10 @@ export type CategoryTypeValue = {
|
||||
};
|
||||
|
||||
export type CategoryFilterValue = {
|
||||
product: string;
|
||||
product: ProductKey;
|
||||
year: string;
|
||||
type: CategoryTypeValue
|
||||
target: CategoryTargetData;
|
||||
target: TargetChild;
|
||||
};
|
||||
|
||||
type CategoryFilterProps = {
|
||||
@@ -28,7 +31,7 @@ type CategoryFilterProps = {
|
||||
className?: string;
|
||||
};
|
||||
|
||||
type Option = { key: string; label: string; value: string | CategoryTypeValue | CategoryTargetData };
|
||||
type Option = { key: string; label: string; value: string | CategoryTypeValue | TargetChild };
|
||||
|
||||
type RowDef = {
|
||||
id: "year" | "product" | "type" | "target";
|
||||
@@ -75,27 +78,36 @@ const CategoryFilter = ({ filterItems, value, onChange, className }: CategoryFil
|
||||
|
||||
// type 비교는 객체참조가 아니라 value로 비교해야 함
|
||||
const handlePick = useCallback(
|
||||
(key: keyof CategoryFilterValue, v: string | CategoryTypeValue | CategoryTargetData) => {
|
||||
// same check
|
||||
if (key === "type" && typeof v === "object" && "value" in v) {
|
||||
if (value.type.value === v.value) return;
|
||||
|
||||
const nextItem = categoryTarget.find((item) => item.type.includes(v.value));
|
||||
const firstTarget = nextItem?.children?.[0]?.target;
|
||||
<K extends keyof CategoryFilterValue>(key: K, v: CategoryFilterValue[K]) => {
|
||||
// 1) type
|
||||
if (key === "type") {
|
||||
const nextType = v as CategoryTypeValue;
|
||||
if (value.type.value === nextType.value) return;
|
||||
|
||||
const nextItem = categoryTarget.find((item) =>
|
||||
item.type.includes(nextType.value)
|
||||
);
|
||||
const firstTarget = nextItem?.children?.[0];
|
||||
onChange({
|
||||
...value,
|
||||
type: v,
|
||||
target: (firstTarget ?? value.target) as CategoryTargetData,
|
||||
type: nextType,
|
||||
target: firstTarget ?? value.target,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (key !== "type") {
|
||||
// string/primitive 비교
|
||||
if ((value as any)[key] === v) return;
|
||||
onChange({ ...value, [key]: v } as CategoryFilterValue);
|
||||
// 2) target (객체 비교는 value로)
|
||||
if (key === "target") {
|
||||
const nextTarget = v as TargetChild;
|
||||
if (value.target.value === nextTarget.value) return;
|
||||
|
||||
onChange({ ...value, target: nextTarget });
|
||||
return;
|
||||
}
|
||||
|
||||
// 3) year/product (primitive)
|
||||
if (value[key] === v) return;
|
||||
onChange({ ...value, [key]: v } as CategoryFilterValue);
|
||||
},
|
||||
[value, onChange]
|
||||
);
|
||||
@@ -106,7 +118,7 @@ const CategoryFilter = ({ filterItems, value, onChange, className }: CategoryFil
|
||||
title: "연도",
|
||||
options:(YEARS).map((y) => ({
|
||||
key:y,
|
||||
label:`20${y}년`,
|
||||
label:`${y}년`,
|
||||
value:y,
|
||||
})),
|
||||
isActive: (v) => value.year === v,
|
||||
@@ -118,11 +130,11 @@ const CategoryFilter = ({ filterItems, value, onChange, className }: CategoryFil
|
||||
title: "제품",
|
||||
options: (filterItems.items ?? []).map((p) => ({
|
||||
key: p,
|
||||
label: p,
|
||||
label: PRODUCT_KEY_MAP[p],
|
||||
value: p,
|
||||
})),
|
||||
isActive: (v) => value.product === v,
|
||||
onSelect: (v) => handlePick("product", v as string),
|
||||
onSelect: (v) => handlePick("product", v as ProductKey),
|
||||
};
|
||||
|
||||
const typeRow: RowDef = {
|
||||
@@ -133,10 +145,7 @@ const CategoryFilter = ({ filterItems, value, onChange, className }: CategoryFil
|
||||
label: t.label,
|
||||
value: { label: t.label, value: t.value },
|
||||
})),
|
||||
isActive: (v) => {
|
||||
const vv = v as CategoryTypeValue;
|
||||
return value.type.value === vv.value;
|
||||
},
|
||||
isActive: (v) => value.type.value === (v as CategoryTypeValue).value,
|
||||
onSelect: (v) => handlePick("type", v as CategoryTypeValue),
|
||||
};
|
||||
|
||||
@@ -144,14 +153,13 @@ const CategoryFilter = ({ filterItems, value, onChange, className }: CategoryFil
|
||||
id: "target",
|
||||
title: "데이터",
|
||||
options: (currentTargetItem?.children ?? []).map((c) => ({
|
||||
key: String(c.target),
|
||||
key: String(c.value),
|
||||
label: c.label,
|
||||
value: c.target,
|
||||
value: { label: c.label, value: c.value },
|
||||
})),
|
||||
isActive: (v) => value.target === v,
|
||||
onSelect: (v) => handlePick("target", v as CategoryTargetData),
|
||||
isActive: (v) => value.target.value === (v as TargetChild).value,
|
||||
onSelect: (v) => handlePick("target", v as TargetChild),
|
||||
};
|
||||
|
||||
// 여기 순서만 바꾸면 배치도 같이 바뀜 (left: 앞쪽 half, right: 뒤쪽 half)
|
||||
return [yearRow, productRow, typeRow, targetRow];
|
||||
}, [YEARS, filterItems.items, currentTargetItem, value, handlePick]);
|
||||
|
||||
@@ -34,8 +34,8 @@ const buildDefaultTotalValue = (): SelectedMap => {
|
||||
const buildDefaultCategoryValue = (categoryFilterItems: ProductsFilterItem): CategoryFilterValue => {
|
||||
const initProduct = categoryFilterItems.items[0];
|
||||
const initType = {label:"보유", value:CategoryTargetType.PENETRATION}
|
||||
const firstTarget = categoryTarget.find((x) => x.type.includes(initType.value))?.children?.[0]?.target;
|
||||
const initTarget = firstTarget ?? CategoryTargetData.PROFILE;
|
||||
const firstTarget = categoryTarget.find((x) => x.type.includes(initType.value))?.children[0];
|
||||
const initTarget = firstTarget ?? { value: CategoryTargetData.PROFILE, label: "Profile"};
|
||||
|
||||
return {
|
||||
year: LAST_YEAR,
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
"use client";
|
||||
|
||||
import dynamic from "next/dynamic";
|
||||
import { useMemo } from "react";
|
||||
import type { EChartsOption } from "echarts";
|
||||
import { CHART_HEIGHTS } from "@/const/chartConst";
|
||||
import {useResizeKey} from "@/hooks/useResize";
|
||||
|
||||
const ReactECharts = dynamic(() => import("echarts-for-react"), { ssr: false });
|
||||
|
||||
type BaseEChartProps = {
|
||||
option: EChartsOption;
|
||||
height?: number | string;
|
||||
className?: string;
|
||||
className?: string; // wrapper용
|
||||
contentClassName?: string; // 안쪽 wrapper
|
||||
chartClassName?: string; // ReactECharts용
|
||||
/** echarts-for-react의 notMerge/lazyUpdate 옵션 필요 시 */
|
||||
notMerge?: boolean;
|
||||
lazyUpdate?: boolean;
|
||||
@@ -22,16 +24,27 @@ const BaseEChart = ({
|
||||
option,
|
||||
height = CHART_HEIGHTS.DEFAULT,
|
||||
className,
|
||||
contentClassName,
|
||||
chartClassName,
|
||||
notMerge = true,
|
||||
lazyUpdate = false, //이거 켜져있으면 오류남 Cannot read properties of undefined (reading 'getRawIndex')
|
||||
onEvents,
|
||||
}: BaseEChartProps) => {
|
||||
const style = useMemo(() => ({ height }), [height]);
|
||||
|
||||
const resizeKey = useResizeKey(150);
|
||||
|
||||
return (
|
||||
<div className={className}>
|
||||
<ReactECharts option={option} style={style} notMerge={notMerge} lazyUpdate={lazyUpdate} onEvents={onEvents} />
|
||||
<div className={className} style={{ display: "flex", flexDirection: "column", height: height }}>
|
||||
<div className={contentClassName} style={{ flex: 1, minHeight: 0 }}>
|
||||
<ReactECharts
|
||||
key={resizeKey}
|
||||
option={option}
|
||||
className={chartClassName}
|
||||
style={{ width: "100%", height: "100%" }}
|
||||
notMerge={notMerge}
|
||||
lazyUpdate={lazyUpdate}
|
||||
onEvents={onEvents}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -15,10 +15,11 @@ import { GroupedOverlayBarData, ShowLabel} from "../types";
|
||||
import {getIsShowLabel, roundedRectIcon} from "@/components/lge-dashboard/chart/utill";
|
||||
import {AXIS_HIDE_STYLE} from "@/const/lgConst";
|
||||
import { CHART_HEIGHTS, LEGEND_ITEM_SIZE } from "@/const/chartConst";
|
||||
import {makeTotalBasePct} from "@/lib/lg-dashboard";
|
||||
|
||||
type Props = {
|
||||
data: GroupedOverlayBarData;
|
||||
height?: number;
|
||||
height?: number | string;
|
||||
|
||||
tooltip?: TooltipComponentOption;
|
||||
grid?: GridComponentOption;
|
||||
@@ -111,7 +112,7 @@ const GroupedOverlayBar = ({
|
||||
for (let yi = 0; yi < years.length; yi++) {
|
||||
const year = years[yi];
|
||||
const yearLabel = `${year}년`;
|
||||
const isOn = yearSelected[yearLabel] !== false;
|
||||
const isOn = yearSelected[yearLabel];
|
||||
|
||||
const totalRow = data.total?.[yi] ?? [];
|
||||
const focusRow = data.focus?.[yi] ?? [];
|
||||
@@ -227,8 +228,9 @@ const GroupedOverlayBar = ({
|
||||
const v = map.get(y)!;
|
||||
const t = v.total ?? 0;
|
||||
const f = v.focus ?? 0;
|
||||
const pct = t > 0 ? ` (${Math.round((f / t) * 100)}%)` : "";
|
||||
return `${totalName} ${t} 중 ${focusName} ${f}${pct}`;
|
||||
const pct = makeTotalBasePct(t, f);
|
||||
const pctStr = pct > 0 ? ` (${pct}%)` : "";
|
||||
return `${totalName} ${t} 중 ${focusName} ${f}${pctStr}`;
|
||||
});
|
||||
|
||||
return [header, ...lines].join("<br/>");
|
||||
|
||||
@@ -14,11 +14,11 @@ import { GroupedStackBarData, ShowLabel} from "../types";
|
||||
import { buildLgPalette } from "@/components/lge-dashboard/color";
|
||||
import {getIsShowLabel, roundedRectIcon} from "@/components/lge-dashboard/chart/utill";
|
||||
import {AXIS_HIDE_STYLE} from "@/const/lgConst";
|
||||
import { CHART_HEIGHTS, LEGEND_ITEM_SIZE } from "@/const/chartConst";
|
||||
import { LEGEND_ITEM_SIZE } from "@/const/chartConst";
|
||||
|
||||
type Props = {
|
||||
data: GroupedStackBarData;
|
||||
height?: number;
|
||||
height?: number | string;
|
||||
|
||||
tooltip?: TooltipComponentOption;
|
||||
grid?: GridComponentOption;
|
||||
@@ -34,7 +34,7 @@ type Props = {
|
||||
|
||||
const GroupedStackBar = ({
|
||||
data,
|
||||
height = CHART_HEIGHTS.DEFAULT,
|
||||
height,
|
||||
tooltip,
|
||||
grid,
|
||||
xAxis,
|
||||
@@ -61,6 +61,7 @@ const GroupedStackBar = ({
|
||||
const defaultYAxis: EChartsOption["yAxis"] = { type: "value", ...AXIS_HIDE_STYLE };
|
||||
|
||||
const latestYear = years.at(-1);
|
||||
console.log(yearBrandPalette, String(latestYear), yearBrandPalette?.[String(latestYear)])
|
||||
const latestPalette = buildLgPalette(yearBrandPalette?.[String(latestYear)]);
|
||||
|
||||
const yearLegendTokens = years.map((y) => {
|
||||
@@ -111,7 +112,7 @@ const GroupedStackBar = ({
|
||||
const brand = brands[bi];
|
||||
const row = data.values?.[yi]?.[bi] ?? [];
|
||||
|
||||
const isYearOn = yearSelected[yearLabel] !== false;
|
||||
const isYearOn = yearSelected[yearLabel];
|
||||
const showLabel = getIsShowLabel(showFocusLabel, yi, years.length);
|
||||
|
||||
realSeries.push({
|
||||
|
||||
@@ -50,13 +50,11 @@ const StackBar = ({
|
||||
isReverse = false,
|
||||
}: Props) => {
|
||||
|
||||
// ✅ 렌더링용 데이터만 뒤집기
|
||||
const renderData = useMemo(
|
||||
() => (isReverse ? reverseSeries(data) : data),
|
||||
[data, isReverse]
|
||||
);
|
||||
|
||||
// ✅ 팔레트도 뒤집어줘야 "시리즈 이름별" 색이 유지됨
|
||||
const palette = useMemo(() => {
|
||||
const temp = buildLgPalette(paletteVarNames);
|
||||
const n = data.series.length; // 원본 기준
|
||||
@@ -67,7 +65,7 @@ const StackBar = ({
|
||||
const option: EChartsOption = useMemo(() => {
|
||||
const fmt = valueFormatter ?? ((v: number) => String(v));
|
||||
const isV = orientation === "vertical";
|
||||
console.log(isReverse)
|
||||
|
||||
return {
|
||||
color: palette,
|
||||
tooltip: tooltip ?? (isReverse ? createReverseTooltip(data, fmt) : createDefaultTooltip(fmt)),
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import {ChartData, DataColumn, DataTable, HorizontalBar, LeftChartTable, SignStyle} from "@/components/lge-dashboard";
|
||||
import {BannerKey, ServerBannerRow} from "@/types/lg";
|
||||
import {BannerKey, BannerRow} from "@/types/lg";
|
||||
import {formatRowLabel, isGapRow, wrapSampleRow} from "@/lib/lg-dashboard";
|
||||
import {useEffect, useMemo} from "react";
|
||||
import {
|
||||
@@ -15,8 +15,9 @@ import {
|
||||
Section
|
||||
} from "@/lib/lg-export-excel";
|
||||
import {useLayoutFilter} from "@/components/layout/LayoutFilterContext";
|
||||
import {CategoryTypeValue} from "@/components/layout/CategoryFilter";
|
||||
import {CategoryFilterValue} from "@/components/layout/CategoryFilter";
|
||||
import {CategoryTargetData} from "@/config/filter.types";
|
||||
import {useDebouncedValue} from "@/hooks/useDebouncedValue";
|
||||
|
||||
|
||||
type SectionSpec = {
|
||||
@@ -36,11 +37,11 @@ const SEP_R = "lg-table__sep-r";
|
||||
const getSectionBannerKeys = (spec: SectionSpec): BannerKey[] =>
|
||||
spec.groupKeys.flatMap((gk) => BANNER_GROUP[gk].keys);
|
||||
|
||||
const buildColumns = (spec: SectionSpec, selectedYear:string): DataColumn<ServerBannerRow>[] => {
|
||||
const columns: DataColumn<ServerBannerRow>[] = [
|
||||
const buildColumns = (spec: SectionSpec, selectedYear:string): DataColumn<BannerRow>[] => {
|
||||
const columns: DataColumn<BannerRow>[] = [
|
||||
{
|
||||
key: "rowLabel",
|
||||
header: `20${selectedYear}년`,
|
||||
header: `${selectedYear}년`,
|
||||
headRowSpan: 2,
|
||||
rowHead: true,
|
||||
cellClassName: "lg-table__rowhead",
|
||||
@@ -77,15 +78,16 @@ const buildColumns = (spec: SectionSpec, selectedYear:string): DataColumn<Server
|
||||
};
|
||||
|
||||
type BannerSummaryProps = {
|
||||
data: ServerBannerRow[];
|
||||
data: BannerRow[];
|
||||
useChart: boolean;
|
||||
useYear: boolean;
|
||||
};
|
||||
|
||||
const BannerSummary = ({ data, useChart, useYear }: BannerSummaryProps) => {
|
||||
const {filterValue, registerExcelExporter } = useLayoutFilter();
|
||||
const debouncedFilterValue = useDebouncedValue<CategoryFilterValue>(filterValue as CategoryFilterValue, 500);
|
||||
|
||||
const buildChartData = (rows: ServerBannerRow[], bannerKeys: BannerKey[]): ChartData => {
|
||||
const buildChartData = (rows: BannerRow[]): ChartData => {
|
||||
const categories = rows
|
||||
.filter((r) => !r.rowLabel.includes("사례수"))
|
||||
.map((r) => formatRowLabel(r.rowLabel))
|
||||
@@ -104,7 +106,7 @@ const BannerSummary = ({ data, useChart, useYear }: BannerSummaryProps) => {
|
||||
return { categories, series };
|
||||
};
|
||||
|
||||
const signStyleGap: SignStyle<ServerBannerRow> = {
|
||||
const signStyleGap: SignStyle<BannerRow> = {
|
||||
rowSelector: (row) => isGapRow(row.rowLabel),
|
||||
display: "arrow",
|
||||
arrowWithNumber: true,
|
||||
@@ -127,7 +129,7 @@ const BannerSummary = ({ data, useChart, useYear }: BannerSummaryProps) => {
|
||||
row.rowLabel = formatRowLabel(row.rowLabel);
|
||||
return row
|
||||
})
|
||||
const chartData = buildChartData(rows, bannerKeys);
|
||||
const chartData = buildChartData(rows);
|
||||
|
||||
return {
|
||||
spec,
|
||||
@@ -141,9 +143,12 @@ const BannerSummary = ({ data, useChart, useYear }: BannerSummaryProps) => {
|
||||
}, [data, useYear, filterValue.year]);
|
||||
|
||||
useEffect(() => {
|
||||
registerExcelExporter(async (payload) => {
|
||||
const targetString =filterValue.target === CategoryTargetData.PROFILE? "Profile" : "보급률 변화"
|
||||
const sheetName = `${filterValue.product}_${(filterValue.type as CategoryTypeValue).label}_${targetString}`
|
||||
registerExcelExporter(async () => {
|
||||
const product = debouncedFilterValue.product;
|
||||
const type = debouncedFilterValue.type.label;
|
||||
const target = debouncedFilterValue.target.value === CategoryTargetData.PROFILE? "Profile" : "보급률 변화"
|
||||
|
||||
const sheetName = `${product}_${type}_${target}`
|
||||
|
||||
type AnyRow = Record<string, any>;
|
||||
const sections: Section<AnyRow>[] =
|
||||
@@ -162,7 +167,7 @@ const BannerSummary = ({ data, useChart, useYear }: BannerSummaryProps) => {
|
||||
});
|
||||
});
|
||||
return () => registerExcelExporter(null);
|
||||
}, [registerExcelExporter]);
|
||||
}, [registerExcelExporter, debouncedFilterValue, sectionRows]);
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-6">
|
||||
@@ -171,7 +176,7 @@ const BannerSummary = ({ data, useChart, useYear }: BannerSummaryProps) => {
|
||||
<div key={`div_${sectionRow.specTitle}`}>
|
||||
{
|
||||
useChart ?
|
||||
<LeftChartTable<ServerBannerRow>
|
||||
<LeftChartTable<BannerRow>
|
||||
key={sectionRow.specTitle}
|
||||
title={sectionRow.specTitle}
|
||||
columns={sectionRow.columns}
|
||||
@@ -193,7 +198,7 @@ const BannerSummary = ({ data, useChart, useYear }: BannerSummaryProps) => {
|
||||
starUnder30Sample={true}
|
||||
/>
|
||||
:
|
||||
<DataTable<ServerBannerRow>
|
||||
<DataTable<BannerRow>
|
||||
key={sectionRow.specTitle}
|
||||
title={sectionRow.specTitle}
|
||||
columns={sectionRow.columns}
|
||||
|
||||
@@ -8,32 +8,31 @@ import {
|
||||
import BannerButtons from "@/components/lge-dashboard/BannerButtons";
|
||||
import {totalFilters} from "@/config/filter.data";
|
||||
import React, {useMemo, useState} from "react";
|
||||
import {BannerGroupKey, CategoryChartMode, ServerBannerRow} from "@/types/lg";
|
||||
import {BannerGroupKey, CategoryChartMode, BannerRow} from "@/types/lg";
|
||||
import {
|
||||
buildRowLabelSeriesChartData,
|
||||
buildYearSeriesChartData, formatRowLabel,
|
||||
isBannerGroupKey, isGapRow,
|
||||
wrapSampleRow
|
||||
} from "@/lib/lg-dashboard";
|
||||
import {BANNER_GROUP, BANNER_KEY_MAP, GAP_WORDING, SAMPLE_SIZE_NOTICE, UNIT_TEXT} from "@/const/lgConst";
|
||||
import {createDefaultGrid, createDefaultLegend, reverseCategories} from "@/lib/chart-options";
|
||||
import {BANNER_GROUP, BANNER_KEY_MAP} from "@/const/lgConst";
|
||||
import {createDefaultGrid, reverseCategories} from "@/lib/chart-options";
|
||||
|
||||
type CategoryByDataProps = {
|
||||
selectedYear: string;
|
||||
title?: string;
|
||||
chartMode: CategoryChartMode;
|
||||
allTableData: ServerBannerRow[];
|
||||
allTableData: BannerRow[];
|
||||
fillGreaterThan5?: boolean;
|
||||
chartHeight?: number;
|
||||
chartHeight?: number | string;
|
||||
chartWidth?: number;
|
||||
unitText?: string;
|
||||
}
|
||||
|
||||
const banners: bannerType[] = totalFilters.map((filter) => {
|
||||
return {variable: filter.variable, variableName: filter.variableName}
|
||||
})
|
||||
|
||||
const signStyleGap: SignStyle<ServerBannerRow> = {
|
||||
const signStyleGap: SignStyle<BannerRow> = {
|
||||
rowSelector: (row) => isGapRow(row.rowLabel),
|
||||
display: "arrow",
|
||||
arrowWithNumber: true,
|
||||
@@ -49,15 +48,14 @@ const CategoryByData = ({
|
||||
fillGreaterThan5,
|
||||
chartHeight,
|
||||
chartWidth,
|
||||
unitText = UNIT_TEXT,
|
||||
}: CategoryByDataProps) => {
|
||||
const [selectedBanner, setSelectedBanner] = useState<bannerType>(banners[0]);
|
||||
|
||||
const buildColumns = (groupKey: BannerGroupKey, selectedYear:string): DataColumn<ServerBannerRow>[] => {
|
||||
const columns: DataColumn<ServerBannerRow>[] = [
|
||||
const buildColumns = (groupKey: BannerGroupKey, selectedYear:string): DataColumn<BannerRow>[] => {
|
||||
const columns: DataColumn<BannerRow>[] = [
|
||||
{
|
||||
key: "rowLabel",
|
||||
header: `20${selectedYear}년`,
|
||||
header: `${selectedYear}년`,
|
||||
headRowSpan: 2,
|
||||
rowHead: true,
|
||||
cellClassName: "lg-table__rowhead",
|
||||
@@ -111,22 +109,34 @@ const CategoryByData = ({
|
||||
</div>
|
||||
<div className="flex gap-6 p-3">
|
||||
<div className="flex-shrink-0" style={{ width: `${chartWidth ?? 400}px`}}>
|
||||
{
|
||||
chartMode === "stack" || chartMode === "reverseStack" ?
|
||||
<StackBar
|
||||
data={chartData}
|
||||
height={`${chartHeight ?? 340}px`}
|
||||
grid={createDefaultGrid("default", { top: 52 })}
|
||||
isReverse={chartMode === "reverseStack"}
|
||||
/>
|
||||
:
|
||||
<HorizontalBar
|
||||
data={chartData}
|
||||
height={`${chartHeight ?? 340}px`}
|
||||
showFocusLabel="none"
|
||||
paletteVarNames={chartData.series.length === 1? ["--chart-1"]: ["--chart-2","--chart-1"]}
|
||||
/>
|
||||
}
|
||||
{(() => {
|
||||
switch (chartMode) {
|
||||
case "horizontal":
|
||||
return (
|
||||
<HorizontalBar
|
||||
data={chartData}
|
||||
height={chartHeight}
|
||||
showFocusLabel="none"
|
||||
paletteVarNames={
|
||||
chartData.series.length === 1 ? ["--chart-1"] : ["--chart-2", "--chart-1"]
|
||||
}
|
||||
/>
|
||||
);
|
||||
case "stack":
|
||||
case "reverseStack":
|
||||
return (
|
||||
<StackBar
|
||||
data={chartData}
|
||||
height={chartHeight}
|
||||
grid={createDefaultGrid("default", { top: 52 })}
|
||||
isReverse={chartMode === "reverseStack"}
|
||||
/>
|
||||
);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
})()}
|
||||
|
||||
</div>
|
||||
|
||||
<div className="flex items-center">
|
||||
|
||||
@@ -3,46 +3,55 @@ 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 Brand from "./category-page/Brand";
|
||||
import TypeSpec from "./category-page/TypeSpec";
|
||||
import OwnershipPath from "./category-page/OwnershipPath";
|
||||
import PurchaseBehavior from "./category-page/PurchaseBehavior";
|
||||
import PurchaseChannel from "./category-page/PurchaseChannel";
|
||||
import PaymentMethod from "./category-page/PaymentMethod";
|
||||
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();
|
||||
console.log(filterValue);
|
||||
const debouncedFilterValue = useDebouncedValue<CategoryFilterValue>(filterValue as CategoryFilterValue, 500);
|
||||
|
||||
const renderPage = () => {
|
||||
if (isTotal) return null;
|
||||
const { fields, variableIdMap } = useMemo(() => {
|
||||
return buildPageModeConfig(debouncedFilterValue);
|
||||
}, [debouncedFilterValue]);
|
||||
|
||||
const target = filterValue.target;
|
||||
const req = useMemo<StatisticsRequest>(() => {
|
||||
return {
|
||||
variableIdMap,
|
||||
bannerIdList: BANNER_GROUP_KEY,
|
||||
filterCondition: buildCategoryFilter(debouncedFilterValue),
|
||||
option: { useCache: false, lastYear: false, decimalPoint: 0 },
|
||||
};
|
||||
}, [variableIdMap, debouncedFilterValue]);
|
||||
|
||||
switch (target) {
|
||||
case CategoryTargetData.PROFILE:
|
||||
return <Profile />;
|
||||
case CategoryTargetData.PENETRATION_CHANGE:
|
||||
return <PenetrationChange />;
|
||||
case CategoryTargetData.BRAND:
|
||||
return <Brand />;
|
||||
case CategoryTargetData.TYPE_SPEC:
|
||||
return <TypeSpec />;
|
||||
case CategoryTargetData.OWNERSHIP_PATH:
|
||||
return <OwnershipPath />;
|
||||
case CategoryTargetData.PURCHASE_BEHAVIOR:
|
||||
return <PurchaseBehavior />;
|
||||
case CategoryTargetData.PURCHASE_CHANNEL:
|
||||
return <PurchaseChannel />;
|
||||
case CategoryTargetData.PAYMENT_METHOD:
|
||||
return <PaymentMethod />;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
};
|
||||
const { data } = useBannerStatisticsQuery(req);
|
||||
const dataMap = data?.statisticsDataMap;
|
||||
const target = debouncedFilterValue.target;
|
||||
const Comp = PAGE_COMPONENTS[target.value]
|
||||
|
||||
return renderPage();
|
||||
if(isTotal) return null;
|
||||
return Comp ? <Comp fields={fields} variableIdMap={variableIdMap} dataMap={dataMap} /> : null;
|
||||
}
|
||||
|
||||
export default CategoryPage;
|
||||
@@ -1,26 +1,43 @@
|
||||
'use client'
|
||||
|
||||
import {useEffect, useMemo} from "react";
|
||||
import {CategoryByData} from "@/components/lge-dashboard";
|
||||
import {apiBrandShareByYear} from "@/config/sample.data";
|
||||
import {PageData, ServerBannerRow} from "@/types/lg";
|
||||
import {buildGapRow} from "@/lib/lg-dashboard";
|
||||
import {BANNER_GROUP, BANNER_KEY_MAP, SITE_TITLE, YEARS} from "@/const/lgConst";
|
||||
import {CategoryPageProps} from "@/components/lge-dashboard/sub-page/CategoryPage";
|
||||
import {useLayoutFilter} from "@/components/layout/LayoutFilterContext";
|
||||
import {CategoryTypeValue} from "@/components/layout/CategoryFilter";
|
||||
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 Brand = () => {
|
||||
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,
|
||||
data: dataLength && dataLength > 0 ? dataMap[f.requestKeyResolved] : []
|
||||
};
|
||||
});
|
||||
|
||||
//사례수만 있는 테이블은 아예 제외
|
||||
return tempTableDataArray.filter((tableData) => tableData.data.length > 0);
|
||||
}, [debouncedFilterValue, fields, dataMap]);
|
||||
|
||||
const tableDataArray = useMemo<PageData<ServerBannerRow>[]>(() => [
|
||||
{title: "브랜드", chartMode:"reverseStack", data: apiBrandShareByYear, chartHeight:400},
|
||||
], []);
|
||||
|
||||
useEffect(() => {
|
||||
registerExcelExporter(async (payload) => {
|
||||
registerExcelExporter(async () => {
|
||||
const product = debouncedFilterValue.product;
|
||||
const type = debouncedFilterValue.type.label;
|
||||
const target = debouncedFilterValue.target.label.replaceAll('/', '_');
|
||||
|
||||
const sheetName = `${filterValue.product}_${(filterValue.type as CategoryTypeValue).label}_브랜드`
|
||||
const sheetName = `${product}_${type}_${target}`
|
||||
const h3 = buildHeader_Banner(BANNER_GROUP, BANNER_KEY_MAP);
|
||||
|
||||
type AnyRow = Record<string, any>;
|
||||
@@ -42,7 +59,7 @@ const Brand = () => {
|
||||
});
|
||||
});
|
||||
return () => registerExcelExporter(null);
|
||||
}, [registerExcelExporter]);
|
||||
}, [registerExcelExporter, debouncedFilterValue, tableDataArray]);
|
||||
|
||||
return (
|
||||
<div>
|
||||
@@ -61,4 +78,4 @@ const Brand = () => {
|
||||
);
|
||||
}
|
||||
|
||||
export default Brand;
|
||||
export default CategoryDetail;
|
||||
@@ -1,65 +0,0 @@
|
||||
'use client'
|
||||
|
||||
import {useLayoutFilter} from "@/components/layout/LayoutFilterContext";
|
||||
import {useEffect, useMemo, useState} from "react";
|
||||
import {PageData, ServerBannerRow} from "@/types/lg";
|
||||
import {apiOwnershipPathByYear, apiOwnershipTriggerByYear} from "@/config/sample.data";
|
||||
import {CategoryByData} from "@/components/lge-dashboard";
|
||||
import {BANNER_GROUP, BANNER_KEY_MAP, SITE_TITLE, YEARS} from "@/const/lgConst";
|
||||
import {CategoryTypeValue} from "@/components/layout/CategoryFilter";
|
||||
import {buildHeader_Banner, exportDashboardExcel, Section} from "@/lib/lg-export-excel";
|
||||
|
||||
const OwnershipPath = () => {
|
||||
const { filterValue, registerExcelExporter } = useLayoutFilter();
|
||||
console.log(filterValue);
|
||||
|
||||
const tableDataArray = useMemo<PageData<ServerBannerRow>[]>(() => [
|
||||
{title: "보유 경로", chartMode:"reverseStack", data: apiOwnershipPathByYear},
|
||||
{title: "구입 계기", chartMode:"horizontal", data: apiOwnershipTriggerByYear, chartHeight: 510,},
|
||||
], []);
|
||||
|
||||
useEffect(() => {
|
||||
registerExcelExporter(async (payload) => {
|
||||
|
||||
const sheetName = `${filterValue.product}_${(filterValue.type as CategoryTypeValue).label}_보유 경로`
|
||||
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]);
|
||||
|
||||
return (
|
||||
<div>
|
||||
{tableDataArray.map((tableData) => (
|
||||
<CategoryByData
|
||||
key={`cbd-${tableData.title.replaceAll(/\s+/g, "_")}`}
|
||||
selectedYear={filterValue.year}
|
||||
title={tableData.title}
|
||||
chartMode={tableData.chartMode}
|
||||
allTableData={tableData.data}
|
||||
chartHeight={tableData.chartHeight}
|
||||
chartWidth={tableData.chartWidth}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default OwnershipPath;
|
||||
@@ -1,64 +0,0 @@
|
||||
'use client'
|
||||
|
||||
import {useLayoutFilter} from "@/components/layout/LayoutFilterContext";
|
||||
import {apiPaymentMethodByYear} from "@/config/sample.data";
|
||||
import {useEffect, useMemo} from "react";
|
||||
import {PageData, ServerBannerRow} from "@/types/lg";
|
||||
import {CategoryByData} from "@/components/lge-dashboard";
|
||||
import {BANNER_GROUP, BANNER_KEY_MAP, SITE_TITLE, YEARS} from "@/const/lgConst";
|
||||
import {CategoryTypeValue} from "@/components/layout/CategoryFilter";
|
||||
import {buildHeader_Banner, exportDashboardExcel, Section} from "@/lib/lg-export-excel";
|
||||
|
||||
const PaymentMethod = () => {
|
||||
const { filterValue, registerExcelExporter } = useLayoutFilter();
|
||||
console.log(filterValue);
|
||||
|
||||
const tableDataArray = useMemo<PageData<ServerBannerRow>[]>(() => [
|
||||
{title: "구매 형식", chartMode:"reverseStack", data: apiPaymentMethodByYear},
|
||||
], []);
|
||||
|
||||
useEffect(() => {
|
||||
registerExcelExporter(async (payload) => {
|
||||
|
||||
const sheetName = `${filterValue.product}_${(filterValue.type as CategoryTypeValue).label}_구매 형식`
|
||||
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]);
|
||||
|
||||
return (
|
||||
<div>
|
||||
{tableDataArray.map((tableData) => (
|
||||
<CategoryByData
|
||||
key={`cbd-${tableData.title.replaceAll(/\s+/g, "_")}`}
|
||||
selectedYear={filterValue.year}
|
||||
title={tableData.title}
|
||||
chartMode={tableData.chartMode}
|
||||
allTableData={tableData.data}
|
||||
chartHeight={tableData.chartHeight}
|
||||
chartWidth={tableData.chartWidth}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default PaymentMethod;
|
||||
@@ -1,16 +1,36 @@
|
||||
'use client'
|
||||
|
||||
import {useLayoutFilter} from "@/components/layout/LayoutFilterContext";
|
||||
import BannerSummary from "@/components/lge-dashboard/combo/BannerSummary";
|
||||
import {useMemo} from "react";
|
||||
import {ServerBannerRow} from "@/types/lg";
|
||||
import {apiYearIndex} from "@/config/sample.data";
|
||||
import {BannerRow} from "@/types/lg";
|
||||
import {CategoryPageProps} from "@/components/lge-dashboard/sub-page/CategoryPage";
|
||||
import {LAST_YEAR} from "@/const/lgConst";
|
||||
|
||||
const PenetrationChange = () => {
|
||||
const { filterValue } = useLayoutFilter();
|
||||
console.log(filterValue);
|
||||
const PenetrationChange = ({
|
||||
dataMap
|
||||
}:CategoryPageProps) => {
|
||||
|
||||
const penetrationChangeData = useMemo<ServerBannerRow[]>(() => apiYearIndex, []);
|
||||
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} />
|
||||
|
||||
@@ -3,28 +3,73 @@
|
||||
import {useLayoutFilter} from "@/components/layout/LayoutFilterContext";
|
||||
import BannerSummary from "@/components/lge-dashboard/combo/BannerSummary";
|
||||
import {useMemo} from "react";
|
||||
import {ServerBannerRow} from "@/types/lg";
|
||||
import {apiOwnershipSummary, apiPurchaseRateKpis} from "@/config/sample.data";
|
||||
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 = () => {
|
||||
const { isTotal, filterValue } = useLayoutFilter();
|
||||
const Profile = ({
|
||||
dataMap
|
||||
}:CategoryPageProps) => {
|
||||
const { filterValue } = useLayoutFilter();
|
||||
const debouncedFilterValue = useDebouncedValue<CategoryFilterValue>(filterValue as CategoryFilterValue, 500);
|
||||
|
||||
const profileData = useMemo<ServerBannerRow[]>(() => {
|
||||
if (isTotal) return [];
|
||||
const profileData = useMemo<BannerRow[]>(() => {
|
||||
if (dataMap === undefined) return [];
|
||||
|
||||
const typeLabel = filterValue.type.label;
|
||||
|
||||
switch (typeLabel) {
|
||||
case "보유":
|
||||
return apiOwnershipSummary;
|
||||
case "구매":
|
||||
return apiPurchaseRateKpis;
|
||||
case "향후 구매":
|
||||
return apiPurchaseRateKpis;
|
||||
default:
|
||||
return [];
|
||||
const targetMap = {
|
||||
[CategoryTargetType.PENETRATION]: "보유",
|
||||
[CategoryTargetType.PURCHASE]: "해당년도",
|
||||
[CategoryTargetType.INTENDED]: "향후구매",
|
||||
}
|
||||
}, [isTotal, filterValue]);
|
||||
|
||||
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} />
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
'use client'
|
||||
|
||||
import {useLayoutFilter} from "@/components/layout/LayoutFilterContext";
|
||||
import {useEffect, useMemo} from "react";
|
||||
import {PageData, ServerBannerRow} from "@/types/lg";
|
||||
import { apiOwnershipPathByYear, apiOwnershipTriggerByYear} from "@/config/sample.data";
|
||||
import {CategoryByData} from "@/components/lge-dashboard";
|
||||
import {BANNER_GROUP, BANNER_KEY_MAP, SITE_TITLE, YEARS} from "@/const/lgConst";
|
||||
import {CategoryTypeValue} from "@/components/layout/CategoryFilter";
|
||||
import {buildHeader_Banner, exportDashboardExcel, Section} from "@/lib/lg-export-excel";
|
||||
|
||||
const PurchaseBehavior = () => {
|
||||
const { filterValue, registerExcelExporter } = useLayoutFilter();
|
||||
console.log(filterValue);
|
||||
|
||||
const tableDataArray = useMemo<PageData<ServerBannerRow>[]>(() => [
|
||||
{title: "보유 경로", chartMode:"horizontal", data: apiOwnershipPathByYear},
|
||||
{title: "구입 계기", chartMode:"horizontal", data: apiOwnershipTriggerByYear},
|
||||
], []);
|
||||
|
||||
useEffect(() => {
|
||||
registerExcelExporter(async (payload) => {
|
||||
|
||||
const sheetName = `${filterValue.product}_${(filterValue.type as CategoryTypeValue).label}_구입 행태`
|
||||
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]);
|
||||
|
||||
return (
|
||||
<div>
|
||||
{tableDataArray.map((tableData) => (
|
||||
<CategoryByData
|
||||
key={`cbd-${tableData.title.replaceAll(/\s+/g, "_")}`}
|
||||
selectedYear={filterValue.year}
|
||||
title={tableData.title}
|
||||
chartMode={tableData.chartMode}
|
||||
allTableData={tableData.data}
|
||||
chartHeight={tableData.chartHeight}
|
||||
chartWidth={tableData.chartWidth}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default PurchaseBehavior;
|
||||
@@ -1,77 +0,0 @@
|
||||
'use client'
|
||||
|
||||
import {useLayoutFilter} from "@/components/layout/LayoutFilterContext";
|
||||
import {
|
||||
apiPurchaseChannelByYear,
|
||||
apiPurchaseChannelSummaryByYear
|
||||
} from "@/config/sample.data";
|
||||
import {useEffect, useMemo} from "react";
|
||||
import {PageData, ServerBannerRow} from "@/types/lg";
|
||||
import {CategoryByData} from "@/components/lge-dashboard";
|
||||
import {BANNER_GROUP, BANNER_KEY_MAP, SITE_TITLE, YEARS} from "@/const/lgConst";
|
||||
import {CategoryTypeValue} from "@/components/layout/CategoryFilter";
|
||||
import {buildHeader_Banner, exportDashboardExcel, Section} from "@/lib/lg-export-excel";
|
||||
|
||||
const PurchaseChannel = () => {
|
||||
const { filterValue, registerExcelExporter } = useLayoutFilter();
|
||||
console.log(filterValue);
|
||||
|
||||
const tableDataArray = useMemo<PageData<ServerBannerRow>[]>(() => [
|
||||
{
|
||||
title: "구매 채널(온/오프라인)",
|
||||
chartMode: "reverseStack",
|
||||
data: apiPurchaseChannelSummaryByYear,
|
||||
},
|
||||
{
|
||||
title: "구매 채널(상세)",
|
||||
chartMode: "horizontal",
|
||||
data: apiPurchaseChannelByYear,
|
||||
chartHeight: 550,
|
||||
},
|
||||
], []);
|
||||
|
||||
useEffect(() => {
|
||||
registerExcelExporter(async (payload) => {
|
||||
|
||||
const sheetName = `${filterValue.product}_${(filterValue.type as CategoryTypeValue).label}_구매 채널`
|
||||
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]);
|
||||
|
||||
return (
|
||||
<div>
|
||||
{tableDataArray.map((tableData) => (
|
||||
<CategoryByData
|
||||
key={`cbd-${tableData.title.replaceAll(/\s+/g, "_")}`}
|
||||
selectedYear={filterValue.year}
|
||||
title={tableData.title}
|
||||
chartMode={tableData.chartMode}
|
||||
allTableData={tableData.data}
|
||||
chartHeight={tableData.chartHeight}
|
||||
chartWidth={tableData.chartWidth}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default PurchaseChannel;
|
||||
@@ -1,68 +0,0 @@
|
||||
'use client'
|
||||
|
||||
import {useLayoutFilter} from "@/components/layout/LayoutFilterContext";
|
||||
import {useEffect, useMemo} from "react";
|
||||
import {PageData, ServerBannerRow} from "@/types/lg";
|
||||
import {apiFridgeDoorTypeByYear} from "@/config/sample.data";
|
||||
import {CategoryByData} from "@/components/lge-dashboard";
|
||||
import {BANNER_GROUP, BANNER_KEY_MAP, SITE_TITLE, YEARS} from "@/const/lgConst";
|
||||
import {CategoryTypeValue} from "@/components/layout/CategoryFilter";
|
||||
import {buildHeader_Banner, exportDashboardExcel, Section} from "@/lib/lg-export-excel";
|
||||
|
||||
const TypeSpec = () => {
|
||||
const { filterValue, registerExcelExporter } = useLayoutFilter();
|
||||
console.log(filterValue);
|
||||
|
||||
const tableDataArray = useMemo<PageData<ServerBannerRow>[]>(() => [
|
||||
{
|
||||
title: "타입",
|
||||
chartMode: "horizontal",
|
||||
data: apiFridgeDoorTypeByYear,
|
||||
},
|
||||
], []);
|
||||
|
||||
useEffect(() => {
|
||||
registerExcelExporter(async (payload) => {
|
||||
|
||||
const sheetName = `${filterValue.product}_${(filterValue.type as CategoryTypeValue).label}_타입/스펙`
|
||||
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]);
|
||||
|
||||
return (
|
||||
<div>
|
||||
{tableDataArray.map((tableData) => (
|
||||
<CategoryByData
|
||||
key={`cbd-${tableData.title.replaceAll(/\s+/g, "_")}`}
|
||||
selectedYear={filterValue.year}
|
||||
title={tableData.title}
|
||||
chartMode={tableData.chartMode}
|
||||
allTableData={tableData.data}
|
||||
chartHeight={tableData.chartHeight}
|
||||
chartWidth={tableData.chartWidth}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default TypeSpec;
|
||||
@@ -1,11 +1,33 @@
|
||||
'use client'
|
||||
|
||||
import { Provider as JotaiProvider } from "jotai";
|
||||
import {LoadingOverlay} from "@/components/common/LoadingOverlay";
|
||||
import ReactQueryLoadingSync from "@/components/common/ReactQueryLoadingSync";
|
||||
import {useState} from "react";
|
||||
import {QueryClient} from "@tanstack/query-core";
|
||||
import { QueryClientProvider } from "@tanstack/react-query";
|
||||
|
||||
export function AppProvider({ children }: { children: React.ReactNode }) {
|
||||
|
||||
const [queryClient] = useState(
|
||||
() =>
|
||||
new QueryClient({
|
||||
defaultOptions: {
|
||||
queries: {
|
||||
refetchOnWindowFocus: false,
|
||||
retry: 1,
|
||||
},
|
||||
},
|
||||
})
|
||||
);
|
||||
|
||||
return (
|
||||
<JotaiProvider>
|
||||
<LoadingOverlay />
|
||||
{children}
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<ReactQueryLoadingSync />
|
||||
<LoadingOverlay />
|
||||
{children}
|
||||
</QueryClientProvider>
|
||||
</JotaiProvider>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user