[st] - 일정등록, 입력단 지난검증결과 알림 뱃지, 로그 상세조회, 검토단 cell style 적용

This commit is contained in:
2026-07-02 17:46:13 +09:00
parent 25417dcda1
commit cea2d39df8
66 changed files with 1615 additions and 206 deletions
@@ -61,6 +61,26 @@ export function buildReviewRowTypeCurrCellStyleCallbackByTab(
return map;
}
/** 여러 cellStyleCallback 결과를 styleName으로 병합 */
export function composeCellStyleCallbacks(
...callbacks: CellStyleCallback[]
): CellStyleCallback {
return (params) => {
const styleNames: string[] = [];
for (const cb of callbacks) {
const result = cb(params);
if (!result) continue;
if (typeof result === "string") {
styleNames.push(result);
} else if (result.styleName) {
styleNames.push(result.styleName);
}
}
const styleName = styleNames.join(" ").trim();
return styleName ? styleName : undefined;
};
}
/**
* 객체 배열을 그리드 row 형식으로 변환 (null/undefined → "").
* 어떤 엔티티 타입이든 공통 사용 가능.
@@ -0,0 +1,183 @@
import type { CellStyleCallback, ColumnConfig } from "@/components/type/DataGrid.type";
import {
buildReviewRowTypeCurrCellStyleExcludeMergeCells,
composeCellStyleCallbacks,
} from "@/components/util/grid/gridFunction";
const DISPLAY_YEAR_FIELD = "displayYear";
/** CURR 미입력 + OLD(전년) 데이터 있음 */
export const REVIEW_CURR_EMPTY_WARN_STYLE = "rg-cell-review-curr-empty-warn";
/** CURR 미입력 + OLD 행 없음 */
export const REVIEW_CURR_EMPTY_NEW_STYLE = "rg-cell-review-curr-empty-new";
function getColumnFieldNames(columns: readonly Pick<ColumnConfig, "fieldName">[]): string[] {
return columns.map((col) => col.fieldName).filter(Boolean);
}
function getFieldNamesBeforeDivision(columns: readonly Pick<ColumnConfig, "fieldName">[]): string[] {
const fields = getColumnFieldNames(columns);
const divisionIndex = fields.indexOf(DISPLAY_YEAR_FIELD);
if (divisionIndex <= 0) return [];
return fields.slice(0, divisionIndex);
}
function getFieldNamesAfterDivision(columns: readonly Pick<ColumnConfig, "fieldName">[]): string[] {
const fields = getColumnFieldNames(columns);
const divisionIndex = fields.indexOf(DISPLAY_YEAR_FIELD);
if (divisionIndex < 0 || divisionIndex >= fields.length - 1) return [];
return fields.slice(divisionIndex + 1);
}
function getDivisionHighlightFieldNames(
columns: readonly Pick<ColumnConfig, "fieldName" | "name">[],
): Set<string> {
const divisionColumn = columns.find((col) => col.fieldName === DISPLAY_YEAR_FIELD);
return new Set(
[DISPLAY_YEAR_FIELD, divisionColumn?.name, divisionColumn?.fieldName].filter(
Boolean,
) as string[],
);
}
function buildRowGroupKey(
row: Record<string, string | number>,
groupKeyFields: readonly string[],
): string {
return groupKeyFields.map((field) => String(row[field] ?? "")).join("\0");
}
export function isEmptyOrZeroGridValue(value: string | number | undefined): boolean {
if (value === null || value === undefined || value === "") return true;
if (typeof value === "number") return value === 0;
const trimmed = String(value).trim();
if (trimmed === "") return true;
const numeric = Number(trimmed.replace(/,/g, ""));
return !Number.isNaN(numeric) && numeric === 0;
}
export function isRowEmptyOrZeroAfterDivision(
row: Record<string, string | number>,
dataFieldNames: readonly string[],
): boolean {
if (dataFieldNames.length === 0) return false;
return dataFieldNames.every((field) => isEmptyOrZeroGridValue(row[field]));
}
type EmptyCurrHighlight =
| typeof REVIEW_CURR_EMPTY_WARN_STYLE
| typeof REVIEW_CURR_EMPTY_NEW_STYLE;
function buildOldRowByGroupKey(
rows: readonly Record<string, string | number>[],
groupKeyFields: readonly string[],
): Map<string, Record<string, string | number>> {
const map = new Map<string, Record<string, string | number>>();
for (const row of rows) {
if (String(row.rowType ?? "") !== "OLD") continue;
map.set(buildRowGroupKey(row, groupKeyFields), row);
}
return map;
}
function buildOldRowIndexByGroupKey(
rows: readonly Record<string, string | number>[],
groupKeyFields: readonly string[],
): Map<string, number> {
const map = new Map<string, number>();
rows.forEach((row, index) => {
if (String(row.rowType ?? "") !== "OLD") return;
map.set(buildRowGroupKey(row, groupKeyFields), index);
});
return map;
}
function resolveEmptyCurrHighlight(
currRow: Record<string, string | number>,
oldRowByGroupKey: ReadonlyMap<string, Record<string, string | number>>,
groupKeyFields: readonly string[],
dataFieldNames: readonly string[],
): EmptyCurrHighlight | undefined {
if (String(currRow.rowType ?? "") !== "CURR") return undefined;
if (!isRowEmptyOrZeroAfterDivision(currRow, dataFieldNames)) return undefined;
const groupKey = buildRowGroupKey(currRow, groupKeyFields);
const oldRow = oldRowByGroupKey.get(groupKey);
if (!oldRow) {
return REVIEW_CURR_EMPTY_NEW_STYLE;
}
if (isRowEmptyOrZeroAfterDivision(oldRow, dataFieldNames)) {
return undefined;
}
return REVIEW_CURR_EMPTY_WARN_STYLE;
}
/**
* 검토 그리드 — CURR 행의 구분 이후 값이 모두 비어있거나 0일 때
* 구분(displayYear): OLD 있음 → OLD·CURR 노란색, OLD 없음 → CURR 하늘색, 둘 다 없음 → 미적용
*/
export function buildReviewEmptyCurrCellStyleCallback(
columns: readonly Pick<ColumnConfig, "fieldName" | "name">[],
rows: readonly Record<string, string | number>[],
): CellStyleCallback {
const groupKeyFields = getFieldNamesBeforeDivision(columns);
const dataFieldNames = getFieldNamesAfterDivision(columns);
const highlightFieldNames = getDivisionHighlightFieldNames(columns);
const oldRowByGroupKey = buildOldRowByGroupKey(rows, groupKeyFields);
const oldRowIndexByGroupKey = buildOldRowIndexByGroupKey(rows, groupKeyFields);
const highlightByRowIndex = new Map<number, EmptyCurrHighlight>();
rows.forEach((row, index) => {
if (String(row.rowType ?? "") !== "CURR") return;
const highlight = resolveEmptyCurrHighlight(
row,
oldRowByGroupKey,
groupKeyFields,
dataFieldNames,
);
if (!highlight) return;
highlightByRowIndex.set(index, highlight);
if (highlight === REVIEW_CURR_EMPTY_WARN_STYLE) {
const oldIndex = oldRowIndexByGroupKey.get(buildRowGroupKey(row, groupKeyFields));
if (oldIndex !== undefined) {
highlightByRowIndex.set(oldIndex, highlight);
}
}
});
return ({ rowIndex, fieldName }) => {
if (highlightFieldNames.size === 0 || !highlightFieldNames.has(fieldName)) {
return undefined;
}
return highlightByRowIndex.get(rowIndex);
};
}
export function buildReviewCellStyleCallback(
columns: readonly Pick<ColumnConfig, "fieldName" | "name" | "mergeCells">[],
rows: readonly Record<string, string | number>[],
): CellStyleCallback {
const base = buildReviewRowTypeCurrCellStyleExcludeMergeCells(columns);
const emptyCurr = buildReviewEmptyCurrCellStyleCallback(columns, rows);
return composeCellStyleCallbacks(base, emptyCurr);
}
export function buildReviewCellStyleCallbackByTab(
tabs: readonly {
tabKey: string;
columns?: readonly Pick<ColumnConfig, "fieldName" | "name" | "mergeCells">[];
}[],
rowDataMap: ReadonlyMap<string, readonly Record<string, string | number>[]>,
): Map<string, CellStyleCallback> {
const map = new Map<string, CellStyleCallback>();
for (const tab of tabs) {
const columns = tab.columns ?? [];
const rows = rowDataMap.get(tab.tabKey) ?? [];
map.set(tab.tabKey, buildReviewCellStyleCallback(columns, rows));
}
return map;
}