From ba81aaa8a54d58d5c7233a99b88c9fc7062380d3 Mon Sep 17 00:00:00 2001 From: kric_jspark Date: Fri, 15 May 2026 14:39:15 +0900 Subject: [PATCH] =?UTF-8?q?260515=5F02=5FENH:=20=EA=B8=B0=EC=A1=B4=20?= =?UTF-8?q?=ED=94=84=EB=A1=9C=EC=A0=9D=ED=8A=B8=20=EC=A0=84=EC=9A=A9=20uti?= =?UTF-8?q?l=20file=EB=AA=85=20=EC=98=A4=ED=83=80=20=EC=88=98=EC=A0=95=20?= =?UTF-8?q?=EB=B0=8F=20=EC=B6=94=EA=B0=80=EB=A1=9C=20=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20util=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/table/BaseDataTable.tsx | 2 +- src/lib/kfpa-util.ts | 110 +++++++++++++++++++++++++ src/lib/kfpa-utill.ts | 3 - 3 files changed, 111 insertions(+), 4 deletions(-) create mode 100644 src/lib/kfpa-util.ts delete mode 100644 src/lib/kfpa-utill.ts diff --git a/src/components/table/BaseDataTable.tsx b/src/components/table/BaseDataTable.tsx index dce63ea..a1f34d5 100644 --- a/src/components/table/BaseDataTable.tsx +++ b/src/components/table/BaseDataTable.tsx @@ -13,7 +13,7 @@ import { toTableCellContent, } from "./core/table-core.helpers"; import {DataColumn} from "@/components/table/types"; -import {isGapRow} from "@/lib/kfpa-utill"; +import {isGapRow} from "@/lib/kfpa-util"; export type MergedTableCell = { key: keyof T; diff --git a/src/lib/kfpa-util.ts b/src/lib/kfpa-util.ts new file mode 100644 index 0000000..a2bdb01 --- /dev/null +++ b/src/lib/kfpa-util.ts @@ -0,0 +1,110 @@ +import { + CATEGORY_KEY_MAP, + DASHBOARD_COMMENT_COLUMNS, + DIV_KEY_MAP, + REGION_KEY_MAP, +} from "@/config/kfpaConfig"; +import type { + CommentColumn, + CommentValue, + CsiDataMap, + CsiMetricKey, + DivDetailData, + CsiSummaryMap, +} from "@/types/kfpa"; + +export const getWaveLabel = (wave: number) => { + const text = String(wave); + return `${wave >= 100 ? text.slice(-2) : text}년`; +}; + +export const getSummaryColumnLabel = (key: string) => { + if (key === "-1") return "지역본부 전체"; + return REGION_KEY_MAP[key] ?? CATEGORY_KEY_MAP[key] ?? DIV_KEY_MAP[key] ?? key; +}; + +export const getSummaryDataKey = (key: string) => + REGION_KEY_MAP[key] || key === "-1" ? `2601009_A_${key}` : `${key}_-1`; + +export const getCsiDataByWave = (dataMap: CsiDataMap | undefined, divKey: string, wave: number) => + dataMap?.[divKey]?.find((item) => item.wave === wave); + +export const getCsiMetricValue = ( + dataMap: CsiDataMap | undefined, + divKey: string, + wave: number, + metricKey: CsiMetricKey +) => getCsiDataByWave(dataMap, divKey, wave)?.[metricKey] ?? null; + +export const getCsiMetricGapValue = ( + dataMap: CsiDataMap | undefined, + divKey: string, + previousWave: number, + currentWave: number, + metricKey: CsiMetricKey +) => { + const previousValue = getCsiMetricValue(dataMap, divKey, previousWave, metricKey); + const currentValue = getCsiMetricValue(dataMap, divKey, currentWave, metricKey); + + if (previousValue == null || currentValue == null) return null; + return currentValue - previousValue; +}; + +export const getSummaryByWave = (dataMap: CsiSummaryMap | undefined, key: string, wave: number) => + dataMap?.[key]?.find((item) => item.wave === wave); + +export const getSummaryCsiValue = (dataMap: CsiSummaryMap | undefined, key: string, wave: number) => + getSummaryByWave(dataMap, key, wave)?.csi ?? null; + +export const getSummarySampleCount = (dataMap: CsiSummaryMap | undefined, key: string, wave: number) => + getSummaryByWave(dataMap, key, wave)?.sampleCount ?? null; + +export const getSummaryGapValue = ( + dataMap: CsiSummaryMap | undefined, + key: string, + previousWave: number, + currentWave: number +) => { + const previousValue = getSummaryCsiValue(dataMap, key, previousWave); + const currentValue = getSummaryCsiValue(dataMap, key, currentWave); + + if (previousValue == null || currentValue == null) return null; + return currentValue - previousValue; +}; + +export const getSelectedDetail = (data: Record | undefined, selectedDiv: string) => { + if (!data) return undefined; + return data[selectedDiv] ?? Object.values(data)[0]; +}; + +export const getCommentColumns = (commentValues?: Record): CommentColumn[] => { + const keys = Object.keys(commentValues ?? {}); + const selectedKeys = keys.length > 0 ? keys : DASHBOARD_COMMENT_COLUMNS.map((column) => column.key); + + return selectedKeys.map((key, index) => ({ + key, + label: DASHBOARD_COMMENT_COLUMNS[index]?.label ?? key, + })); +}; + +export const createEmptyCommentValue = (): CommentValue => ({ + directExperience: "", + indirectExperience: "", + capability: "", +}); + +export const createCommentDraft = ( + columns: Array<{ key: string }>, + source?: Record +) => + columns.reduce>((acc, column) => { + acc[column.key] = { + ...createEmptyCommentValue(), + ...(source?.[column.key] ?? {}), + }; + return acc; + }, {}); + +export const isGapRow = (raw: string) => raw.replace(/\s+/g, "").toUpperCase().includes("전년대비"); + +export const isSampleRow = (raw: string) => raw.replace(/\s+/g, "").includes("사례수"); \ No newline at end of file diff --git a/src/lib/kfpa-utill.ts b/src/lib/kfpa-utill.ts deleted file mode 100644 index e9e9350..0000000 --- a/src/lib/kfpa-utill.ts +++ /dev/null @@ -1,3 +0,0 @@ -export const isGapRow = (raw: string) => raw.replace(/\s+/g, "").toUpperCase().includes("전년대비"); - -export const isSampleRow = (raw: string) => raw.replace(/\s+/g, "").includes("사례수"); \ No newline at end of file