"use client"; /** * V2Hierarchy 설정 패널 * 통합 계층 컴포넌트의 세부 설정을 관리합니다. */ import React, { useState, useEffect } from "react"; import { Label } from "@/components/ui/label"; import { Input } from "@/components/ui/input"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; import { Separator } from "@/components/ui/separator"; import { Checkbox } from "@/components/ui/checkbox"; import { tableTypeApi } from "@/lib/api/screen"; interface V2HierarchyConfigPanelProps { config: Record; onChange: (config: Record) => void; } interface TableOption { tableName: string; displayName: string; } interface ColumnOption { columnName: string; displayName: string; } export const V2HierarchyConfigPanel: React.FC = ({ config, onChange, }) => { // 테이블 목록 const [tables, setTables] = useState([]); const [loadingTables, setLoadingTables] = useState(false); // 컬럼 목록 const [columns, setColumns] = useState([]); const [loadingColumns, setLoadingColumns] = useState(false); // 설정 업데이트 핸들러 const updateConfig = (field: string, value: any) => { onChange({ ...config, [field]: value }); }; // 테이블 목록 로드 useEffect(() => { const loadTables = async () => { setLoadingTables(true); try { const data = await tableTypeApi.getTables(); setTables(data.map(t => ({ tableName: t.tableName, displayName: t.displayName || t.tableName }))); } catch (error) { console.error("테이블 목록 로드 실패:", error); } finally { setLoadingTables(false); } }; loadTables(); }, []); // 테이블 선택 시 컬럼 목록 로드 useEffect(() => { const loadColumns = async () => { if (!config.tableName) { setColumns([]); return; } setLoadingColumns(true); try { const data = await tableTypeApi.getColumns(config.tableName); setColumns(data.map((c: any) => ({ columnName: c.columnName || c.column_name, displayName: c.displayName || c.columnName || c.column_name }))); } catch (error) { console.error("컬럼 목록 로드 실패:", error); } finally { setLoadingColumns(false); } }; loadColumns(); }, [config.tableName]); return (
{/* 계층 타입 */}
{/* 뷰 모드 */}
{/* 데이터 소스 */}
{/* DB 설정 */} {config.dataSource === "db" && (
{/* 테이블 선택 */}
{/* 컬럼 선택 */} {config.tableName && ( <>
)}
)} {/* API 설정 */} {config.dataSource === "api" && (
updateConfig("apiEndpoint", e.target.value)} placeholder="/api/hierarchy" className="h-8 text-xs" />
)} {/* 옵션 */}
updateConfig("maxLevel", e.target.value ? Number(e.target.value) : undefined)} placeholder="제한 없음" min="1" className="h-8 text-xs" />
updateConfig("draggable", checked)} />
updateConfig("selectable", checked)} />
updateConfig("multiSelect", checked)} />
updateConfig("showCheckbox", checked)} />
updateConfig("expandAll", checked)} />
{/* BOM 전용 설정 */} {config.hierarchyType === "bom" && ( <>
updateConfig("showQuantity", checked)} />
)} {/* 연쇄 선택박스 전용 설정 */} {config.hierarchyType === "cascading" && ( <>
updateConfig("clearOnParentChange", checked)} />
)}
); }; V2HierarchyConfigPanel.displayName = "V2HierarchyConfigPanel"; export default V2HierarchyConfigPanel;