Merge branch 'feature/v2-renewal' of http://39.117.244.52:3000/kjs/ERP-node into jskim-node
This commit is contained in:
@@ -93,9 +93,12 @@ export const SelectedItemsDetailInputComponent: React.FC<SelectedItemsDetailInpu
|
||||
[config, component.config, component.id],
|
||||
);
|
||||
|
||||
// 소스 테이블의 키 필드명 (기본값: "item_id" → 하위 호환)
|
||||
// 예: item_info 기반이면 "item_id", customer_mng 기반이면 "customer_id"
|
||||
const sourceKeyField = componentConfig.sourceKeyField || "item_id";
|
||||
// 소스 테이블의 키 필드명
|
||||
// 우선순위: 1) config에서 명시적 설정 → 2) additionalFields에서 autoFillFrom:"id" 필드 감지 → 3) 하위 호환 "item_id"
|
||||
const sourceKeyField = useMemo(() => {
|
||||
// sourceKeyField는 config에서 직접 지정 (ConfigPanel 자동 감지에서 설정됨)
|
||||
return componentConfig.sourceKeyField || "item_id";
|
||||
}, [componentConfig.sourceKeyField]);
|
||||
|
||||
// 🆕 dataSourceId 우선순위: URL 파라미터 > 컴포넌트 설정 > component.id
|
||||
const dataSourceId = useMemo(
|
||||
@@ -472,10 +475,16 @@ export const SelectedItemsDetailInputComponent: React.FC<SelectedItemsDetailInpu
|
||||
|
||||
if (allGroupsEmpty) {
|
||||
// 디테일 데이터가 없어도 기본 레코드 생성 (품목-거래처 매핑 유지)
|
||||
// autoFillFrom 필드 (item_id 등)는 반드시 포함시켜야 나중에 식별 가능
|
||||
const baseRecord: Record<string, any> = {};
|
||||
|
||||
// sourceKeyField 자동 매핑 (item_id = originalData.id)
|
||||
if (sourceKeyField && item.originalData?.id) {
|
||||
baseRecord[sourceKeyField] = item.originalData.id;
|
||||
}
|
||||
|
||||
// 나머지 autoFillFrom 필드 (sourceKeyField 제외)
|
||||
additionalFields.forEach((f) => {
|
||||
if (f.autoFillFrom && item.originalData) {
|
||||
if (f.name !== sourceKeyField && f.autoFillFrom && item.originalData) {
|
||||
const value = item.originalData[f.autoFillFrom];
|
||||
if (value !== undefined && value !== null) {
|
||||
baseRecord[f.name] = value;
|
||||
@@ -530,7 +539,7 @@ export const SelectedItemsDetailInputComponent: React.FC<SelectedItemsDetailInpu
|
||||
|
||||
return allRecords;
|
||||
},
|
||||
[componentConfig.fieldGroups, componentConfig.additionalFields],
|
||||
[componentConfig.fieldGroups, componentConfig.additionalFields, sourceKeyField],
|
||||
);
|
||||
|
||||
// 🆕 저장 요청 시에만 데이터 전달 (이벤트 리스너 방식)
|
||||
@@ -677,27 +686,14 @@ export const SelectedItemsDetailInputComponent: React.FC<SelectedItemsDetailInpu
|
||||
|
||||
for (const item of items) {
|
||||
// sourceKeyField 값 추출 (예: item_id 또는 customer_id)
|
||||
// (수정 모드에서 autoFillFrom:"id"가 가격 레코드 PK를 반환하는 문제 방지)
|
||||
let sourceKeyValue: string | null = null;
|
||||
|
||||
// 1순위: originalData에 sourceKeyField가 직접 있으면 사용 (수정 모드에서 정확한 값)
|
||||
// 1순위: originalData에 sourceKeyField가 직접 있으면 사용 (수정 모드)
|
||||
if (item.originalData && item.originalData[sourceKeyField]) {
|
||||
sourceKeyValue = item.originalData[sourceKeyField];
|
||||
}
|
||||
|
||||
// 2순위: autoFillFrom 로직 (신규 등록 모드에서 사용)
|
||||
if (!sourceKeyValue) {
|
||||
mainGroups.forEach((group) => {
|
||||
const groupFields = additionalFields.filter((f) => f.groupId === group.id);
|
||||
groupFields.forEach((field) => {
|
||||
if (field.name === sourceKeyField && field.autoFillFrom && item.originalData) {
|
||||
sourceKeyValue = item.originalData[field.autoFillFrom] || null;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// 3순위: fallback (최후의 수단)
|
||||
// 2순위: 원본 데이터의 id를 sourceKeyField 값으로 사용 (신규 등록 모드)
|
||||
if (!sourceKeyValue && item.originalData) {
|
||||
sourceKeyValue = item.originalData.id || null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user