entity-search-iniput 수정
This commit is contained in:
@@ -11,6 +11,7 @@ import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover
|
||||
import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList } from "@/components/ui/command";
|
||||
import { dynamicFormApi } from "@/lib/api/dynamicForm";
|
||||
import { cascadingRelationApi } from "@/lib/api/cascadingRelation";
|
||||
import { AutoFillMapping } from "./config";
|
||||
|
||||
export function EntitySearchInputComponent({
|
||||
tableName,
|
||||
@@ -37,6 +38,8 @@ export function EntitySearchInputComponent({
|
||||
formData,
|
||||
// 다중선택 props
|
||||
multiple: multipleProp,
|
||||
// 자동 채움 매핑 props
|
||||
autoFillMappings: autoFillMappingsProp,
|
||||
// 추가 props
|
||||
component,
|
||||
isInteractive,
|
||||
@@ -47,6 +50,7 @@ export function EntitySearchInputComponent({
|
||||
isInteractive?: boolean;
|
||||
onFormDataChange?: (fieldName: string, value: any) => void;
|
||||
webTypeConfig?: any; // 웹타입 설정 (연쇄관계 등)
|
||||
autoFillMappings?: AutoFillMapping[]; // 자동 채움 매핑
|
||||
}) {
|
||||
// uiMode가 있으면 우선 사용, 없으면 modeProp 사용, 기본값 "combo"
|
||||
const mode = (uiMode || modeProp || "combo") as "select" | "modal" | "combo" | "autocomplete";
|
||||
@@ -54,6 +58,18 @@ export function EntitySearchInputComponent({
|
||||
// 다중선택 및 연쇄관계 설정 (props > webTypeConfig > componentConfig 순서)
|
||||
const config = component?.componentConfig || component?.webTypeConfig || {};
|
||||
const isMultiple = multipleProp ?? config.multiple ?? false;
|
||||
|
||||
// 자동 채움 매핑 설정 (props > config)
|
||||
const autoFillMappings: AutoFillMapping[] = autoFillMappingsProp ?? config.autoFillMappings ?? [];
|
||||
|
||||
// 디버그: 자동 채움 매핑 설정 확인
|
||||
console.log("🔧 [EntitySearchInput] 자동 채움 매핑 설정:", {
|
||||
autoFillMappingsProp,
|
||||
configAutoFillMappings: config.autoFillMappings,
|
||||
effectiveAutoFillMappings: autoFillMappings,
|
||||
isInteractive,
|
||||
hasOnFormDataChange: !!onFormDataChange,
|
||||
});
|
||||
|
||||
// 연쇄관계 설정 추출
|
||||
const effectiveCascadingRelationCode = cascadingRelationCode || config.cascadingRelationCode;
|
||||
@@ -309,6 +325,23 @@ export function EntitySearchInputComponent({
|
||||
console.log("📤 EntitySearchInput -> onFormDataChange:", component.columnName, newValue);
|
||||
}
|
||||
}
|
||||
|
||||
// 🆕 자동 채움 매핑 적용
|
||||
if (autoFillMappings.length > 0 && isInteractive && onFormDataChange && fullData) {
|
||||
console.log("🔄 자동 채움 매핑 적용:", { mappings: autoFillMappings, fullData });
|
||||
|
||||
for (const mapping of autoFillMappings) {
|
||||
if (mapping.sourceField && mapping.targetField) {
|
||||
const sourceValue = fullData[mapping.sourceField];
|
||||
if (sourceValue !== undefined) {
|
||||
onFormDataChange(mapping.targetField, sourceValue);
|
||||
console.log(` ✅ ${mapping.sourceField} → ${mapping.targetField}:`, sourceValue);
|
||||
} else {
|
||||
console.log(` ⚠️ ${mapping.sourceField} 값이 없음`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 다중선택 모드에서 개별 항목 제거
|
||||
@@ -436,7 +469,7 @@ export function EntitySearchInputComponent({
|
||||
const isSelected = selectedValues.includes(String(option[valueField]));
|
||||
return (
|
||||
<CommandItem
|
||||
key={option[valueField] || index}
|
||||
key={option[valueField] ?? `option-${index}`}
|
||||
value={`${option[displayField] || ""}-${option[valueField] || ""}`}
|
||||
onSelect={() => handleSelectOption(option)}
|
||||
className="text-xs sm:text-sm"
|
||||
@@ -509,7 +542,7 @@ export function EntitySearchInputComponent({
|
||||
<CommandGroup>
|
||||
{effectiveOptions.map((option, index) => (
|
||||
<CommandItem
|
||||
key={option[valueField] || index}
|
||||
key={option[valueField] ?? `select-option-${index}`}
|
||||
value={`${option[displayField] || ""}-${option[valueField] || ""}`}
|
||||
onSelect={() => handleSelectOption(option)}
|
||||
className="text-xs sm:text-sm"
|
||||
|
||||
Reference in New Issue
Block a user