범용 폼 모달 사전필터 기능 수정
This commit is contained in:
+353
-333
@@ -9,17 +9,7 @@ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@
|
||||
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from "@/components/ui/accordion";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Separator } from "@/components/ui/separator";
|
||||
import {
|
||||
Plus,
|
||||
Trash2,
|
||||
GripVertical,
|
||||
ChevronUp,
|
||||
ChevronDown,
|
||||
Settings,
|
||||
Database,
|
||||
Layout,
|
||||
Table,
|
||||
} from "lucide-react";
|
||||
import { Plus, Trash2, GripVertical, ChevronUp, ChevronDown, Settings, Database, Layout, Table } from "lucide-react";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { apiClient } from "@/lib/api/client";
|
||||
import { getNumberingRules } from "@/lib/api/numberingRule";
|
||||
@@ -31,11 +21,7 @@ import {
|
||||
MODAL_SIZE_OPTIONS,
|
||||
SECTION_TYPE_OPTIONS,
|
||||
} from "./types";
|
||||
import {
|
||||
defaultSectionConfig,
|
||||
defaultTableSectionConfig,
|
||||
generateSectionId,
|
||||
} from "./config";
|
||||
import { defaultSectionConfig, defaultTableSectionConfig, generateSectionId } from "./config";
|
||||
|
||||
// 모달 import
|
||||
import { FieldDetailSettingsModal } from "./modals/FieldDetailSettingsModal";
|
||||
@@ -45,22 +31,26 @@ import { TableSectionSettingsModal } from "./modals/TableSectionSettingsModal";
|
||||
|
||||
// 도움말 텍스트 컴포넌트
|
||||
const HelpText = ({ children }: { children: React.ReactNode }) => (
|
||||
<p className="text-[10px] text-muted-foreground mt-0.5">{children}</p>
|
||||
<p className="text-muted-foreground mt-0.5 text-[10px]">{children}</p>
|
||||
);
|
||||
|
||||
// 부모 화면에서 전달 가능한 필드 타입
|
||||
interface AvailableParentField {
|
||||
name: string; // 필드명 (columnName)
|
||||
label: string; // 표시 라벨
|
||||
name: string; // 필드명 (columnName)
|
||||
label: string; // 표시 라벨
|
||||
sourceComponent?: string; // 출처 컴포넌트 (예: "TableList", "SplitPanelLayout2")
|
||||
sourceTable?: string; // 출처 테이블명
|
||||
sourceTable?: string; // 출처 테이블명
|
||||
}
|
||||
|
||||
export function UniversalFormModalConfigPanel({ config, onChange, allComponents = [] }: UniversalFormModalConfigPanelProps) {
|
||||
export function UniversalFormModalConfigPanel({
|
||||
config,
|
||||
onChange,
|
||||
allComponents = [],
|
||||
}: UniversalFormModalConfigPanelProps) {
|
||||
// 테이블 목록
|
||||
const [tables, setTables] = useState<{ name: string; label: string }[]>([]);
|
||||
const [tableColumns, setTableColumns] = useState<{
|
||||
[tableName: string]: { name: string; type: string; label: string }[];
|
||||
[tableName: string]: { name: string; type: string; label: string; inputType?: string }[];
|
||||
}>({});
|
||||
|
||||
// 부모 화면에서 전달 가능한 필드 목록
|
||||
@@ -140,7 +130,7 @@ export function UniversalFormModalConfigPanel({ config, onChange, allComponents
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// 좌측 패널 테이블 컬럼도 추출
|
||||
const leftTableName = compConfig.leftPanel?.tableName;
|
||||
if (leftTableName) {
|
||||
@@ -152,7 +142,7 @@ export function UniversalFormModalConfigPanel({ config, onChange, allComponents
|
||||
const colName = col.columnName || col.column_name;
|
||||
const colLabel = col.displayName || col.columnComment || col.column_comment || colName;
|
||||
// 중복 방지
|
||||
if (!fields.some(f => f.name === colName && f.sourceTable === leftTableName)) {
|
||||
if (!fields.some((f) => f.name === colName && f.sourceTable === leftTableName)) {
|
||||
fields.push({
|
||||
name: colName,
|
||||
label: colLabel,
|
||||
@@ -179,7 +169,7 @@ export function UniversalFormModalConfigPanel({ config, onChange, allComponents
|
||||
columns.forEach((col: any) => {
|
||||
const colName = col.columnName || col.column_name;
|
||||
const colLabel = col.displayName || col.columnComment || col.column_comment || colName;
|
||||
if (!fields.some(f => f.name === colName && f.sourceTable === tableName)) {
|
||||
if (!fields.some((f) => f.name === colName && f.sourceTable === tableName)) {
|
||||
fields.push({
|
||||
name: colName,
|
||||
label: colLabel,
|
||||
@@ -198,11 +188,11 @@ export function UniversalFormModalConfigPanel({ config, onChange, allComponents
|
||||
// 4. 버튼 컴포넌트 - openModalWithData의 fieldMappings/dataMapping에서 소스 컬럼 추출
|
||||
if (compType === "button-primary" || compType === "button" || compType === "button-secondary") {
|
||||
const action = compConfig.action || {};
|
||||
|
||||
|
||||
// fieldMappings에서 소스 컬럼 추출
|
||||
const fieldMappings = action.fieldMappings || [];
|
||||
fieldMappings.forEach((mapping: any) => {
|
||||
if (mapping.sourceColumn && !fields.some(f => f.name === mapping.sourceColumn)) {
|
||||
if (mapping.sourceColumn && !fields.some((f) => f.name === mapping.sourceColumn)) {
|
||||
fields.push({
|
||||
name: mapping.sourceColumn,
|
||||
label: mapping.sourceColumn,
|
||||
@@ -211,11 +201,11 @@ export function UniversalFormModalConfigPanel({ config, onChange, allComponents
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// dataMapping에서 소스 컬럼 추출
|
||||
const dataMapping = action.dataMapping || [];
|
||||
dataMapping.forEach((mapping: any) => {
|
||||
if (mapping.sourceColumn && !fields.some(f => f.name === mapping.sourceColumn)) {
|
||||
if (mapping.sourceColumn && !fields.some((f) => f.name === mapping.sourceColumn)) {
|
||||
fields.push({
|
||||
name: mapping.sourceColumn,
|
||||
label: mapping.sourceColumn,
|
||||
@@ -237,7 +227,7 @@ export function UniversalFormModalConfigPanel({ config, onChange, allComponents
|
||||
columns.forEach((col: any) => {
|
||||
const colName = col.columnName || col.column_name;
|
||||
const colLabel = col.displayName || col.columnComment || col.column_comment || colName;
|
||||
if (!fields.some(f => f.name === colName)) {
|
||||
if (!fields.some((f) => f.name === colName)) {
|
||||
fields.push({
|
||||
name: colName,
|
||||
label: colLabel,
|
||||
@@ -253,8 +243,8 @@ export function UniversalFormModalConfigPanel({ config, onChange, allComponents
|
||||
}
|
||||
|
||||
// 중복 제거 (같은 name이면 첫 번째만 유지)
|
||||
const uniqueFields = fields.filter((field, index, self) =>
|
||||
index === self.findIndex(f => f.name === field.name)
|
||||
const uniqueFields = fields.filter(
|
||||
(field, index, self) => index === self.findIndex((f) => f.name === field.name),
|
||||
);
|
||||
|
||||
setAvailableParentFields(uniqueFields);
|
||||
@@ -276,11 +266,19 @@ export function UniversalFormModalConfigPanel({ config, onChange, allComponents
|
||||
const data = response.data?.data;
|
||||
if (response.data?.success && Array.isArray(data)) {
|
||||
setTables(
|
||||
data.map((t: { tableName?: string; table_name?: string; displayName?: string; tableLabel?: string; table_label?: string }) => ({
|
||||
name: t.tableName || t.table_name || "",
|
||||
// displayName 우선, 없으면 tableLabel, 그것도 없으면 테이블명
|
||||
label: t.displayName || t.tableLabel || t.table_label || "",
|
||||
})),
|
||||
data.map(
|
||||
(t: {
|
||||
tableName?: string;
|
||||
table_name?: string;
|
||||
displayName?: string;
|
||||
tableLabel?: string;
|
||||
table_label?: string;
|
||||
}) => ({
|
||||
name: t.tableName || t.table_name || "",
|
||||
// displayName 우선, 없으면 tableLabel, 그것도 없으면 테이블명
|
||||
label: t.displayName || t.tableLabel || t.table_label || "",
|
||||
}),
|
||||
),
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
@@ -308,10 +306,13 @@ export function UniversalFormModalConfigPanel({ config, onChange, allComponents
|
||||
displayName?: string;
|
||||
columnComment?: string;
|
||||
column_comment?: string;
|
||||
inputType?: string;
|
||||
input_type?: string;
|
||||
}) => ({
|
||||
name: c.columnName || c.column_name || "",
|
||||
type: c.dataType || c.data_type || "text",
|
||||
label: c.displayName || c.columnComment || c.column_comment || c.columnName || c.column_name || "",
|
||||
inputType: c.inputType || c.input_type || "text",
|
||||
}),
|
||||
),
|
||||
}));
|
||||
@@ -359,21 +360,24 @@ export function UniversalFormModalConfigPanel({ config, onChange, allComponents
|
||||
);
|
||||
|
||||
// 섹션 관리
|
||||
const addSection = useCallback((type: "fields" | "table" = "fields") => {
|
||||
const newSection: FormSectionConfig = {
|
||||
...defaultSectionConfig,
|
||||
id: generateSectionId(),
|
||||
title: type === "table" ? `테이블 섹션 ${config.sections.length + 1}` : `섹션 ${config.sections.length + 1}`,
|
||||
type,
|
||||
fields: type === "fields" ? [] : undefined,
|
||||
tableConfig: type === "table" ? { ...defaultTableSectionConfig } : undefined,
|
||||
};
|
||||
onChange({
|
||||
...config,
|
||||
sections: [...config.sections, newSection],
|
||||
});
|
||||
}, [config, onChange]);
|
||||
|
||||
const addSection = useCallback(
|
||||
(type: "fields" | "table" = "fields") => {
|
||||
const newSection: FormSectionConfig = {
|
||||
...defaultSectionConfig,
|
||||
id: generateSectionId(),
|
||||
title: type === "table" ? `테이블 섹션 ${config.sections.length + 1}` : `섹션 ${config.sections.length + 1}`,
|
||||
type,
|
||||
fields: type === "fields" ? [] : undefined,
|
||||
tableConfig: type === "table" ? { ...defaultTableSectionConfig } : undefined,
|
||||
};
|
||||
onChange({
|
||||
...config,
|
||||
sections: [...config.sections, newSection],
|
||||
});
|
||||
},
|
||||
[config, onChange],
|
||||
);
|
||||
|
||||
// 섹션 타입 변경
|
||||
const changeSectionType = useCallback(
|
||||
(sectionId: string, newType: "fields" | "table") => {
|
||||
@@ -381,7 +385,7 @@ export function UniversalFormModalConfigPanel({ config, onChange, allComponents
|
||||
...config,
|
||||
sections: config.sections.map((s) => {
|
||||
if (s.id !== sectionId) return s;
|
||||
|
||||
|
||||
if (newType === "table") {
|
||||
return {
|
||||
...s,
|
||||
@@ -400,9 +404,9 @@ export function UniversalFormModalConfigPanel({ config, onChange, allComponents
|
||||
}),
|
||||
});
|
||||
},
|
||||
[config, onChange]
|
||||
[config, onChange],
|
||||
);
|
||||
|
||||
|
||||
// 테이블 섹션 설정 모달 열기
|
||||
const handleOpenTableSectionSettings = (section: FormSectionConfig) => {
|
||||
setSelectedSection(section);
|
||||
@@ -487,293 +491,310 @@ export function UniversalFormModalConfigPanel({ config, onChange, allComponents
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="h-full flex flex-col overflow-hidden w-full min-w-0">
|
||||
<div className="flex-1 overflow-y-auto overflow-x-hidden w-full min-w-0">
|
||||
<div className="space-y-4 p-4 w-full min-w-0 max-w-full">
|
||||
{/* 모달 기본 설정 */}
|
||||
<Accordion type="single" collapsible defaultValue="modal-settings" className="w-full min-w-0">
|
||||
<AccordionItem value="modal-settings" className="border rounded-lg w-full min-w-0">
|
||||
<AccordionTrigger className="px-4 py-3 text-sm font-medium hover:no-underline w-full min-w-0">
|
||||
<div className="flex items-center gap-2 w-full min-w-0">
|
||||
<Settings className="h-4 w-4 shrink-0" />
|
||||
<span className="truncate">모달 기본 설정</span>
|
||||
</div>
|
||||
</AccordionTrigger>
|
||||
<AccordionContent className="px-4 pb-4 space-y-4 w-full min-w-0">
|
||||
<div className="w-full min-w-0">
|
||||
<Label className="text-xs font-medium mb-1.5 block">모달 제목</Label>
|
||||
<Input
|
||||
value={config.modal.title}
|
||||
onChange={(e) => updateModalConfig({ title: e.target.value })}
|
||||
className="h-9 text-sm w-full max-w-full"
|
||||
/>
|
||||
<HelpText>모달 상단에 표시될 제목입니다</HelpText>
|
||||
</div>
|
||||
|
||||
<div className="w-full min-w-0">
|
||||
<Label className="text-xs font-medium mb-1.5 block">모달 크기</Label>
|
||||
<Select value={config.modal.size} onValueChange={(value: any) => updateModalConfig({ size: value })}>
|
||||
<SelectTrigger className="h-9 text-sm w-full max-w-full">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{MODAL_SIZE_OPTIONS.map((opt) => (
|
||||
<SelectItem key={opt.value} value={opt.value}>
|
||||
{opt.label}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<HelpText>모달 창의 크기를 선택하세요</HelpText>
|
||||
</div>
|
||||
|
||||
{/* 저장 버튼 표시 설정 */}
|
||||
<div className="w-full min-w-0">
|
||||
<div className="flex items-center gap-2">
|
||||
<Checkbox
|
||||
id="show-save-button"
|
||||
checked={config.modal.showSaveButton !== false}
|
||||
onCheckedChange={(checked) => updateModalConfig({ showSaveButton: checked === true })}
|
||||
/>
|
||||
<Label htmlFor="show-save-button" className="text-xs font-medium cursor-pointer">
|
||||
저장 버튼 표시
|
||||
</Label>
|
||||
<div className="flex h-full w-full min-w-0 flex-col overflow-hidden">
|
||||
<div className="w-full min-w-0 flex-1 overflow-x-hidden overflow-y-auto">
|
||||
<div className="w-full max-w-full min-w-0 space-y-4 p-4">
|
||||
{/* 모달 기본 설정 */}
|
||||
<Accordion type="single" collapsible defaultValue="modal-settings" className="w-full min-w-0">
|
||||
<AccordionItem value="modal-settings" className="w-full min-w-0 rounded-lg border">
|
||||
<AccordionTrigger className="w-full min-w-0 px-4 py-3 text-sm font-medium hover:no-underline">
|
||||
<div className="flex w-full min-w-0 items-center gap-2">
|
||||
<Settings className="h-4 w-4 shrink-0" />
|
||||
<span className="truncate">모달 기본 설정</span>
|
||||
</div>
|
||||
<HelpText>체크 해제 시 모달 하단의 저장 버튼이 숨겨집니다</HelpText>
|
||||
</div>
|
||||
|
||||
<div className="space-y-3 w-full min-w-0">
|
||||
</AccordionTrigger>
|
||||
<AccordionContent className="w-full min-w-0 space-y-4 px-4 pb-4">
|
||||
<div className="w-full min-w-0">
|
||||
<Label className="text-xs font-medium mb-1.5 block">저장 버튼 텍스트</Label>
|
||||
<Label className="mb-1.5 block text-xs font-medium">모달 제목</Label>
|
||||
<Input
|
||||
value={config.modal.saveButtonText || "저장"}
|
||||
onChange={(e) => updateModalConfig({ saveButtonText: e.target.value })}
|
||||
className="h-9 text-sm w-full max-w-full"
|
||||
value={config.modal.title}
|
||||
onChange={(e) => updateModalConfig({ title: e.target.value })}
|
||||
className="h-9 w-full max-w-full text-sm"
|
||||
/>
|
||||
<HelpText>모달 상단에 표시될 제목입니다</HelpText>
|
||||
</div>
|
||||
|
||||
<div className="w-full min-w-0">
|
||||
<Label className="text-xs font-medium mb-1.5 block">취소 버튼 텍스트</Label>
|
||||
<Input
|
||||
value={config.modal.cancelButtonText || "취소"}
|
||||
onChange={(e) => updateModalConfig({ cancelButtonText: e.target.value })}
|
||||
className="h-9 text-sm w-full max-w-full"
|
||||
/>
|
||||
<Label className="mb-1.5 block text-xs font-medium">모달 크기</Label>
|
||||
<Select value={config.modal.size} onValueChange={(value: any) => updateModalConfig({ size: value })}>
|
||||
<SelectTrigger className="h-9 w-full max-w-full text-sm">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{MODAL_SIZE_OPTIONS.map((opt) => (
|
||||
<SelectItem key={opt.value} value={opt.value}>
|
||||
{opt.label}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<HelpText>모달 창의 크기를 선택하세요</HelpText>
|
||||
</div>
|
||||
</div>
|
||||
</AccordionContent>
|
||||
</AccordionItem>
|
||||
</Accordion>
|
||||
|
||||
{/* 저장 설정 */}
|
||||
<Accordion type="single" collapsible defaultValue="save-settings" className="w-full min-w-0">
|
||||
<AccordionItem value="save-settings" className="border rounded-lg w-full min-w-0">
|
||||
<AccordionTrigger className="px-4 py-3 text-sm font-medium hover:no-underline w-full min-w-0">
|
||||
<div className="flex items-center gap-2 w-full min-w-0">
|
||||
<Database className="h-4 w-4 shrink-0" />
|
||||
<span className="truncate">저장 설정</span>
|
||||
</div>
|
||||
</AccordionTrigger>
|
||||
<AccordionContent className="px-4 pb-4 space-y-4 w-full min-w-0">
|
||||
<div className="space-y-3 w-full min-w-0">
|
||||
<div className="flex-1 min-w-0">
|
||||
<Label className="text-xs font-medium mb-1.5 block">저장 테이블</Label>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{config.saveConfig.tableName || "(미설정)"}
|
||||
</p>
|
||||
{config.saveConfig.customApiSave?.enabled && config.saveConfig.customApiSave?.multiTable?.enabled && (
|
||||
<Badge variant="secondary" className="text-xs px-2 py-0.5 mt-2">
|
||||
다중 테이블 모드
|
||||
</Badge>
|
||||
)}
|
||||
{/* 저장 버튼 표시 설정 */}
|
||||
<div className="w-full min-w-0">
|
||||
<div className="flex items-center gap-2">
|
||||
<Checkbox
|
||||
id="show-save-button"
|
||||
checked={config.modal.showSaveButton !== false}
|
||||
onCheckedChange={(checked) => updateModalConfig({ showSaveButton: checked === true })}
|
||||
/>
|
||||
<Label htmlFor="show-save-button" className="cursor-pointer text-xs font-medium">
|
||||
저장 버튼 표시
|
||||
</Label>
|
||||
</div>
|
||||
<HelpText>체크 해제 시 모달 하단의 저장 버튼이 숨겨집니다</HelpText>
|
||||
</div>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
onClick={() => setSaveSettingsModalOpen(true)}
|
||||
className="h-9 text-xs w-full"
|
||||
>
|
||||
<Settings className="h-4 w-4 mr-2" />
|
||||
저장 설정 열기
|
||||
</Button>
|
||||
</div>
|
||||
<HelpText>
|
||||
데이터를 저장할 테이블과 방식을 설정합니다.
|
||||
<br />
|
||||
"저장 설정 열기"를 클릭하여 상세 설정을 변경하세요.
|
||||
</HelpText>
|
||||
</AccordionContent>
|
||||
</AccordionItem>
|
||||
</Accordion>
|
||||
|
||||
{/* 섹션 구성 */}
|
||||
<Accordion type="single" collapsible defaultValue="sections" className="w-full min-w-0">
|
||||
<AccordionItem value="sections" className="border rounded-lg w-full min-w-0">
|
||||
<AccordionTrigger className="px-4 py-3 text-sm font-medium hover:no-underline w-full min-w-0">
|
||||
<div className="flex items-center gap-2 w-full min-w-0">
|
||||
<Layout className="h-4 w-4 shrink-0" />
|
||||
<span className="truncate">섹션 구성</span>
|
||||
<Badge variant="secondary" className="text-xs px-2 py-0.5 shrink-0">
|
||||
{config.sections.length}개
|
||||
</Badge>
|
||||
</div>
|
||||
</AccordionTrigger>
|
||||
<AccordionContent className="px-4 pb-4 space-y-4 w-full min-w-0">
|
||||
{/* 섹션 추가 버튼들 */}
|
||||
<div className="flex gap-2 w-full min-w-0">
|
||||
<Button size="sm" variant="outline" onClick={() => addSection("fields")} className="h-9 text-xs flex-1 min-w-0">
|
||||
<Plus className="h-4 w-4 mr-1 shrink-0" />
|
||||
<span className="truncate">필드 섹션</span>
|
||||
</Button>
|
||||
<Button size="sm" variant="outline" onClick={() => addSection("table")} className="h-9 text-xs flex-1 min-w-0">
|
||||
<Table className="h-4 w-4 mr-1 shrink-0" />
|
||||
<span className="truncate">테이블 섹션</span>
|
||||
</Button>
|
||||
</div>
|
||||
<HelpText>
|
||||
필드 섹션: 일반 입력 필드들을 배치합니다.
|
||||
<br />
|
||||
테이블 섹션: 품목 목록 등 반복 테이블 형식 데이터를 관리합니다.
|
||||
</HelpText>
|
||||
|
||||
{config.sections.length === 0 ? (
|
||||
<div className="text-center py-12 border border-dashed rounded-lg w-full bg-muted/20">
|
||||
<p className="text-sm text-muted-foreground mb-2 font-medium">섹션이 없습니다</p>
|
||||
<p className="text-xs text-muted-foreground">위 버튼으로 섹션을 추가하세요</p>
|
||||
<div className="w-full min-w-0 space-y-3">
|
||||
<div className="w-full min-w-0">
|
||||
<Label className="mb-1.5 block text-xs font-medium">저장 버튼 텍스트</Label>
|
||||
<Input
|
||||
value={config.modal.saveButtonText || "저장"}
|
||||
onChange={(e) => updateModalConfig({ saveButtonText: e.target.value })}
|
||||
className="h-9 w-full max-w-full text-sm"
|
||||
/>
|
||||
</div>
|
||||
<div className="w-full min-w-0">
|
||||
<Label className="mb-1.5 block text-xs font-medium">취소 버튼 텍스트</Label>
|
||||
<Input
|
||||
value={config.modal.cancelButtonText || "취소"}
|
||||
onChange={(e) => updateModalConfig({ cancelButtonText: e.target.value })}
|
||||
className="h-9 w-full max-w-full text-sm"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-3 w-full min-w-0">
|
||||
{config.sections.map((section, index) => (
|
||||
<div key={section.id} className="border rounded-lg p-3 bg-card w-full min-w-0 overflow-hidden space-y-3">
|
||||
{/* 헤더: 제목 + 타입 배지 + 삭제 */}
|
||||
<div className="flex items-start justify-between gap-3 w-full min-w-0">
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="flex items-center gap-2 mb-1.5">
|
||||
<span className="text-sm font-medium truncate">{section.title}</span>
|
||||
</AccordionContent>
|
||||
</AccordionItem>
|
||||
</Accordion>
|
||||
|
||||
{/* 저장 설정 */}
|
||||
<Accordion type="single" collapsible defaultValue="save-settings" className="w-full min-w-0">
|
||||
<AccordionItem value="save-settings" className="w-full min-w-0 rounded-lg border">
|
||||
<AccordionTrigger className="w-full min-w-0 px-4 py-3 text-sm font-medium hover:no-underline">
|
||||
<div className="flex w-full min-w-0 items-center gap-2">
|
||||
<Database className="h-4 w-4 shrink-0" />
|
||||
<span className="truncate">저장 설정</span>
|
||||
</div>
|
||||
</AccordionTrigger>
|
||||
<AccordionContent className="w-full min-w-0 space-y-4 px-4 pb-4">
|
||||
<div className="w-full min-w-0 space-y-3">
|
||||
<div className="min-w-0 flex-1">
|
||||
<Label className="mb-1.5 block text-xs font-medium">저장 테이블</Label>
|
||||
<p className="text-muted-foreground text-sm">{config.saveConfig.tableName || "(미설정)"}</p>
|
||||
{config.saveConfig.customApiSave?.enabled &&
|
||||
config.saveConfig.customApiSave?.multiTable?.enabled && (
|
||||
<Badge variant="secondary" className="mt-2 px-2 py-0.5 text-xs">
|
||||
다중 테이블 모드
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
onClick={() => setSaveSettingsModalOpen(true)}
|
||||
className="h-9 w-full text-xs"
|
||||
>
|
||||
<Settings className="mr-2 h-4 w-4" />
|
||||
저장 설정 열기
|
||||
</Button>
|
||||
</div>
|
||||
<HelpText>
|
||||
데이터를 저장할 테이블과 방식을 설정합니다.
|
||||
<br />
|
||||
"저장 설정 열기"를 클릭하여 상세 설정을 변경하세요.
|
||||
</HelpText>
|
||||
</AccordionContent>
|
||||
</AccordionItem>
|
||||
</Accordion>
|
||||
|
||||
{/* 섹션 구성 */}
|
||||
<Accordion type="single" collapsible defaultValue="sections" className="w-full min-w-0">
|
||||
<AccordionItem value="sections" className="w-full min-w-0 rounded-lg border">
|
||||
<AccordionTrigger className="w-full min-w-0 px-4 py-3 text-sm font-medium hover:no-underline">
|
||||
<div className="flex w-full min-w-0 items-center gap-2">
|
||||
<Layout className="h-4 w-4 shrink-0" />
|
||||
<span className="truncate">섹션 구성</span>
|
||||
<Badge variant="secondary" className="shrink-0 px-2 py-0.5 text-xs">
|
||||
{config.sections.length}개
|
||||
</Badge>
|
||||
</div>
|
||||
</AccordionTrigger>
|
||||
<AccordionContent className="w-full min-w-0 space-y-4 px-4 pb-4">
|
||||
{/* 섹션 추가 버튼들 */}
|
||||
<div className="flex w-full min-w-0 gap-2">
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
onClick={() => addSection("fields")}
|
||||
className="h-9 min-w-0 flex-1 text-xs"
|
||||
>
|
||||
<Plus className="mr-1 h-4 w-4 shrink-0" />
|
||||
<span className="truncate">필드 섹션</span>
|
||||
</Button>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
onClick={() => addSection("table")}
|
||||
className="h-9 min-w-0 flex-1 text-xs"
|
||||
>
|
||||
<Table className="mr-1 h-4 w-4 shrink-0" />
|
||||
<span className="truncate">테이블 섹션</span>
|
||||
</Button>
|
||||
</div>
|
||||
<HelpText>
|
||||
필드 섹션: 일반 입력 필드들을 배치합니다.
|
||||
<br />
|
||||
테이블 섹션: 품목 목록 등 반복 테이블 형식 데이터를 관리합니다.
|
||||
</HelpText>
|
||||
|
||||
{config.sections.length === 0 ? (
|
||||
<div className="bg-muted/20 w-full rounded-lg border border-dashed py-12 text-center">
|
||||
<p className="text-muted-foreground mb-2 text-sm font-medium">섹션이 없습니다</p>
|
||||
<p className="text-muted-foreground text-xs">위 버튼으로 섹션을 추가하세요</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="w-full min-w-0 space-y-3">
|
||||
{config.sections.map((section, index) => (
|
||||
<div
|
||||
key={section.id}
|
||||
className="bg-card w-full min-w-0 space-y-3 overflow-hidden rounded-lg border p-3"
|
||||
>
|
||||
{/* 헤더: 제목 + 타입 배지 + 삭제 */}
|
||||
<div className="flex w-full min-w-0 items-start justify-between gap-3">
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="mb-1.5 flex items-center gap-2">
|
||||
<span className="truncate text-sm font-medium">{section.title}</span>
|
||||
{section.type === "table" ? (
|
||||
<Badge
|
||||
variant="outline"
|
||||
className="border-purple-200 bg-purple-50 px-1.5 py-0.5 text-xs text-purple-600"
|
||||
>
|
||||
테이블
|
||||
</Badge>
|
||||
) : section.repeatable ? (
|
||||
<Badge variant="outline" className="px-1.5 py-0.5 text-xs">
|
||||
반복
|
||||
</Badge>
|
||||
) : null}
|
||||
</div>
|
||||
{section.type === "table" ? (
|
||||
<Badge variant="outline" className="text-xs px-1.5 py-0.5 text-purple-600 bg-purple-50 border-purple-200">
|
||||
테이블
|
||||
<Badge variant="secondary" className="px-2 py-0.5 text-xs">
|
||||
{section.tableConfig?.source?.tableName || "(소스 미설정)"}
|
||||
</Badge>
|
||||
) : section.repeatable ? (
|
||||
<Badge variant="outline" className="text-xs px-1.5 py-0.5">
|
||||
반복
|
||||
) : (
|
||||
<Badge variant="secondary" className="px-2 py-0.5 text-xs">
|
||||
{(section.fields || []).length}개 필드
|
||||
</Badge>
|
||||
) : null}
|
||||
)}
|
||||
</div>
|
||||
{section.type === "table" ? (
|
||||
<Badge variant="secondary" className="text-xs px-2 py-0.5">
|
||||
{section.tableConfig?.source?.tableName || "(소스 미설정)"}
|
||||
</Badge>
|
||||
) : (
|
||||
<Badge variant="secondary" className="text-xs px-2 py-0.5">
|
||||
{(section.fields || []).length}개 필드
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
onClick={() => removeSection(section.id)}
|
||||
className="h-7 w-7 p-0 text-destructive hover:text-destructive shrink-0"
|
||||
>
|
||||
<Trash2 className="h-4 w-4" />
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{/* 순서 조정 버튼 */}
|
||||
<div className="flex items-center gap-2">
|
||||
<GripVertical className="h-4 w-4 text-muted-foreground shrink-0" />
|
||||
<div className="flex gap-1">
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
onClick={() => removeSection(section.id)}
|
||||
className="text-destructive hover:text-destructive h-7 w-7 shrink-0 p-0"
|
||||
>
|
||||
<Trash2 className="h-4 w-4" />
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{/* 순서 조정 버튼 */}
|
||||
<div className="flex items-center gap-2">
|
||||
<GripVertical className="text-muted-foreground h-4 w-4 shrink-0" />
|
||||
<div className="flex gap-1">
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
onClick={() => moveSectionUp(index)}
|
||||
disabled={index === 0}
|
||||
className="h-7 px-2 text-xs"
|
||||
>
|
||||
<ChevronUp className="h-3.5 w-3.5" />
|
||||
</Button>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
onClick={() => moveSectionDown(index)}
|
||||
disabled={index === config.sections.length - 1}
|
||||
className="h-7 px-2 text-xs"
|
||||
>
|
||||
<ChevronDown className="h-3.5 w-3.5" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 필드 목록 (필드 타입만) */}
|
||||
{section.type !== "table" && (section.fields || []).length > 0 && (
|
||||
<div className="flex max-w-full flex-wrap gap-1.5 overflow-hidden pt-1">
|
||||
{(section.fields || []).slice(0, 4).map((field) => (
|
||||
<Badge
|
||||
key={field.id}
|
||||
variant="outline"
|
||||
className={cn("shrink-0 px-2 py-0.5 text-xs", getFieldTypeColor(field.fieldType))}
|
||||
>
|
||||
{field.label}
|
||||
</Badge>
|
||||
))}
|
||||
{(section.fields || []).length > 4 && (
|
||||
<Badge variant="outline" className="shrink-0 px-2 py-0.5 text-xs">
|
||||
+{(section.fields || []).length - 4}
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 테이블 컬럼 목록 (테이블 타입만) */}
|
||||
{section.type === "table" &&
|
||||
section.tableConfig?.columns &&
|
||||
section.tableConfig.columns.length > 0 && (
|
||||
<div className="flex max-w-full flex-wrap gap-1.5 overflow-hidden pt-1">
|
||||
{section.tableConfig.columns.slice(0, 4).map((col, idx) => (
|
||||
<Badge
|
||||
key={col.field || `col_${idx}`}
|
||||
variant="outline"
|
||||
className="shrink-0 border-purple-200 bg-purple-50 px-2 py-0.5 text-xs text-purple-600"
|
||||
>
|
||||
{col.label || col.field || `컬럼 ${idx + 1}`}
|
||||
</Badge>
|
||||
))}
|
||||
{section.tableConfig.columns.length > 4 && (
|
||||
<Badge variant="outline" className="shrink-0 px-2 py-0.5 text-xs">
|
||||
+{section.tableConfig.columns.length - 4}
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 설정 버튼 (타입에 따라 다름) */}
|
||||
{section.type === "table" ? (
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
onClick={() => moveSectionUp(index)}
|
||||
disabled={index === 0}
|
||||
className="h-7 px-2 text-xs"
|
||||
onClick={() => handleOpenTableSectionSettings(section)}
|
||||
className="h-9 w-full text-xs"
|
||||
>
|
||||
<ChevronUp className="h-3.5 w-3.5" />
|
||||
<Table className="mr-2 h-4 w-4" />
|
||||
테이블 설정
|
||||
</Button>
|
||||
) : (
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
onClick={() => moveSectionDown(index)}
|
||||
disabled={index === config.sections.length - 1}
|
||||
className="h-7 px-2 text-xs"
|
||||
onClick={() => handleOpenSectionLayout(section)}
|
||||
className="h-9 w-full text-xs"
|
||||
>
|
||||
<ChevronDown className="h-3.5 w-3.5" />
|
||||
<Layout className="mr-2 h-4 w-4" />
|
||||
레이아웃 설정
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* 필드 목록 (필드 타입만) */}
|
||||
{section.type !== "table" && (section.fields || []).length > 0 && (
|
||||
<div className="flex flex-wrap gap-1.5 max-w-full overflow-hidden pt-1">
|
||||
{(section.fields || []).slice(0, 4).map((field) => (
|
||||
<Badge
|
||||
key={field.id}
|
||||
variant="outline"
|
||||
className={cn("text-xs px-2 py-0.5 shrink-0", getFieldTypeColor(field.fieldType))}
|
||||
>
|
||||
{field.label}
|
||||
</Badge>
|
||||
))}
|
||||
{(section.fields || []).length > 4 && (
|
||||
<Badge variant="outline" className="text-xs px-2 py-0.5 shrink-0">
|
||||
+{(section.fields || []).length - 4}
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 테이블 컬럼 목록 (테이블 타입만) */}
|
||||
{section.type === "table" && section.tableConfig?.columns && section.tableConfig.columns.length > 0 && (
|
||||
<div className="flex flex-wrap gap-1.5 max-w-full overflow-hidden pt-1">
|
||||
{section.tableConfig.columns.slice(0, 4).map((col, idx) => (
|
||||
<Badge
|
||||
key={col.field || `col_${idx}`}
|
||||
variant="outline"
|
||||
className="text-xs px-2 py-0.5 shrink-0 text-purple-600 bg-purple-50 border-purple-200"
|
||||
>
|
||||
{col.label || col.field || `컬럼 ${idx + 1}`}
|
||||
</Badge>
|
||||
))}
|
||||
{section.tableConfig.columns.length > 4 && (
|
||||
<Badge variant="outline" className="text-xs px-2 py-0.5 shrink-0">
|
||||
+{section.tableConfig.columns.length - 4}
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 설정 버튼 (타입에 따라 다름) */}
|
||||
{section.type === "table" ? (
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
onClick={() => handleOpenTableSectionSettings(section)}
|
||||
className="h-9 text-xs w-full"
|
||||
>
|
||||
<Table className="h-4 w-4 mr-2" />
|
||||
테이블 설정
|
||||
</Button>
|
||||
) : (
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
onClick={() => handleOpenSectionLayout(section)}
|
||||
className="h-9 text-xs w-full"
|
||||
>
|
||||
<Layout className="h-4 w-4 mr-2" />
|
||||
레이아웃 설정
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</AccordionContent>
|
||||
</AccordionItem>
|
||||
</Accordion>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</AccordionContent>
|
||||
</AccordionItem>
|
||||
</Accordion>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -813,11 +834,13 @@ export function UniversalFormModalConfigPanel({ config, onChange, allComponents
|
||||
setFieldDetailModalOpen(true);
|
||||
}}
|
||||
tableName={config.saveConfig.tableName}
|
||||
tableColumns={tableColumns[config.saveConfig.tableName || ""]?.map(col => ({
|
||||
name: col.name,
|
||||
type: col.type,
|
||||
label: col.label || col.name
|
||||
})) || []}
|
||||
tableColumns={
|
||||
tableColumns[config.saveConfig.tableName || ""]?.map((col) => ({
|
||||
name: col.name,
|
||||
type: col.type,
|
||||
label: col.label || col.name,
|
||||
})) || []
|
||||
}
|
||||
/>
|
||||
)}
|
||||
|
||||
@@ -845,15 +868,13 @@ export function UniversalFormModalConfigPanel({ config, onChange, allComponents
|
||||
fields: group.fields.map((f) => (f.id === updatedField.id ? updatedField : f)),
|
||||
})),
|
||||
};
|
||||
|
||||
|
||||
// config 업데이트
|
||||
onChange({
|
||||
...config,
|
||||
sections: config.sections.map((s) =>
|
||||
s.id === selectedSection.id ? updatedSection : s
|
||||
),
|
||||
sections: config.sections.map((s) => (s.id === selectedSection.id ? updatedSection : s)),
|
||||
});
|
||||
|
||||
|
||||
// selectedSection과 selectedField 상태도 업데이트 (다음에 다시 열었을 때 최신 값 반영)
|
||||
setSelectedSection(updatedSection);
|
||||
setSelectedField(updatedField as FormFieldConfig);
|
||||
@@ -881,29 +902,28 @@ export function UniversalFormModalConfigPanel({ config, onChange, allComponents
|
||||
...selectedSection,
|
||||
...updates,
|
||||
};
|
||||
|
||||
|
||||
// config 업데이트
|
||||
onChange({
|
||||
...config,
|
||||
sections: config.sections.map((s) =>
|
||||
s.id === selectedSection.id ? updatedSection : s
|
||||
),
|
||||
sections: config.sections.map((s) => (s.id === selectedSection.id ? updatedSection : s)),
|
||||
});
|
||||
|
||||
|
||||
setSelectedSection(updatedSection);
|
||||
setTableSectionSettingsModalOpen(false);
|
||||
}}
|
||||
tables={tables.map(t => ({ table_name: t.name, comment: t.label }))}
|
||||
tables={tables.map((t) => ({ table_name: t.name, comment: t.label }))}
|
||||
tableColumns={Object.fromEntries(
|
||||
Object.entries(tableColumns).map(([tableName, cols]) => [
|
||||
tableName,
|
||||
cols.map(c => ({
|
||||
cols.map((c) => ({
|
||||
column_name: c.name,
|
||||
data_type: c.type,
|
||||
is_nullable: "YES",
|
||||
comment: c.label,
|
||||
input_type: c.inputType || "text",
|
||||
})),
|
||||
])
|
||||
]),
|
||||
)}
|
||||
onLoadTableColumns={loadTableColumns}
|
||||
allSections={config.sections as FormSectionConfig[]}
|
||||
|
||||
Reference in New Issue
Block a user