"use client"; 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 { Button } from "@/components/ui/button"; import { Textarea } from "@/components/ui/textarea"; import { Separator } from "@/components/ui/separator"; import { RefreshCw } from "lucide-react"; interface MapConfigPanelProps { config: any; onChange: (config: any) => void; } interface DbConnection { id: number; name: string; db_type: string; } interface TableInfo { table_name: string; } interface ColumnInfo { column_name: string; data_type: string; } export default function MapConfigPanel({ config, onChange }: MapConfigPanelProps) { const [connections, setConnections] = useState([]); const [tables, setTables] = useState([]); const [columns, setColumns] = useState([]); const [isLoadingConnections, setIsLoadingConnections] = useState(false); const [isLoadingTables, setIsLoadingTables] = useState(false); const [isLoadingColumns, setIsLoadingColumns] = useState(false); // DB 연결 목록 로드 useEffect(() => { loadConnections(); }, []); // 테이블 목록 로드 useEffect(() => { if (config.dataSource?.type === "external" && config.dataSource?.connectionId) { loadTables(config.dataSource.connectionId); } else if (config.dataSource?.type === "internal") { loadInternalTables(); } }, [config.dataSource?.type, config.dataSource?.connectionId]); // 컬럼 목록 로드 useEffect(() => { if (config.dataSource?.tableName) { if (config.dataSource.type === "external" && config.dataSource.connectionId) { loadColumns(config.dataSource.connectionId, config.dataSource.tableName); } else if (config.dataSource.type === "internal") { loadInternalColumns(config.dataSource.tableName); } } }, [config.dataSource?.tableName]); const loadConnections = async () => { setIsLoadingConnections(true); try { const response = await fetch("/api/external-db-connections"); const data = await response.json(); if (data.success) { setConnections(data.data || []); } } catch (error) { console.error("DB 연결 목록 로드 실패:", error); } finally { setIsLoadingConnections(false); } }; const loadTables = async (connectionId: number) => { setIsLoadingTables(true); try { const response = await fetch(`/api/external-db-connections/${connectionId}/tables`); const data = await response.json(); if (data.success) { setTables(data.data || []); } } catch (error) { console.error("테이블 목록 로드 실패:", error); } finally { setIsLoadingTables(false); } }; const loadInternalTables = async () => { setIsLoadingTables(true); try { const response = await fetch("/api/table-management/tables"); const data = await response.json(); if (data.success) { setTables(data.data.map((t: any) => ({ table_name: t.tableName })) || []); } } catch (error) { console.error("내부 테이블 목록 로드 실패:", error); } finally { setIsLoadingTables(false); } }; const loadColumns = async (connectionId: number, tableName: string) => { setIsLoadingColumns(true); try { const response = await fetch( `/api/external-db-connections/${connectionId}/tables/${encodeURIComponent(tableName)}/columns` ); const data = await response.json(); if (data.success) { setColumns(data.data || []); } } catch (error) { console.error("컬럼 목록 로드 실패:", error); } finally { setIsLoadingColumns(false); } }; const loadInternalColumns = async (tableName: string) => { setIsLoadingColumns(true); try { const response = await fetch(`/api/table-management/tables/${encodeURIComponent(tableName)}/columns`); const data = await response.json(); if (data.success) { setColumns(data.data.map((c: any) => ({ column_name: c.columnName, data_type: c.dataType })) || []); } } catch (error) { console.error("내부 컬럼 목록 로드 실패:", error); } finally { setIsLoadingColumns(false); } }; const updateConfig = (path: string, value: any) => { const keys = path.split("."); const newConfig = { ...config }; let current: any = newConfig; for (let i = 0; i < keys.length - 1; i++) { if (!current[keys[i]]) { current[keys[i]] = {}; } current = current[keys[i]]; } current[keys[keys.length - 1]] = value; onChange(newConfig); }; return (

📊 데이터 소스

{/* DB 타입 선택 */}
{/* 외부 DB 연결 선택 */} {config.dataSource?.type === "external" && (
)} {/* 테이블 선택 */}
{/* 위도 컬럼 */}
{/* 경도 컬럼 */}
{/* 라벨 컬럼 (선택) */}
{/* Radix UI Select v2.x: 빈 문자열 value="" 금지 → "__none__" 사용 */}
{/* 상태 컬럼 (선택) */}
{/* Radix UI Select v2.x: 빈 문자열 value="" 금지 → "__none__" 사용 */}
{/* WHERE 조건 (선택) */}