260515_02_ENH: 기존 프로젝트 전용 util file명 오타 수정 및 추가로 필요한 util 추가
This commit is contained in:
@@ -13,7 +13,7 @@ import {
|
|||||||
toTableCellContent,
|
toTableCellContent,
|
||||||
} from "./core/table-core.helpers";
|
} from "./core/table-core.helpers";
|
||||||
import {DataColumn} from "@/components/table/types";
|
import {DataColumn} from "@/components/table/types";
|
||||||
import {isGapRow} from "@/lib/kfpa-utill";
|
import {isGapRow} from "@/lib/kfpa-util";
|
||||||
|
|
||||||
export type MergedTableCell<T> = {
|
export type MergedTableCell<T> = {
|
||||||
key: keyof T;
|
key: keyof T;
|
||||||
|
|||||||
110
src/lib/kfpa-util.ts
Normal file
110
src/lib/kfpa-util.ts
Normal file
@@ -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<string, DivDetailData> | undefined, selectedDiv: string) => {
|
||||||
|
if (!data) return undefined;
|
||||||
|
return data[selectedDiv] ?? Object.values(data)[0];
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getCommentColumns = (commentValues?: Record<string, CommentValue>): 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<string, CommentValue>
|
||||||
|
) =>
|
||||||
|
columns.reduce<Record<string, CommentValue>>((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("사례수");
|
||||||
@@ -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("사례수");
|
|
||||||
Reference in New Issue
Block a user