"use client"; import React, { useState } from "react"; import { ListWidgetConfig, QueryResult, FieldGroup, FieldConfig, DisplayColumnConfig } from "../types"; import { Label } from "@/components/ui/label"; import { Input } from "@/components/ui/input"; import { Button } from "@/components/ui/button"; import { Switch } from "@/components/ui/switch"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; import { UnifiedColumnEditor } from "../widgets/list-widget/UnifiedColumnEditor"; import { ListTableOptions } from "../widgets/list-widget/ListTableOptions"; import { Plus, Trash2, ChevronDown, ChevronUp, X, Check } from "lucide-react"; import { Checkbox } from "@/components/ui/checkbox"; import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover"; interface ListWidgetSectionProps { queryResult: QueryResult | null; config: ListWidgetConfig; onConfigChange: (updates: Partial) => void; } /** * 리스트 위젯 설정 섹션 * - 컬럼 설정 * - 테이블 옵션 * - 행 클릭 팝업 설정 */ export function ListWidgetSection({ queryResult, config, onConfigChange }: ListWidgetSectionProps) { const [expandedGroups, setExpandedGroups] = useState>({}); // 팝업 설정 초기화 const popupConfig = config.rowDetailPopup || { enabled: false, title: "상세 정보", additionalQuery: { enabled: false, tableName: "", matchColumn: "" }, fieldGroups: [], }; // 팝업 설정 업데이트 헬퍼 const updatePopupConfig = (updates: Partial) => { onConfigChange({ rowDetailPopup: { ...popupConfig, ...updates }, }); }; // 필드 그룹 추가 const addFieldGroup = () => { const newGroup: FieldGroup = { id: `group-${Date.now()}`, title: "새 그룹", icon: "info", color: "gray", fields: [], }; updatePopupConfig({ fieldGroups: [...(popupConfig.fieldGroups || []), newGroup], }); }; // 필드 그룹 삭제 const removeFieldGroup = (groupId: string) => { updatePopupConfig({ fieldGroups: (popupConfig.fieldGroups || []).filter((g) => g.id !== groupId), }); }; // 필드 그룹 업데이트 const updateFieldGroup = (groupId: string, updates: Partial) => { updatePopupConfig({ fieldGroups: (popupConfig.fieldGroups || []).map((g) => (g.id === groupId ? { ...g, ...updates } : g)), }); }; // 필드 추가 const addField = (groupId: string) => { const newField: FieldConfig = { column: "", label: "", format: "text", }; updatePopupConfig({ fieldGroups: (popupConfig.fieldGroups || []).map((g) => g.id === groupId ? { ...g, fields: [...g.fields, newField] } : g, ), }); }; // 필드 삭제 const removeField = (groupId: string, fieldIndex: number) => { updatePopupConfig({ fieldGroups: (popupConfig.fieldGroups || []).map((g) => g.id === groupId ? { ...g, fields: g.fields.filter((_, i) => i !== fieldIndex) } : g, ), }); }; // 필드 업데이트 const updateField = (groupId: string, fieldIndex: number, updates: Partial) => { updatePopupConfig({ fieldGroups: (popupConfig.fieldGroups || []).map((g) => g.id === groupId ? { ...g, fields: g.fields.map((f, i) => (i === fieldIndex ? { ...f, ...updates } : f)) } : g, ), }); }; // 그룹 확장/축소 토글 const toggleGroupExpand = (groupId: string) => { setExpandedGroups((prev) => ({ ...prev, [groupId]: !prev[groupId] })); }; return (
{/* 컬럼 설정 - 쿼리 실행 후에만 표시 */} {queryResult && queryResult.columns.length > 0 && (
)} {/* 테이블 옵션 */} {config.columns.length > 0 && (
)} {/* 행 클릭 팝업 설정 */}
updatePopupConfig({ enabled })} aria-label="행 클릭 팝업 활성화" />
{popupConfig.enabled && (
{/* 팝업 제목 */}
updatePopupConfig({ title: e.target.value })} placeholder="상세 정보" className="mt-1 h-8 text-xs" />
{/* 추가 데이터 조회 설정 */}
updatePopupConfig({ additionalQuery: { ...popupConfig.additionalQuery, enabled, queryMode: "table", tableName: "", matchColumn: "" }, }) } aria-label="추가 데이터 조회 활성화" />
{popupConfig.additionalQuery?.enabled && (
{/* 조회 모드 선택 */}
{/* 테이블 조회 모드 */} {(popupConfig.additionalQuery?.queryMode || "table") === "table" && ( <>
updatePopupConfig({ additionalQuery: { ...popupConfig.additionalQuery!, tableName: e.target.value }, }) } placeholder="vehicles" className="mt-1 h-8 text-xs" />
updatePopupConfig({ additionalQuery: { ...popupConfig.additionalQuery!, matchColumn: e.target.value }, }) } placeholder="id" className="mt-1 h-8 text-xs" />
updatePopupConfig({ additionalQuery: { ...popupConfig.additionalQuery!, sourceColumn: e.target.value }, }) } placeholder="비워두면 매칭 컬럼과 동일" className="mt-1 h-8 text-xs" />
)} {/* 커스텀 쿼리 모드 */} {popupConfig.additionalQuery?.queryMode === "custom" && ( <>
updatePopupConfig({ additionalQuery: { ...popupConfig.additionalQuery!, sourceColumn: e.target.value }, }) } placeholder="id" className="mt-1 h-8 text-xs" />

쿼리에서 사용할 파라미터 컬럼