[ST] - fix: 일반검증 항목 관리, 참조 지표(컬럼) 오류 로직 수정

This commit is contained in:
2026-08-27 13:07:33 +09:00
parent 64ed53cf4d
commit 9b53c1ae08
2 changed files with 65 additions and 18 deletions
@@ -632,6 +632,7 @@ const DetailComponent = ({ selectedVrfcRow }: DetailComponentProps) => {
kornArtopnEqtnCn: string;
engArtopnEqtnCn: string;
refStatsCd: string | null;
refStatsNm: string | null;
}) => {
setRuleBlocks((prev) => {
const i = prev.findIndex(
@@ -650,11 +651,12 @@ const DetailComponent = ({ selectedVrfcRow }: DetailComponentProps) => {
kornArtopnEqtnCn: payload.kornArtopnEqtnCn,
engArtopnEqtnCn: payload.engArtopnEqtnCn,
refStatsCd: payload.refStatsCd,
refStatsNm: payload.refStatsNm,
}
: {
vrfcDtlSn: null,
refStatsCd: payload.refStatsCd,
refStatsNm: null,
refStatsNm: payload.refStatsNm,
kornArtopnEqtnCn: payload.kornArtopnEqtnCn,
engArtopnEqtnCn: payload.engArtopnEqtnCn,
cmprOpert: null,
@@ -1,9 +1,12 @@
import { useEffect, useRef, useState } from "react";
import { useQuery } from "@tanstack/react-query";
import { useAlertStore } from "@/shared/lib";
import { CodeSelect } from "@/entities/code";
import { ENDPOINT } from "@/shared/config";
import { CodeApi } from "@/entities/code";
import { generalverificationApiService } from "@/entities/statistics/api/general-verification-service";
import type { SelectedVerifyColumnListResponseData,VerifyColumnListResponseData, VerifyDetailResponseDto } from "@/entities/statistics/model/general-verification-interface";
import type { SelectedVerifyColumnListResponseData, VerifyColumnListResponseData, VerifyDetailResponseDto } from "@/entities/statistics/model/general-verification-interface";
import {
Button,
Checkbox,
@@ -14,6 +17,11 @@ import {
DialogHeader,
DialogTitle,
Input,
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
Skeleton,
Textarea,
} from "@common/components";
@@ -21,8 +29,10 @@ import {
export interface FomulaDialogConfirmPayload {
kornArtopnEqtnCn: string;
engArtopnEqtnCn: string;
/** 참조 통계코드 (선택 안 했으면 null) */
/** 참조 통계코드 (수식에 참조 컬럼이 없으면 null) */
refStatsCd: string | null;
/** 참조 통계명 (수식에 참조 컬럼이 없으면 null) */
refStatsNm: string | null;
}
interface FomulaDialogProps {
@@ -63,6 +73,11 @@ const FomulaDialog = ({ open, onOpenChange, data, trgtStatsCd, trgtStatsNm, allo
const isUserDirectInputMode = allowLikeDirectInput && userDirectInput;
const { setMessage: alert } = useAlertStore((state) => state);
const { data: statsItemCodes } = useQuery({
queryKey: [ENDPOINT.CMS_SERVICE.CODE, "STITEM"],
queryFn: () => CodeApi.getCode("STITEM"),
enabled: open,
});
/** 다이얼로그에서 쓰는 기호 → 제출용 value. 백엔드 규격에 맞게 수정 가능 */
const OPERATOR_SYMBOL_TO_VALUE: Record<string, string> = {
@@ -375,6 +390,7 @@ const FomulaDialog = ({ open, onOpenChange, data, trgtStatsCd, trgtStatsNm, allo
const handleChangeRefStatsCd = (next: string) => {
if (!open) return;
if (trgtStatsCd && next === trgtStatsCd) return;
// 현재 refStatsCdLocal에 해당하는 참조 컬럼이 수식에 포함돼 있으면 변경을 막고 안내만 표시
const currentRefCols = refColList ?? [];
@@ -404,6 +420,26 @@ const FomulaDialog = ({ open, onOpenChange, data, trgtStatsCd, trgtStatsNm, allo
/** 참조 컬럼: 선택한 참조 통계로 조회한 목록이 있으면 사용, 없으면 getVerifyColumnList 결과 사용 */
const refColList = selectedColumnInfo?.targetColumnInfo?.colList ?? columnInfo?.refColumnInfo?.colList ?? [];
const formulaUsesRefColumn = (): boolean => {
const engSet = new Set(refColList.map((c) => c.engColNm).filter(Boolean));
if (engSet.size === 0) return false;
return formulaValueSegments.some((seg) => engSet.has(seg));
};
const resolveRefStatsForConfirm = (isEmptyFormula: boolean): {
refStatsCd: string | null;
refStatsNm: string | null;
} => {
if (isEmptyFormula || !formulaUsesRefColumn() || !refStatsCdLocal) {
return { refStatsCd: null, refStatsNm: null };
}
const refStatsNm =
statsItemCodes?.find((item) => item.lwpoCd === refStatsCdLocal)?.lwpoCdNm
?? data?.refStatsNm
?? null;
return { refStatsCd: refStatsCdLocal, refStatsNm };
};
const handleOpenChange = (nextOpen: boolean) => {
if (!nextOpen) {
setFormulaDisplaySegments([]);
@@ -528,11 +564,10 @@ const FomulaDialog = ({ open, onOpenChange, data, trgtStatsCd, trgtStatsNm, allo
)}
</div>
<Textarea
className={`w-full flex-1 resize-none !text-3xl p-4 !leading-loose font-bold ${
isUserDirectInputMode
className={`w-full flex-1 resize-none !text-3xl p-4 !leading-loose font-bold ${isUserDirectInputMode
? "bg-white text-gray-900"
: "bg-gray-100 text-gray-600"
}`}
}`}
id="formulaDisplayInput"
ref={formulaTextareaRef}
value={formulaDisplaySegments.join('')}
@@ -648,13 +683,25 @@ const FomulaDialog = ({ open, onOpenChange, data, trgtStatsCd, trgtStatsNm, allo
<div className="flex items-center justify-between">
<div className="flex gap-2 justify-center items-center">
<h3 className="font-bold text-title text-[14px]">참조 컬럼</h3>
<CodeSelect
upCd="STITEM"
<Select
value={refStatsCdLocal}
onValueChange={handleChangeRefStatsCd}
placeholder="선택"
className="w-[16rem]"
/>
>
<SelectTrigger className="w-[16rem]">
<SelectValue placeholder="선택" />
</SelectTrigger>
<SelectContent>
{statsItemCodes?.map((item) => (
<SelectItem
key={item.lwpoCd}
value={item.lwpoCd}
disabled={Boolean(trgtStatsCd) && item.lwpoCd === trgtStatsCd}
>
{item.lwpoCdNm}
</SelectItem>
))}
</SelectContent>
</Select>
</div>
{(refColList?.length ?? 0) > 0 ?
<Button
@@ -717,14 +764,11 @@ const FomulaDialog = ({ open, onOpenChange, data, trgtStatsCd, trgtStatsNm, allo
const raw = formulaDisplaySegments.join("");
const wrapped = wrapWithBacktick(raw);
const isEmptyFormula = raw.trim().length === 0;
const refStats = resolveRefStatsForConfirm(isEmptyFormula);
onConfirm?.({
kornArtopnEqtnCn: isEmptyFormula ? raw : wrapped,
engArtopnEqtnCn: isEmptyFormula ? raw : wrapped,
refStatsCd: isEmptyFormula
? null
: refStatsCdLocal
? refStatsCdLocal
: null,
...refStats,
});
onOpenChange?.(false);
return;
@@ -742,10 +786,11 @@ const FomulaDialog = ({ open, onOpenChange, data, trgtStatsCd, trgtStatsNm, allo
const kornArtopnEqtnCn = formulaDisplaySegments.join('');
const engArtopnEqtnCn = getFormulaValueForSubmit();
const isEmptyFormula = kornArtopnEqtnCn.trim().length === 0;
const refStats = resolveRefStatsForConfirm(isEmptyFormula);
onConfirm?.({
kornArtopnEqtnCn,
engArtopnEqtnCn,
refStatsCd: isEmptyFormula ? null : (refStatsCdLocal ? refStatsCdLocal : null),
...refStats,
});
onOpenChange?.(false);
}}