109 lines
3.7 KiB
TypeScript
109 lines
3.7 KiB
TypeScript
/** 셀/푸터 검증 오류 한 건 (입력 조회 verificationResult 항목) */
|
|
export type VerificationResultLikeItem = {
|
|
vrfcCd: string;
|
|
rsnExpln: string;
|
|
nowCn?: string;
|
|
cmprCn?: string;
|
|
nowVlCn?: string;
|
|
compVlCn?: string;
|
|
};
|
|
|
|
export type VerificationResultLikeMap = Record<
|
|
string,
|
|
VerificationResultLikeItem[]
|
|
>;
|
|
|
|
/** 입력 조회 verificationResult의 기준값/입력값이 null이면 "-" */
|
|
export function displayVerificationCn(
|
|
value: string | null | undefined,
|
|
): string {
|
|
if (value == null || String(value).trim() === "") return "-";
|
|
return String(value);
|
|
}
|
|
|
|
export function normalizeVerificationResultItem<T extends VerificationResultLikeItem>(
|
|
item: T,
|
|
): T {
|
|
return {
|
|
...item,
|
|
nowCn: displayVerificationCn(item.nowCn ?? item.nowVlCn),
|
|
cmprCn: displayVerificationCn(item.cmprCn ?? item.compVlCn),
|
|
};
|
|
}
|
|
|
|
export function normalizeVerificationResultMap<T extends VerificationResultLikeMap>(
|
|
result: T | null | undefined,
|
|
): T | undefined {
|
|
if (!result || typeof result !== "object") return undefined;
|
|
const next = {} as T;
|
|
for (const [key, items] of Object.entries(result)) {
|
|
(next as VerificationResultLikeMap)[key] = Array.isArray(items)
|
|
? items.map((item) => normalizeVerificationResultItem(item))
|
|
: [];
|
|
}
|
|
return next;
|
|
}
|
|
|
|
/** 조회 행/객체에 붙은 verificationResult의 cmprCn·nowCn null을 "-"로 바꿈 */
|
|
export function withNormalizedVerificationResult<T extends object>(item: T): T {
|
|
if (!("verificationResult" in item) || item.verificationResult == null) {
|
|
return item;
|
|
}
|
|
const verificationResult = normalizeVerificationResultMap(
|
|
item.verificationResult as VerificationResultLikeMap,
|
|
);
|
|
if (!verificationResult) return item;
|
|
return { ...item, verificationResult };
|
|
}
|
|
|
|
/** 검증 오류 배열 → RealGrid styleName */
|
|
export function getVerificationStyleName(
|
|
errors: VerificationResultLikeItem[] | null | undefined,
|
|
): string | undefined {
|
|
if (!Array.isArray(errors) || errors.length === 0) return undefined;
|
|
const hasImr = errors.some(
|
|
(e) => e.vrfcCd === "IMR" || e.vrfcCd === "HB",
|
|
);
|
|
return hasImr ? "rg-cell-verify-error-imr" : "rg-cell-verify-error";
|
|
}
|
|
|
|
/** 검증 오류 배열 → 툴팁/메시지 문구 */
|
|
export function formatVerificationTooltip(
|
|
errors: VerificationResultLikeItem[] | null | undefined,
|
|
): string | undefined {
|
|
if (!Array.isArray(errors) || errors.length === 0) return undefined;
|
|
const text = errors
|
|
.map((e) => {
|
|
const prefix =
|
|
e.vrfcCd === "IMR"
|
|
? "시계열 검증 - "
|
|
: e.vrfcCd === "NV"
|
|
? "일반검증 - "
|
|
: "모집단 검증 - ";
|
|
const comp = displayVerificationCn(e.cmprCn ?? e.compVlCn);
|
|
const now = displayVerificationCn(e.nowCn ?? e.nowVlCn);
|
|
return `${prefix}${e.rsnExpln}\n(검증 기준값: ${comp} / 현재 입력값: ${now})`;
|
|
})
|
|
.filter(Boolean)
|
|
.join("\n");
|
|
return text.length > 0 ? text : undefined;
|
|
}
|
|
|
|
/** fieldName 및 alias 중 첫 매칭 오류 배열 */
|
|
export function getVerificationErrorsForField(
|
|
result: VerificationResultLikeMap | null | undefined,
|
|
fieldName: string,
|
|
aliases?: readonly string[],
|
|
): VerificationResultLikeItem[] | undefined {
|
|
if (!result) return undefined;
|
|
const direct = result[fieldName];
|
|
if (Array.isArray(direct) && direct.length > 0) return direct;
|
|
if (aliases) {
|
|
for (const alias of aliases) {
|
|
const found = result[alias];
|
|
if (Array.isArray(found) && found.length > 0) return found;
|
|
}
|
|
}
|
|
return undefined;
|
|
}
|