From 447bf937de54a181e8b0ce67d0a1ee40639c4b94 Mon Sep 17 00:00:00 2001 From: hjjeong Date: Tue, 20 Jan 2026 14:13:09 +0900 Subject: [PATCH] =?UTF-8?q?=EC=88=98=EC=A0=95=20=EB=B2=84=ED=8A=BC=20?= =?UTF-8?q?=ED=95=B8=EB=93=A4=EB=9F=AC=20Primary=20Key=20=EC=B0=BE?= =?UTF-8?q?=EA=B8=B0=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SplitPanelLayoutComponent.tsx | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/frontend/lib/registry/components/split-panel-layout/SplitPanelLayoutComponent.tsx b/frontend/lib/registry/components/split-panel-layout/SplitPanelLayoutComponent.tsx index 0113a9a8..33997fc7 100644 --- a/frontend/lib/registry/components/split-panel-layout/SplitPanelLayoutComponent.tsx +++ b/frontend/lib/registry/components/split-panel-layout/SplitPanelLayoutComponent.tsx @@ -1418,7 +1418,7 @@ export const SplitPanelLayoutComponent: React.FC // 수정 버튼 핸들러 const handleEditClick = useCallback( - (panel: "left" | "right", item: any) => { + async (panel: "left" | "right", item: any) => { // 🆕 우측 패널 수정 버튼 설정 확인 if (panel === "right" && componentConfig.rightPanel?.editButton?.mode === "modal") { const modalScreenId = componentConfig.rightPanel?.editButton?.modalScreenId; @@ -1427,18 +1427,40 @@ export const SplitPanelLayoutComponent: React.FC // 커스텀 모달 화면 열기 const rightTableName = componentConfig.rightPanel?.tableName || ""; - // Primary Key 찾기 (우선순위: id > ID > 첫 번째 필드) + // Primary Key 찾기: 테이블 메타데이터에서 실제 PK 컬럼 조회 let primaryKeyName = "id"; let primaryKeyValue: any; - if (item.id !== undefined && item.id !== null) { + // 1. 테이블 컬럼 메타데이터에서 실제 PK 찾기 + let pkColumn = rightTableColumns.find( + (col) => col.isPrimaryKey === true || col.is_primary_key === true || col.is_primary_key === "YES" + ); + + // 2. rightTableColumns가 비어있으면 API로 직접 조회 + if (!pkColumn && rightTableColumns.length === 0 && rightTableName) { + try { + const columnsResponse = await tableTypeApi.getColumns(rightTableName); + pkColumn = columnsResponse?.find( + (col: any) => col.isPrimaryKey === true || col.is_primary_key === true || col.is_primary_key === "YES" + ); + } catch (error) { + console.error("PK 컬럼 조회 실패:", error); + } + } + + if (pkColumn) { + const pkName = pkColumn.columnName || pkColumn.column_name; + primaryKeyName = pkName; + primaryKeyValue = item[pkName]; + } else if (item.id !== undefined && item.id !== null) { + // 3. 폴백: id 컬럼 primaryKeyName = "id"; primaryKeyValue = item.id; } else if (item.ID !== undefined && item.ID !== null) { primaryKeyName = "ID"; primaryKeyValue = item.ID; } else { - // 첫 번째 필드를 Primary Key로 간주 + // 4. 최후의 폴백: 첫 번째 필드 const firstKey = Object.keys(item)[0]; primaryKeyName = firstKey; primaryKeyValue = item[firstKey];