"use client"; import React, { useState, useEffect } from "react"; import { Label } from "@/components/ui/label"; import { Input } from "@/components/ui/input"; import { Switch } from "@/components/ui/switch"; import { Button } from "@/components/ui/button"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; import { Accordion, AccordionContent, AccordionItem, AccordionTrigger, } from "@/components/ui/accordion"; import { Popover, PopoverContent, PopoverTrigger, } from "@/components/ui/popover"; import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, } from "@/components/ui/command"; import { Check, ChevronsUpDown, Loader2 } from "lucide-react"; import { cn } from "@/lib/utils"; import { tableTypeApi } from "@/lib/api/screen"; import { TimelineSchedulerConfig } from "./types"; import { zoomLevelOptions, statusOptions } from "./config"; interface TimelineSchedulerConfigPanelProps { config: TimelineSchedulerConfig; onChange: (config: Partial) => void; } interface TableInfo { tableName: string; displayName: string; } interface ColumnInfo { columnName: string; displayName: string; } export function TimelineSchedulerConfigPanel({ config, onChange, }: TimelineSchedulerConfigPanelProps) { const [tables, setTables] = useState([]); const [tableColumns, setTableColumns] = useState([]); const [resourceColumns, setResourceColumns] = useState([]); const [loading, setLoading] = useState(false); const [tableSelectOpen, setTableSelectOpen] = useState(false); const [resourceTableSelectOpen, setResourceTableSelectOpen] = useState(false); // 테이블 목록 로드 useEffect(() => { const loadTables = async () => { setLoading(true); try { const tableList = await tableTypeApi.getTables(); if (Array.isArray(tableList)) { setTables( tableList.map((t: any) => ({ tableName: t.table_name || t.tableName, displayName: t.display_name || t.displayName || t.table_name || t.tableName, })) ); } } catch (err) { console.error("테이블 목록 로드 오류:", err); } finally { setLoading(false); } }; loadTables(); }, []); // 스케줄 테이블 컬럼 로드 useEffect(() => { const loadColumns = async () => { if (!config.selectedTable) { setTableColumns([]); return; } try { const columns = await tableTypeApi.getColumns(config.selectedTable); if (Array.isArray(columns)) { setTableColumns( columns.map((col: any) => ({ columnName: col.column_name || col.columnName, displayName: col.display_name || col.displayName || col.column_name || col.columnName, })) ); } } catch (err) { console.error("컬럼 로드 오류:", err); setTableColumns([]); } }; loadColumns(); }, [config.selectedTable]); // 리소스 테이블 컬럼 로드 useEffect(() => { const loadResourceColumns = async () => { if (!config.resourceTable) { setResourceColumns([]); return; } try { const columns = await tableTypeApi.getColumns(config.resourceTable); if (Array.isArray(columns)) { setResourceColumns( columns.map((col: any) => ({ columnName: col.column_name || col.columnName, displayName: col.display_name || col.displayName || col.column_name || col.columnName, })) ); } } catch (err) { console.error("리소스 컬럼 로드 오류:", err); setResourceColumns([]); } }; loadResourceColumns(); }, [config.resourceTable]); // 설정 업데이트 헬퍼 const updateConfig = (updates: Partial) => { onChange({ ...config, ...updates }); }; // 필드 매핑 업데이트 const updateFieldMapping = (field: string, value: string) => { updateConfig({ fieldMapping: { ...config.fieldMapping, [field]: value, }, }); }; // 리소스 필드 매핑 업데이트 const updateResourceFieldMapping = (field: string, value: string) => { updateConfig({ resourceFieldMapping: { ...config.resourceFieldMapping, id: config.resourceFieldMapping?.id || "id", name: config.resourceFieldMapping?.name || "name", [field]: value, }, }); }; return (
{/* 테이블 설정 */} 테이블 설정 {/* 스케줄 테이블 선택 */}
{ const lowerSearch = search.toLowerCase(); if (value.toLowerCase().includes(lowerSearch)) { return 1; } return 0; }} > 테이블을 찾을 수 없습니다. {tables.map((table) => ( { updateConfig({ selectedTable: table.tableName }); setTableSelectOpen(false); }} className="text-xs" >
{table.displayName} {table.tableName}
))}
{/* 리소스 테이블 선택 */}
{ const lowerSearch = search.toLowerCase(); if (value.toLowerCase().includes(lowerSearch)) { return 1; } return 0; }} > 테이블을 찾을 수 없습니다. {tables.map((table) => ( { updateConfig({ resourceTable: table.tableName }); setResourceTableSelectOpen(false); }} className="text-xs" >
{table.displayName} {table.tableName}
))}
{/* 필드 매핑 */} 필드 매핑 {/* 스케줄 필드 매핑 */} {config.selectedTable && (
{/* ID 필드 */}
{/* 리소스 ID 필드 */}
{/* 제목 필드 */}
{/* 시작일 필드 */}
{/* 종료일 필드 */}
{/* 상태 필드 */}
)} {/* 리소스 필드 매핑 */} {config.resourceTable && (
{/* ID 필드 */}
{/* 이름 필드 */}
)}
{/* 표시 설정 */} 표시 설정 {/* 기본 줌 레벨 */}
{/* 높이 */}
updateConfig({ height: parseInt(e.target.value) || 500 }) } className="h-8 text-xs" />
{/* 행 높이 */}
updateConfig({ rowHeight: parseInt(e.target.value) || 50 }) } className="h-8 text-xs" />
{/* 토글 스위치들 */}
updateConfig({ editable: v })} />
updateConfig({ draggable: v })} />
updateConfig({ resizable: v })} />
updateConfig({ showTodayLine: v })} />
updateConfig({ showProgress: v })} />
updateConfig({ showToolbar: v })} />
); } export default TimelineSchedulerConfigPanel;