Merge pull request '260401_04_ENH: Total Filter multi-select 가능하게 수정 및 DEBOUNCE_TIME 상수화' (#7) from develop into master
Reviewed-on: #7
This commit is contained in:
@@ -33,7 +33,7 @@ const PAGE_COMPONENTS: Partial<Record<CategoryTargetData, React.ComponentType<Ca
|
||||
|
||||
const CategoryPage = () => {
|
||||
const { isTotal, filterValue } = useLayoutFilter();
|
||||
const debouncedFilterValue = useDebouncedValue<CategoryFilterValue>(filterValue as CategoryFilterValue, 500);
|
||||
const debouncedFilterValue = useDebouncedValue<CategoryFilterValue>(filterValue as CategoryFilterValue);
|
||||
|
||||
const { fields, variableIdMap } = useMemo(() => {
|
||||
return buildPageModeConfig(debouncedFilterValue);
|
||||
|
||||
@@ -6,7 +6,7 @@ import {useEffect, useMemo} from "react";
|
||||
import {BannerRow, PageData} from "@/types/lg.types";
|
||||
import {buildHeader_Banner, exportDashboardExcel, Section} from "@/lib/lg-export-excel";
|
||||
import {BANNER_GROUP} from "@/const/lg-banner.const";
|
||||
import {BANNER_KEY_MAP} from "@/const/lg-schema.const";
|
||||
import {BANNER_KEY_MAP, PRODUCT_KEY_MAP} from "@/const/lg-schema.const";
|
||||
import {QID_SURVEY_TITLE} from "@/const/lg-survey.const";
|
||||
import {SITE_TITLE, YEARS} from "@/const/lg-common.const";
|
||||
import {CategoryByData} from "@/components/lge-dashboard";
|
||||
@@ -18,7 +18,7 @@ const CategoryDetail = ({
|
||||
fillGreaterThan5
|
||||
}:CategoryPageProps) => {
|
||||
const {filterValue, registerExcelExporter} = useLayoutFilter();
|
||||
const debouncedFilterValue = useDebouncedValue<CategoryFilterValue>(filterValue as CategoryFilterValue, 500);
|
||||
const debouncedFilterValue = useDebouncedValue<CategoryFilterValue>(filterValue as CategoryFilterValue);
|
||||
|
||||
const tableDataArray = useMemo<PageData<BannerRow>[]>(() => {
|
||||
const tempTableDataArray = fields.map((f) :PageData<BannerRow> => {
|
||||
@@ -46,7 +46,7 @@ const CategoryDetail = ({
|
||||
|
||||
useEffect(() => {
|
||||
registerExcelExporter(async () => {
|
||||
const product = debouncedFilterValue.product;
|
||||
const product = PRODUCT_KEY_MAP[debouncedFilterValue.product];
|
||||
const type = debouncedFilterValue.type.label;
|
||||
const target = debouncedFilterValue.target.label.replaceAll('/', '_');
|
||||
|
||||
@@ -79,7 +79,7 @@ const CategoryDetail = ({
|
||||
{tableDataArray.map((tableData) => (
|
||||
<CategoryByData
|
||||
key={`cbd-${tableData.title.replaceAll(/\s+/g, "_")}`}
|
||||
selectedYear={filterValue.year}
|
||||
selectedYear={debouncedFilterValue.year}
|
||||
title={tableData.title}
|
||||
surveyTitle={tableData.surveyTitle}
|
||||
chartMode={tableData.chartMode}
|
||||
|
||||
@@ -15,7 +15,7 @@ const Profile = ({
|
||||
dataMap
|
||||
}:CategoryPageProps) => {
|
||||
const { filterValue } = useLayoutFilter();
|
||||
const debouncedFilterValue = useDebouncedValue<CategoryFilterValue>(filterValue as CategoryFilterValue, 500);
|
||||
const debouncedFilterValue = useDebouncedValue<CategoryFilterValue>(filterValue as CategoryFilterValue);
|
||||
|
||||
const profileData = useMemo<BannerRow[]>(() => {
|
||||
if (dataMap === undefined) return [];
|
||||
|
||||
@@ -44,7 +44,7 @@ import {useBannerStatisticsQuery, useProductStatisticsQuery} from "@/query/stati
|
||||
|
||||
const LGPenetrationPage = () => {
|
||||
const {filterValue, registerExcelExporter} = useLayoutFilter();
|
||||
const debouncedFilterValue = useDebouncedValue<SelectedMap>(filterValue as SelectedMap, 500);
|
||||
const debouncedFilterValue = useDebouncedValue<SelectedMap>(filterValue as SelectedMap);
|
||||
|
||||
const req = useMemo<StatisticsRequest>(() => {
|
||||
return {
|
||||
|
||||
@@ -36,7 +36,7 @@ import {toNumOr0} from "@/lib/utils";
|
||||
|
||||
const LGPurchasePage = () => {
|
||||
const { filterValue, registerExcelExporter } = useLayoutFilter();
|
||||
const debouncedFilterValue = useDebouncedValue<SelectedMap>(filterValue as SelectedMap, 500);
|
||||
const debouncedFilterValue = useDebouncedValue<SelectedMap>(filterValue as SelectedMap);
|
||||
|
||||
const req = useMemo<StatisticsRequest>(() => {
|
||||
return {
|
||||
|
||||
@@ -36,7 +36,7 @@ import {SelectedMap} from "@/types/common";
|
||||
|
||||
const PenetrationPage = () => {
|
||||
const { filterValue, registerExcelExporter } = useLayoutFilter();
|
||||
const debouncedFilterValue = useDebouncedValue<SelectedMap>(filterValue as SelectedMap, 500);
|
||||
const debouncedFilterValue = useDebouncedValue<SelectedMap>(filterValue as SelectedMap);
|
||||
const [isBrandShare, setIsBrandShare] = useState(false);
|
||||
|
||||
const req = useMemo<StatisticsRequest>(() => {
|
||||
|
||||
@@ -36,7 +36,7 @@ import {useProductStatisticsQuery} from "@/query/statistics";
|
||||
|
||||
const PurchasePage = () => {
|
||||
const { filterValue, registerExcelExporter } = useLayoutFilter();
|
||||
const debouncedFilterValue = useDebouncedValue<SelectedMap>(filterValue as SelectedMap, 500);
|
||||
const debouncedFilterValue = useDebouncedValue<SelectedMap>(filterValue as SelectedMap);
|
||||
|
||||
const req = useMemo<StatisticsRequest>(() => {
|
||||
return {
|
||||
|
||||
@@ -28,7 +28,9 @@ const buildDefaultTotalValue = (): SelectedMap => {
|
||||
totalFilters.forEach((f) => {
|
||||
// "전체"가 있으면 그 value, 없으면 첫 번째 값
|
||||
const all = f.children.find((c) => c.label === "전체");
|
||||
init[f.variable] = all?.value ?? f.children[0]?.value ?? "";
|
||||
const initValue = all?.value ?? f.children[0]?.value ?? "";
|
||||
|
||||
init[f.variable] = [initValue];
|
||||
});
|
||||
return init;
|
||||
};
|
||||
@@ -108,14 +110,14 @@ const MainLayout = ({ children }: MainLayoutProps) => {
|
||||
const isDefaultTotalFilter = useMemo(() => {
|
||||
if(!isTotal) return false;
|
||||
|
||||
return Object.values(totalValue).every(value => value === "0");
|
||||
return Object.values(totalValue).every(value => value.length === 1 && value[0] === "0");
|
||||
},[isTotal, totalValue])
|
||||
|
||||
const setDefaletTotalFilter = () => {
|
||||
const setDefaultTotalFilter = () => {
|
||||
if(isTotal && !isDefaultTotalFilter){
|
||||
setTotalValue(prev =>
|
||||
Object.fromEntries(
|
||||
Object.keys(prev).map(key => [key, "0"])
|
||||
Object.keys(prev).map(key => [key, ["0"]])
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -181,7 +183,7 @@ const MainLayout = ({ children }: MainLayoutProps) => {
|
||||
<>
|
||||
<Button
|
||||
variant={isDefaultTotalFilter ? "secondary" : "default"}
|
||||
onClick={setDefaletTotalFilter}
|
||||
onClick={setDefaultTotalFilter}
|
||||
className="h-6 rounded-sm px-3 ml-3 text-sm font-semibold content-text-sm"
|
||||
>
|
||||
초기화
|
||||
|
||||
@@ -20,9 +20,32 @@ const TotalFilter = ({
|
||||
className
|
||||
}: TotalFilterProps) => {
|
||||
|
||||
const handlePick = (variable: string, v: string) => {
|
||||
if (value[variable] === v) return;
|
||||
onChange({ ...value, [variable]: v });
|
||||
const getSelectableCount = (variable: string) =>
|
||||
filters.find((filter) => filter.variable === variable)?.children
|
||||
.filter((child) => child.value !== "0").length ?? 0;
|
||||
|
||||
const handlePick = (variable: string, selectedValue: string) => {
|
||||
if (selectedValue === "0") {
|
||||
onChange({ ...value, [variable]: ["0"] });
|
||||
return;
|
||||
}
|
||||
|
||||
const currentValues = value[variable] ?? ["0"];
|
||||
const normalizedValues = currentValues.filter((item) => item !== "0");
|
||||
const selectableCount = getSelectableCount(variable);
|
||||
|
||||
const isAlreadySelected = normalizedValues.includes(selectedValue);
|
||||
|
||||
const nextValues = isAlreadySelected
|
||||
? normalizedValues.filter((item) => item !== selectedValue)
|
||||
: [...normalizedValues, selectedValue].sort((a, b) => Number(a) - Number(b));
|
||||
|
||||
if (nextValues.length === 0 || nextValues.length === selectableCount) {
|
||||
onChange({ ...value, [variable]: ["0"] });
|
||||
return;
|
||||
}
|
||||
|
||||
onChange({ ...value, [variable]: nextValues });
|
||||
};
|
||||
|
||||
const arranged = useMemo(() => {
|
||||
@@ -74,7 +97,7 @@ const TotalFilter = ({
|
||||
{/* 우측 옵션 */}
|
||||
<div className="flex min-w-0 flex-1 flex-wrap items-center gap-1 px-2 py-2">
|
||||
{row.children.map((c) => {
|
||||
const active = current === c.value;
|
||||
const active = current.includes(c.value);
|
||||
|
||||
return (
|
||||
<Button
|
||||
|
||||
@@ -80,7 +80,7 @@ type BannerSummaryProps = {
|
||||
|
||||
const BannerSummary = ({ data, useChart, useYear, getCellClassName }: BannerSummaryProps) => {
|
||||
const { filterValue, registerExcelExporter } = useLayoutFilter();
|
||||
const debouncedFilterValue = useDebouncedValue<CategoryFilterValue>(filterValue as CategoryFilterValue, 500);
|
||||
const debouncedFilterValue = useDebouncedValue<CategoryFilterValue>(filterValue as CategoryFilterValue);
|
||||
|
||||
const buildChartData = (rows: BannerRow[]): ChartData => {
|
||||
const categories = rows
|
||||
@@ -113,10 +113,10 @@ const BannerSummary = ({ data, useChart, useYear, getCellClassName }: BannerSumm
|
||||
return SECTIONS.map((spec) => {
|
||||
const specTitle = spec.title;
|
||||
const bannerKeys = getSectionBannerKeys(spec);
|
||||
const columns = buildColumns(spec, useYear ? filterValue.year : "");
|
||||
const columns = buildColumns(spec, useYear ? debouncedFilterValue.year : "");
|
||||
|
||||
// rows가 spec마다 다르면 여기서 가져오도록 구성
|
||||
const rows = wrapSampleRow(useYear ? data.filter((d) => d.year === filterValue.year) : data).map((row) => {
|
||||
const rows = wrapSampleRow(useYear ? data.filter((d) => d.year === debouncedFilterValue.year) : data).map((row) => {
|
||||
row.rowLabel = formatRowLabel(row.rowLabel);
|
||||
return row;
|
||||
});
|
||||
@@ -131,7 +131,7 @@ const BannerSummary = ({ data, useChart, useYear, getCellClassName }: BannerSumm
|
||||
chartData,
|
||||
};
|
||||
});
|
||||
}, [data, useYear, filterValue.year]);
|
||||
}, [data, useYear, debouncedFilterValue.year]);
|
||||
|
||||
useEffect(() => {
|
||||
registerExcelExporter(async () => {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
export const DEBOUNCE_TIME = 500;
|
||||
export const USE_CACHE = true;
|
||||
export const API_DECIMAL_POINT = 0;
|
||||
export const VIEW_DECIMAL_POINT = 0;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import {DEBOUNCE_TIME} from "@/const/lg-common.const";
|
||||
|
||||
export function useDebouncedValue<T>(value: T, delayMs = 1200) {
|
||||
export function useDebouncedValue<T>(value: T, delayMs = DEBOUNCE_TIME) {
|
||||
const [debounced, setDebounced] = useState(value);
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
@@ -25,4 +25,4 @@ export type PageResponse<T> = {
|
||||
empty: boolean;
|
||||
}
|
||||
|
||||
export type SelectedMap = Record<string, string>;
|
||||
export type SelectedMap = Record<string, string[]>;
|
||||
Reference in New Issue
Block a user