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