2025-08-21 09:41:46 +09:00
|
|
|
"use client";
|
|
|
|
|
|
2025-09-08 14:20:01 +09:00
|
|
|
import { useState, useEffect, useMemo, useCallback } from "react";
|
2025-08-21 09:41:46 +09:00
|
|
|
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
|
|
|
|
import { Input } from "@/components/ui/input";
|
|
|
|
|
import { Button } from "@/components/ui/button";
|
|
|
|
|
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
|
|
|
|
|
import { Badge } from "@/components/ui/badge";
|
|
|
|
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
2025-09-22 17:00:59 +09:00
|
|
|
import { Search, Database, RefreshCw, Settings, Menu, X, Plus, Activity } from "lucide-react";
|
2025-08-21 09:41:46 +09:00
|
|
|
import { LoadingSpinner } from "@/components/common/LoadingSpinner";
|
|
|
|
|
import { toast } from "sonner";
|
2025-08-29 10:09:34 +09:00
|
|
|
import { useMultiLang } from "@/hooks/useMultiLang";
|
2025-09-22 17:00:59 +09:00
|
|
|
import { useAuth } from "@/hooks/useAuth";
|
2025-09-23 10:40:21 +09:00
|
|
|
import { TABLE_MANAGEMENT_KEYS } from "@/constants/tableManagement";
|
|
|
|
|
import { INPUT_TYPE_OPTIONS } from "@/types/input-types";
|
2025-08-29 10:09:34 +09:00
|
|
|
import { apiClient } from "@/lib/api/client";
|
2025-09-15 15:38:48 +09:00
|
|
|
import { commonCodeApi } from "@/lib/api/commonCode";
|
2025-09-16 15:13:00 +09:00
|
|
|
import { entityJoinApi, ReferenceTableColumn } from "@/lib/api/entityJoin";
|
2025-09-22 17:00:59 +09:00
|
|
|
import { CreateTableModal } from "@/components/admin/CreateTableModal";
|
|
|
|
|
import { AddColumnModal } from "@/components/admin/AddColumnModal";
|
|
|
|
|
import { DDLLogViewer } from "@/components/admin/DDLLogViewer";
|
2025-09-08 14:20:01 +09:00
|
|
|
// 가상화 스크롤링을 위한 간단한 구현
|
2025-08-21 09:41:46 +09:00
|
|
|
|
|
|
|
|
interface TableInfo {
|
|
|
|
|
tableName: string;
|
|
|
|
|
displayName: string;
|
|
|
|
|
description: string;
|
|
|
|
|
columnCount: number;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface ColumnTypeInfo {
|
|
|
|
|
columnName: string;
|
|
|
|
|
displayName: string;
|
2025-09-23 10:40:21 +09:00
|
|
|
inputType: string; // webType → inputType 변경
|
2025-08-21 09:41:46 +09:00
|
|
|
detailSettings: string;
|
|
|
|
|
description: string;
|
|
|
|
|
isNullable: string;
|
|
|
|
|
defaultValue?: string;
|
|
|
|
|
maxLength?: number;
|
|
|
|
|
numericPrecision?: number;
|
|
|
|
|
numericScale?: number;
|
|
|
|
|
codeCategory?: string;
|
|
|
|
|
codeValue?: string;
|
|
|
|
|
referenceTable?: string;
|
|
|
|
|
referenceColumn?: string;
|
2025-09-16 15:13:00 +09:00
|
|
|
displayColumn?: string; // 🎯 Entity 조인에서 표시할 컬럼명
|
2025-08-21 09:41:46 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default function TableManagementPage() {
|
2025-08-29 10:09:34 +09:00
|
|
|
const { userLang, getText } = useMultiLang({ companyCode: "*" });
|
2025-09-22 17:00:59 +09:00
|
|
|
const { user } = useAuth();
|
2025-08-21 09:41:46 +09:00
|
|
|
const [tables, setTables] = useState<TableInfo[]>([]);
|
|
|
|
|
const [columns, setColumns] = useState<ColumnTypeInfo[]>([]);
|
|
|
|
|
const [selectedTable, setSelectedTable] = useState<string | null>(null);
|
|
|
|
|
const [searchTerm, setSearchTerm] = useState("");
|
|
|
|
|
const [loading, setLoading] = useState(false);
|
|
|
|
|
const [columnsLoading, setColumnsLoading] = useState(false);
|
|
|
|
|
const [originalColumns, setOriginalColumns] = useState<ColumnTypeInfo[]>([]); // 원본 데이터 저장
|
2025-08-29 10:09:34 +09:00
|
|
|
const [uiTexts, setUiTexts] = useState<Record<string, string>>({});
|
2025-08-21 09:41:46 +09:00
|
|
|
|
2025-09-08 14:20:01 +09:00
|
|
|
// 페이지네이션 상태
|
|
|
|
|
const [currentPage, setCurrentPage] = useState(1);
|
|
|
|
|
const [pageSize, setPageSize] = useState(50);
|
|
|
|
|
const [totalColumns, setTotalColumns] = useState(0);
|
|
|
|
|
|
|
|
|
|
// 테이블 라벨 상태
|
|
|
|
|
const [tableLabel, setTableLabel] = useState("");
|
|
|
|
|
const [tableDescription, setTableDescription] = useState("");
|
|
|
|
|
|
2025-09-16 15:13:00 +09:00
|
|
|
// 🎯 Entity 조인 관련 상태
|
|
|
|
|
const [referenceTableColumns, setReferenceTableColumns] = useState<Record<string, ReferenceTableColumn[]>>({});
|
|
|
|
|
|
2025-09-22 17:00:59 +09:00
|
|
|
// DDL 기능 관련 상태
|
|
|
|
|
const [createTableModalOpen, setCreateTableModalOpen] = useState(false);
|
|
|
|
|
const [addColumnModalOpen, setAddColumnModalOpen] = useState(false);
|
|
|
|
|
const [ddlLogViewerOpen, setDdlLogViewerOpen] = useState(false);
|
|
|
|
|
|
2025-09-30 18:28:54 +09:00
|
|
|
// 최고 관리자 여부 확인 (회사코드가 "*"인 경우)
|
|
|
|
|
const isSuperAdmin = user?.companyCode === "*";
|
2025-09-22 17:00:59 +09:00
|
|
|
|
2025-08-29 10:09:34 +09:00
|
|
|
// 다국어 텍스트 로드
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
const loadTexts = async () => {
|
|
|
|
|
if (!userLang) return;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const response = await apiClient.post(
|
|
|
|
|
"/multilang/batch",
|
|
|
|
|
{
|
|
|
|
|
langKeys: Object.values(TABLE_MANAGEMENT_KEYS),
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
params: {
|
|
|
|
|
companyCode: "*",
|
|
|
|
|
menuCode: "TABLE_MANAGEMENT",
|
|
|
|
|
userLang: userLang,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (response.data.success) {
|
|
|
|
|
setUiTexts(response.data.data);
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error("다국어 텍스트 로드 실패:", error);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
loadTexts();
|
|
|
|
|
}, [userLang]);
|
|
|
|
|
|
|
|
|
|
// 텍스트 가져오기 함수
|
|
|
|
|
const getTextFromUI = (key: string, fallback?: string) => {
|
|
|
|
|
return uiTexts[key] || fallback || key;
|
|
|
|
|
};
|
|
|
|
|
|
2025-09-16 15:13:00 +09:00
|
|
|
// 🎯 참조 테이블 컬럼 정보 로드
|
|
|
|
|
const loadReferenceTableColumns = useCallback(
|
|
|
|
|
async (tableName: string) => {
|
|
|
|
|
if (!tableName) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 이미 로드된 경우이지만 빈 배열이 아닌 경우만 스킵
|
|
|
|
|
const existingColumns = referenceTableColumns[tableName];
|
|
|
|
|
if (existingColumns && existingColumns.length > 0) {
|
|
|
|
|
console.log(`🎯 참조 테이블 컬럼 이미 로드됨: ${tableName}`, existingColumns);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log(`🎯 참조 테이블 컬럼 로드 시작: ${tableName}`);
|
|
|
|
|
try {
|
|
|
|
|
const result = await entityJoinApi.getReferenceTableColumns(tableName);
|
|
|
|
|
console.log(`🎯 참조 테이블 컬럼 로드 성공: ${tableName}`, result.columns);
|
|
|
|
|
setReferenceTableColumns((prev) => ({
|
|
|
|
|
...prev,
|
|
|
|
|
[tableName]: result.columns,
|
|
|
|
|
}));
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error(`참조 테이블 컬럼 로드 실패: ${tableName}`, error);
|
|
|
|
|
setReferenceTableColumns((prev) => ({
|
|
|
|
|
...prev,
|
|
|
|
|
[tableName]: [],
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
[], // 의존성 배열에서 referenceTableColumns 제거
|
|
|
|
|
);
|
|
|
|
|
|
2025-09-23 10:40:21 +09:00
|
|
|
// 입력 타입 옵션 (8개 핵심 타입)
|
|
|
|
|
const inputTypeOptions = INPUT_TYPE_OPTIONS.map((option) => ({
|
|
|
|
|
value: option.value,
|
|
|
|
|
label: option.label,
|
|
|
|
|
description: option.description,
|
|
|
|
|
}));
|
2025-08-21 09:41:46 +09:00
|
|
|
|
2025-09-23 10:40:21 +09:00
|
|
|
// 메모이제이션된 입력타입 옵션
|
|
|
|
|
const memoizedInputTypeOptions = useMemo(() => inputTypeOptions, []);
|
2025-09-01 11:48:12 +09:00
|
|
|
|
2025-08-21 09:41:46 +09:00
|
|
|
// 참조 테이블 옵션 (실제 테이블 목록에서 가져옴)
|
|
|
|
|
const referenceTableOptions = [
|
2025-08-29 10:09:34 +09:00
|
|
|
{ value: "none", label: getTextFromUI(TABLE_MANAGEMENT_KEYS.LABEL_NONE, "선택 안함") },
|
2025-08-21 09:41:46 +09:00
|
|
|
...tables.map((table) => ({ value: table.tableName, label: table.displayName || table.tableName })),
|
|
|
|
|
];
|
|
|
|
|
|
2025-09-15 15:38:48 +09:00
|
|
|
// 공통 코드 카테고리 목록 상태
|
|
|
|
|
const [commonCodeCategories, setCommonCodeCategories] = useState<Array<{ value: string; label: string }>>([]);
|
|
|
|
|
|
|
|
|
|
// 공통 코드 옵션
|
2025-08-21 09:41:46 +09:00
|
|
|
const commonCodeOptions = [
|
2025-08-29 10:09:34 +09:00
|
|
|
{ value: "none", label: getTextFromUI(TABLE_MANAGEMENT_KEYS.SELECT_CODE_PLACEHOLDER, "코드 선택") },
|
2025-09-15 15:38:48 +09:00
|
|
|
...commonCodeCategories,
|
2025-08-21 09:41:46 +09:00
|
|
|
];
|
|
|
|
|
|
2025-09-15 15:38:48 +09:00
|
|
|
// 공통코드 카테고리 목록 로드
|
|
|
|
|
const loadCommonCodeCategories = async () => {
|
|
|
|
|
try {
|
|
|
|
|
const response = await commonCodeApi.categories.getList({ isActive: true });
|
|
|
|
|
console.log("🔍 공통코드 카테고리 API 응답:", response);
|
|
|
|
|
|
|
|
|
|
if (response.success && response.data) {
|
|
|
|
|
console.log("📋 공통코드 카테고리 데이터:", response.data);
|
|
|
|
|
|
|
|
|
|
const categories = response.data.map((category) => {
|
|
|
|
|
console.log("🏷️ 카테고리 항목:", category);
|
|
|
|
|
return {
|
|
|
|
|
value: category.category_code,
|
|
|
|
|
label: category.category_name || category.category_code,
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
console.log("✅ 매핑된 카테고리 옵션:", categories);
|
|
|
|
|
setCommonCodeCategories(categories);
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error("공통코드 카테고리 로드 실패:", error);
|
|
|
|
|
// 에러는 로그만 남기고 사용자에게는 알리지 않음 (선택적 기능)
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2025-08-21 09:41:46 +09:00
|
|
|
// 테이블 목록 로드
|
|
|
|
|
const loadTables = async () => {
|
|
|
|
|
setLoading(true);
|
|
|
|
|
try {
|
2025-08-29 10:09:34 +09:00
|
|
|
const response = await apiClient.get("/table-management/tables");
|
2025-08-21 09:41:46 +09:00
|
|
|
|
|
|
|
|
// 응답 상태 확인
|
2025-08-29 10:09:34 +09:00
|
|
|
if (response.data.success) {
|
|
|
|
|
setTables(response.data.data);
|
2025-08-21 09:41:46 +09:00
|
|
|
toast.success("테이블 목록을 성공적으로 로드했습니다.");
|
|
|
|
|
} else {
|
2025-08-29 10:09:34 +09:00
|
|
|
toast.error(response.data.message || "테이블 목록 로드에 실패했습니다.");
|
2025-08-21 09:41:46 +09:00
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error("테이블 목록 로드 실패:", error);
|
|
|
|
|
toast.error("테이블 목록 로드 중 오류가 발생했습니다.");
|
|
|
|
|
} finally {
|
|
|
|
|
setLoading(false);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2025-09-08 14:20:01 +09:00
|
|
|
// 컬럼 타입 정보 로드 (페이지네이션 적용)
|
|
|
|
|
const loadColumnTypes = useCallback(async (tableName: string, page: number = 1, size: number = 50) => {
|
2025-08-21 09:41:46 +09:00
|
|
|
setColumnsLoading(true);
|
|
|
|
|
try {
|
2025-09-08 14:20:01 +09:00
|
|
|
const response = await apiClient.get(`/table-management/tables/${tableName}/columns`, {
|
|
|
|
|
params: { page, size },
|
|
|
|
|
});
|
2025-08-21 09:41:46 +09:00
|
|
|
|
|
|
|
|
// 응답 상태 확인
|
2025-08-29 10:09:34 +09:00
|
|
|
if (response.data.success) {
|
2025-09-08 14:20:01 +09:00
|
|
|
const data = response.data.data;
|
2025-09-23 10:40:21 +09:00
|
|
|
|
|
|
|
|
// 컬럼 데이터에 기본값 설정
|
|
|
|
|
const processedColumns = (data.columns || data).map((col: any) => ({
|
|
|
|
|
...col,
|
|
|
|
|
inputType: col.inputType || "text", // 기본값: text
|
|
|
|
|
}));
|
|
|
|
|
|
2025-09-08 14:20:01 +09:00
|
|
|
if (page === 1) {
|
2025-09-23 10:40:21 +09:00
|
|
|
setColumns(processedColumns);
|
|
|
|
|
setOriginalColumns(processedColumns);
|
2025-09-08 14:20:01 +09:00
|
|
|
} else {
|
|
|
|
|
// 페이지 추가 로드 시 기존 데이터에 추가
|
2025-09-23 10:40:21 +09:00
|
|
|
setColumns((prev) => [...prev, ...processedColumns]);
|
2025-09-08 14:20:01 +09:00
|
|
|
}
|
2025-09-23 10:40:21 +09:00
|
|
|
setTotalColumns(data.total || processedColumns.length);
|
2025-08-21 09:41:46 +09:00
|
|
|
toast.success("컬럼 정보를 성공적으로 로드했습니다.");
|
|
|
|
|
} else {
|
2025-08-29 10:09:34 +09:00
|
|
|
toast.error(response.data.message || "컬럼 정보 로드에 실패했습니다.");
|
2025-08-21 09:41:46 +09:00
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error("컬럼 타입 정보 로드 실패:", error);
|
|
|
|
|
toast.error("컬럼 정보 로드 중 오류가 발생했습니다.");
|
|
|
|
|
} finally {
|
|
|
|
|
setColumnsLoading(false);
|
|
|
|
|
}
|
2025-09-08 14:20:01 +09:00
|
|
|
}, []);
|
2025-08-21 09:41:46 +09:00
|
|
|
|
|
|
|
|
// 테이블 선택
|
2025-09-08 14:20:01 +09:00
|
|
|
const handleTableSelect = useCallback(
|
|
|
|
|
(tableName: string) => {
|
|
|
|
|
setSelectedTable(tableName);
|
|
|
|
|
setCurrentPage(1);
|
|
|
|
|
setColumns([]);
|
|
|
|
|
|
|
|
|
|
// 선택된 테이블 정보에서 라벨 설정
|
|
|
|
|
const tableInfo = tables.find((table) => table.tableName === tableName);
|
|
|
|
|
setTableLabel(tableInfo?.displayName || tableName);
|
|
|
|
|
setTableDescription(tableInfo?.description || "");
|
|
|
|
|
|
|
|
|
|
loadColumnTypes(tableName, 1, pageSize);
|
|
|
|
|
},
|
|
|
|
|
[loadColumnTypes, pageSize, tables],
|
|
|
|
|
);
|
2025-08-21 09:41:46 +09:00
|
|
|
|
2025-09-23 10:40:21 +09:00
|
|
|
// 입력 타입 변경
|
|
|
|
|
const handleInputTypeChange = useCallback(
|
|
|
|
|
(columnName: string, newInputType: string) => {
|
2025-09-08 14:20:01 +09:00
|
|
|
setColumns((prev) =>
|
|
|
|
|
prev.map((col) => {
|
|
|
|
|
if (col.columnName === columnName) {
|
2025-09-23 10:40:21 +09:00
|
|
|
const inputTypeOption = memoizedInputTypeOptions.find((option) => option.value === newInputType);
|
2025-09-08 14:20:01 +09:00
|
|
|
return {
|
|
|
|
|
...col,
|
2025-09-23 10:40:21 +09:00
|
|
|
inputType: newInputType,
|
|
|
|
|
detailSettings: inputTypeOption?.description || col.detailSettings,
|
2025-09-08 14:20:01 +09:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
return col;
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
},
|
2025-09-23 10:40:21 +09:00
|
|
|
[memoizedInputTypeOptions],
|
2025-09-08 14:20:01 +09:00
|
|
|
);
|
2025-08-21 09:41:46 +09:00
|
|
|
|
|
|
|
|
// 상세 설정 변경 (코드/엔티티 타입용)
|
2025-09-08 14:20:01 +09:00
|
|
|
const handleDetailSettingsChange = useCallback(
|
|
|
|
|
(columnName: string, settingType: string, value: string) => {
|
|
|
|
|
setColumns((prev) =>
|
|
|
|
|
prev.map((col) => {
|
|
|
|
|
if (col.columnName === columnName) {
|
|
|
|
|
let newDetailSettings = col.detailSettings;
|
|
|
|
|
let codeCategory = col.codeCategory;
|
|
|
|
|
let codeValue = col.codeValue;
|
|
|
|
|
let referenceTable = col.referenceTable;
|
|
|
|
|
let referenceColumn = col.referenceColumn;
|
2025-09-16 15:13:00 +09:00
|
|
|
let displayColumn = col.displayColumn;
|
2025-09-08 14:20:01 +09:00
|
|
|
|
|
|
|
|
if (settingType === "code") {
|
|
|
|
|
if (value === "none") {
|
|
|
|
|
newDetailSettings = "";
|
|
|
|
|
codeCategory = undefined;
|
|
|
|
|
codeValue = undefined;
|
|
|
|
|
} else {
|
|
|
|
|
const codeOption = commonCodeOptions.find((option) => option.value === value);
|
|
|
|
|
newDetailSettings = codeOption ? `공통코드: ${codeOption.label}` : "";
|
|
|
|
|
codeCategory = value;
|
|
|
|
|
codeValue = value;
|
|
|
|
|
}
|
|
|
|
|
} else if (settingType === "entity") {
|
|
|
|
|
if (value === "none") {
|
|
|
|
|
newDetailSettings = "";
|
|
|
|
|
referenceTable = undefined;
|
|
|
|
|
referenceColumn = undefined;
|
2025-09-16 15:13:00 +09:00
|
|
|
displayColumn = undefined;
|
2025-09-08 14:20:01 +09:00
|
|
|
} else {
|
|
|
|
|
const tableOption = referenceTableOptions.find((option) => option.value === value);
|
|
|
|
|
newDetailSettings = tableOption ? `참조테이블: ${tableOption.label}` : "";
|
|
|
|
|
referenceTable = value;
|
2025-09-16 15:13:00 +09:00
|
|
|
// 🎯 참조 컬럼을 소스 컬럼명과 동일하게 설정 (일반적인 경우)
|
|
|
|
|
// 예: user_info.dept_code -> dept_info.dept_code
|
|
|
|
|
referenceColumn = col.columnName;
|
|
|
|
|
// 참조 테이블의 컬럼 정보 로드
|
|
|
|
|
loadReferenceTableColumns(value);
|
2025-09-08 14:20:01 +09:00
|
|
|
}
|
2025-09-16 15:13:00 +09:00
|
|
|
} else if (settingType === "entity_reference_column") {
|
|
|
|
|
// 🎯 Entity 참조 컬럼 변경 (조인할 컬럼)
|
|
|
|
|
referenceColumn = value;
|
|
|
|
|
const tableOption = referenceTableOptions.find((option) => option.value === col.referenceTable);
|
|
|
|
|
newDetailSettings = tableOption ? `참조테이블: ${tableOption.label}` : "";
|
|
|
|
|
} else if (settingType === "entity_display_column") {
|
|
|
|
|
// 🎯 Entity 표시 컬럼 변경
|
|
|
|
|
displayColumn = value;
|
|
|
|
|
const tableOption = referenceTableOptions.find((option) => option.value === col.referenceTable);
|
|
|
|
|
newDetailSettings = tableOption ? `참조테이블: ${tableOption.label} (${value})` : "";
|
2025-08-21 09:41:46 +09:00
|
|
|
}
|
|
|
|
|
|
2025-09-08 14:20:01 +09:00
|
|
|
return {
|
|
|
|
|
...col,
|
|
|
|
|
detailSettings: newDetailSettings,
|
|
|
|
|
codeCategory,
|
|
|
|
|
codeValue,
|
|
|
|
|
referenceTable,
|
|
|
|
|
referenceColumn,
|
2025-09-16 15:13:00 +09:00
|
|
|
displayColumn,
|
2025-09-08 14:20:01 +09:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
return col;
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
},
|
2025-09-16 15:13:00 +09:00
|
|
|
[commonCodeOptions, referenceTableOptions, loadReferenceTableColumns],
|
2025-09-08 14:20:01 +09:00
|
|
|
);
|
2025-08-21 09:41:46 +09:00
|
|
|
|
|
|
|
|
// 라벨 변경 핸들러 추가
|
2025-09-08 14:20:01 +09:00
|
|
|
const handleLabelChange = useCallback((columnName: string, newLabel: string) => {
|
2025-08-21 09:41:46 +09:00
|
|
|
setColumns((prev) =>
|
|
|
|
|
prev.map((col) => {
|
|
|
|
|
if (col.columnName === columnName) {
|
|
|
|
|
return {
|
|
|
|
|
...col,
|
|
|
|
|
displayName: newLabel,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
return col;
|
|
|
|
|
}),
|
|
|
|
|
);
|
2025-09-08 14:20:01 +09:00
|
|
|
}, []);
|
2025-08-21 09:41:46 +09:00
|
|
|
|
2025-08-29 10:09:34 +09:00
|
|
|
// 컬럼 변경 핸들러 (인덱스 기반)
|
2025-09-08 14:20:01 +09:00
|
|
|
const handleColumnChange = useCallback((index: number, field: keyof ColumnTypeInfo, value: any) => {
|
2025-08-29 10:09:34 +09:00
|
|
|
setColumns((prev) =>
|
|
|
|
|
prev.map((col, i) => {
|
|
|
|
|
if (i === index) {
|
|
|
|
|
return {
|
|
|
|
|
...col,
|
|
|
|
|
[field]: value,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
return col;
|
|
|
|
|
}),
|
|
|
|
|
);
|
2025-09-08 14:20:01 +09:00
|
|
|
}, []);
|
2025-08-29 10:09:34 +09:00
|
|
|
|
|
|
|
|
// 개별 컬럼 저장
|
|
|
|
|
const handleSaveColumn = async (column: ColumnTypeInfo) => {
|
|
|
|
|
if (!selectedTable) return;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const columnSetting = {
|
2025-09-01 11:48:12 +09:00
|
|
|
columnName: column.columnName, // 실제 DB 컬럼명 (변경 불가)
|
|
|
|
|
columnLabel: column.displayName, // 사용자가 입력한 표시명
|
2025-09-23 10:40:21 +09:00
|
|
|
inputType: column.inputType || "text",
|
2025-09-01 11:48:12 +09:00
|
|
|
detailSettings: column.detailSettings || "",
|
|
|
|
|
codeCategory: column.codeCategory || "",
|
|
|
|
|
codeValue: column.codeValue || "",
|
|
|
|
|
referenceTable: column.referenceTable || "",
|
|
|
|
|
referenceColumn: column.referenceColumn || "",
|
2025-09-16 15:13:00 +09:00
|
|
|
displayColumn: column.displayColumn || "", // 🎯 Entity 조인에서 표시할 컬럼명
|
2025-08-29 10:09:34 +09:00
|
|
|
};
|
|
|
|
|
|
2025-09-01 11:48:12 +09:00
|
|
|
console.log("저장할 컬럼 설정:", columnSetting);
|
|
|
|
|
|
2025-08-29 10:09:34 +09:00
|
|
|
const response = await apiClient.post(`/table-management/tables/${selectedTable}/columns/settings`, [
|
|
|
|
|
columnSetting,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
if (response.data.success) {
|
|
|
|
|
toast.success("컬럼 설정이 성공적으로 저장되었습니다.");
|
|
|
|
|
// 원본 데이터 업데이트
|
|
|
|
|
setOriginalColumns((prev) => prev.map((col) => (col.columnName === column.columnName ? column : col)));
|
2025-09-01 11:48:12 +09:00
|
|
|
|
|
|
|
|
// 저장 후 데이터 확인을 위해 다시 로드
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
loadColumnTypes(selectedTable);
|
|
|
|
|
}, 1000);
|
2025-08-29 10:09:34 +09:00
|
|
|
} else {
|
|
|
|
|
toast.error(response.data.message || "컬럼 설정 저장에 실패했습니다.");
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error("컬럼 설정 저장 실패:", error);
|
|
|
|
|
toast.error("컬럼 설정 저장 중 오류가 발생했습니다.");
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2025-09-08 14:20:01 +09:00
|
|
|
// 전체 저장 (테이블 라벨 + 모든 컬럼 설정)
|
|
|
|
|
const saveAllSettings = async () => {
|
|
|
|
|
if (!selectedTable) return;
|
2025-08-21 09:41:46 +09:00
|
|
|
|
|
|
|
|
try {
|
2025-09-08 14:20:01 +09:00
|
|
|
// 1. 테이블 라벨 저장 (변경된 경우에만)
|
|
|
|
|
if (tableLabel !== selectedTable || tableDescription) {
|
|
|
|
|
try {
|
|
|
|
|
await apiClient.put(`/table-management/tables/${selectedTable}/label`, {
|
|
|
|
|
displayName: tableLabel,
|
|
|
|
|
description: tableDescription,
|
|
|
|
|
});
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.warn("테이블 라벨 저장 실패 (API 미구현 가능):", error);
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-08-21 09:41:46 +09:00
|
|
|
|
2025-09-08 14:20:01 +09:00
|
|
|
// 2. 모든 컬럼 설정 저장
|
|
|
|
|
if (columns.length > 0) {
|
|
|
|
|
const columnSettings = columns.map((column) => ({
|
|
|
|
|
columnName: column.columnName, // 실제 DB 컬럼명 (변경 불가)
|
|
|
|
|
columnLabel: column.displayName, // 사용자가 입력한 표시명
|
2025-09-23 10:40:21 +09:00
|
|
|
inputType: column.inputType || "text",
|
2025-09-08 14:20:01 +09:00
|
|
|
detailSettings: column.detailSettings || "",
|
|
|
|
|
description: column.description || "",
|
|
|
|
|
codeCategory: column.codeCategory || "",
|
|
|
|
|
codeValue: column.codeValue || "",
|
|
|
|
|
referenceTable: column.referenceTable || "",
|
|
|
|
|
referenceColumn: column.referenceColumn || "",
|
2025-09-16 15:13:00 +09:00
|
|
|
displayColumn: column.displayColumn || "", // 🎯 Entity 조인에서 표시할 컬럼명
|
2025-09-08 14:20:01 +09:00
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
console.log("저장할 전체 설정:", { tableLabel, tableDescription, columnSettings });
|
|
|
|
|
|
|
|
|
|
// 전체 테이블 설정을 한 번에 저장
|
|
|
|
|
const response = await apiClient.post(
|
|
|
|
|
`/table-management/tables/${selectedTable}/columns/settings`,
|
|
|
|
|
columnSettings,
|
|
|
|
|
);
|
2025-09-01 11:48:12 +09:00
|
|
|
|
2025-09-08 14:20:01 +09:00
|
|
|
if (response.data.success) {
|
|
|
|
|
// 저장 성공 후 원본 데이터 업데이트
|
|
|
|
|
setOriginalColumns([...columns]);
|
|
|
|
|
toast.success(`테이블 '${selectedTable}' 설정이 모두 저장되었습니다.`);
|
|
|
|
|
|
|
|
|
|
// 테이블 목록 새로고침 (라벨 변경 반영)
|
|
|
|
|
loadTables();
|
|
|
|
|
|
|
|
|
|
// 저장 후 데이터 확인을 위해 다시 로드
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
loadColumnTypes(selectedTable, 1, pageSize);
|
|
|
|
|
}, 1000);
|
|
|
|
|
} else {
|
|
|
|
|
toast.error(response.data.message || "설정 저장에 실패했습니다.");
|
|
|
|
|
}
|
2025-08-21 09:41:46 +09:00
|
|
|
}
|
|
|
|
|
} catch (error) {
|
2025-09-08 14:20:01 +09:00
|
|
|
console.error("설정 저장 실패:", error);
|
|
|
|
|
toast.error("설정 저장 중 오류가 발생했습니다.");
|
2025-08-21 09:41:46 +09:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2025-09-08 14:20:01 +09:00
|
|
|
// 필터링된 테이블 목록 (메모이제이션)
|
|
|
|
|
const filteredTables = useMemo(
|
|
|
|
|
() =>
|
|
|
|
|
tables.filter(
|
|
|
|
|
(table) =>
|
|
|
|
|
table.tableName.toLowerCase().includes(searchTerm.toLowerCase()) ||
|
|
|
|
|
table.displayName.toLowerCase().includes(searchTerm.toLowerCase()),
|
|
|
|
|
),
|
|
|
|
|
[tables, searchTerm],
|
2025-08-21 09:41:46 +09:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// 선택된 테이블 정보
|
|
|
|
|
const selectedTableInfo = tables.find((table) => table.tableName === selectedTable);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
loadTables();
|
2025-09-15 15:38:48 +09:00
|
|
|
loadCommonCodeCategories();
|
2025-08-21 09:41:46 +09:00
|
|
|
}, []);
|
|
|
|
|
|
2025-09-16 15:13:00 +09:00
|
|
|
// 🎯 컬럼 로드 후 이미 설정된 참조 테이블들의 컬럼 정보 로드
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (columns.length > 0) {
|
|
|
|
|
const entityColumns = columns.filter(
|
|
|
|
|
(col) => col.webType === "entity" && col.referenceTable && col.referenceTable !== "none",
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
entityColumns.forEach((col) => {
|
|
|
|
|
if (col.referenceTable) {
|
|
|
|
|
console.log(`🎯 기존 Entity 컬럼 발견, 참조 테이블 컬럼 로드: ${col.columnName} -> ${col.referenceTable}`);
|
|
|
|
|
loadReferenceTableColumns(col.referenceTable);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}, [columns, loadReferenceTableColumns]);
|
|
|
|
|
|
2025-09-08 14:20:01 +09:00
|
|
|
// 더 많은 데이터 로드
|
|
|
|
|
const loadMoreColumns = useCallback(() => {
|
|
|
|
|
if (selectedTable && columns.length < totalColumns && !columnsLoading) {
|
|
|
|
|
const nextPage = Math.floor(columns.length / pageSize) + 1;
|
|
|
|
|
loadColumnTypes(selectedTable, nextPage, pageSize);
|
|
|
|
|
}
|
|
|
|
|
}, [selectedTable, columns.length, totalColumns, columnsLoading, pageSize, loadColumnTypes]);
|
|
|
|
|
|
2025-08-21 09:41:46 +09:00
|
|
|
return (
|
2025-09-30 18:28:54 +09:00
|
|
|
<div className="w-full max-w-none space-y-8 px-4 py-8">
|
2025-08-29 10:09:34 +09:00
|
|
|
{/* 페이지 제목 */}
|
2025-09-30 18:28:54 +09:00
|
|
|
<div className="flex items-center justify-between rounded-lg border bg-white p-6 shadow-sm">
|
2025-08-21 09:41:46 +09:00
|
|
|
<div>
|
2025-08-29 10:09:34 +09:00
|
|
|
<h1 className="text-3xl font-bold text-gray-900">
|
|
|
|
|
{getTextFromUI(TABLE_MANAGEMENT_KEYS.PAGE_TITLE, "테이블 타입 관리")}
|
|
|
|
|
</h1>
|
|
|
|
|
<p className="mt-2 text-gray-600">
|
|
|
|
|
{getTextFromUI(TABLE_MANAGEMENT_KEYS.PAGE_DESCRIPTION, "데이터베이스 테이블과 컬럼의 타입을 관리합니다")}
|
|
|
|
|
</p>
|
2025-09-22 17:00:59 +09:00
|
|
|
{isSuperAdmin && (
|
|
|
|
|
<p className="mt-1 text-sm font-medium text-blue-600">
|
|
|
|
|
🔧 최고 관리자 권한으로 새 테이블 생성 및 컬럼 추가가 가능합니다
|
|
|
|
|
</p>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
{/* DDL 기능 버튼들 (최고 관리자만) */}
|
|
|
|
|
{isSuperAdmin && (
|
|
|
|
|
<>
|
|
|
|
|
<Button
|
|
|
|
|
onClick={() => setCreateTableModalOpen(true)}
|
|
|
|
|
className="bg-green-600 text-white hover:bg-green-700"
|
|
|
|
|
size="sm"
|
|
|
|
|
>
|
|
|
|
|
<Plus className="mr-2 h-4 w-4" />새 테이블 생성
|
|
|
|
|
</Button>
|
|
|
|
|
|
|
|
|
|
{selectedTable && (
|
|
|
|
|
<Button onClick={() => setAddColumnModalOpen(true)} variant="outline" size="sm">
|
|
|
|
|
<Plus className="mr-2 h-4 w-4" />
|
|
|
|
|
컬럼 추가
|
|
|
|
|
</Button>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
<Button onClick={() => setDdlLogViewerOpen(true)} variant="outline" size="sm">
|
|
|
|
|
<Activity className="mr-2 h-4 w-4" />
|
|
|
|
|
DDL 로그
|
|
|
|
|
</Button>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
<Button onClick={loadTables} disabled={loading} className="flex items-center gap-2" size="sm">
|
|
|
|
|
<RefreshCw className={`h-4 w-4 ${loading ? "animate-spin" : ""}`} />
|
|
|
|
|
{getTextFromUI(TABLE_MANAGEMENT_KEYS.BUTTON_REFRESH, "새로고침")}
|
|
|
|
|
</Button>
|
2025-08-21 09:41:46 +09:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
2025-09-16 15:13:00 +09:00
|
|
|
<div className="grid grid-cols-1 gap-6 lg:grid-cols-5">
|
2025-08-29 10:09:34 +09:00
|
|
|
{/* 테이블 목록 */}
|
2025-09-30 18:28:54 +09:00
|
|
|
<Card className="shadow-sm lg:col-span-1">
|
2025-09-25 09:29:56 +09:00
|
|
|
<CardHeader className="bg-gray-50/50">
|
2025-08-29 10:09:34 +09:00
|
|
|
<CardTitle className="flex items-center gap-2">
|
2025-09-25 09:29:56 +09:00
|
|
|
<Database className="h-5 w-5 text-gray-600" />
|
2025-08-29 10:09:34 +09:00
|
|
|
{getTextFromUI(TABLE_MANAGEMENT_KEYS.TABLE_NAME, "테이블 목록")}
|
|
|
|
|
</CardTitle>
|
|
|
|
|
</CardHeader>
|
|
|
|
|
<CardContent>
|
|
|
|
|
{/* 검색 */}
|
|
|
|
|
<div className="mb-4">
|
|
|
|
|
<div className="relative">
|
|
|
|
|
<Search className="absolute top-1/2 left-3 h-4 w-4 -translate-y-1/2 transform text-gray-400" />
|
|
|
|
|
<Input
|
|
|
|
|
placeholder={getTextFromUI(TABLE_MANAGEMENT_KEYS.SEARCH_PLACEHOLDER, "테이블 검색...")}
|
|
|
|
|
value={searchTerm}
|
|
|
|
|
onChange={(e) => setSearchTerm(e.target.value)}
|
|
|
|
|
className="pl-10"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* 테이블 목록 */}
|
|
|
|
|
<div className="max-h-96 space-y-2 overflow-y-auto">
|
2025-08-21 09:41:46 +09:00
|
|
|
{loading ? (
|
2025-08-29 10:09:34 +09:00
|
|
|
<div className="flex items-center justify-center py-8">
|
2025-08-21 09:41:46 +09:00
|
|
|
<LoadingSpinner />
|
2025-08-29 10:09:34 +09:00
|
|
|
<span className="ml-2 text-sm text-gray-500">
|
|
|
|
|
{getTextFromUI(TABLE_MANAGEMENT_KEYS.MESSAGE_LOADING_TABLES, "테이블 로딩 중...")}
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
) : tables.length === 0 ? (
|
|
|
|
|
<div className="py-8 text-center text-gray-500">
|
|
|
|
|
{getTextFromUI(TABLE_MANAGEMENT_KEYS.MESSAGE_NO_TABLES, "테이블이 없습니다")}
|
2025-08-21 09:41:46 +09:00
|
|
|
</div>
|
|
|
|
|
) : (
|
2025-08-29 10:09:34 +09:00
|
|
|
tables
|
|
|
|
|
.filter(
|
|
|
|
|
(table) =>
|
|
|
|
|
table.tableName.toLowerCase().includes(searchTerm.toLowerCase()) ||
|
|
|
|
|
(table.displayName && table.displayName.toLowerCase().includes(searchTerm.toLowerCase())),
|
|
|
|
|
)
|
|
|
|
|
.map((table) => (
|
|
|
|
|
<div
|
|
|
|
|
key={table.tableName}
|
|
|
|
|
className={`cursor-pointer rounded-lg border p-3 transition-colors ${
|
|
|
|
|
selectedTable === table.tableName
|
|
|
|
|
? "border-blue-500 bg-blue-50"
|
|
|
|
|
: "border-gray-200 hover:border-gray-300"
|
|
|
|
|
}`}
|
|
|
|
|
onClick={() => handleTableSelect(table.tableName)}
|
|
|
|
|
>
|
|
|
|
|
<div className="flex items-center justify-between">
|
|
|
|
|
<div>
|
|
|
|
|
<h3 className="font-medium text-gray-900">{table.displayName || table.tableName}</h3>
|
|
|
|
|
<p className="text-sm text-gray-500">
|
|
|
|
|
{table.description || getTextFromUI(TABLE_MANAGEMENT_KEYS.TABLE_DESCRIPTION, "설명 없음")}
|
|
|
|
|
</p>
|
2025-08-21 09:41:46 +09:00
|
|
|
</div>
|
2025-08-29 10:09:34 +09:00
|
|
|
<Badge variant="secondary">
|
|
|
|
|
{table.columnCount} {getTextFromUI(TABLE_MANAGEMENT_KEYS.TABLE_COLUMN_COUNT, "컬럼")}
|
|
|
|
|
</Badge>
|
2025-08-21 09:41:46 +09:00
|
|
|
</div>
|
2025-08-29 10:09:34 +09:00
|
|
|
</div>
|
|
|
|
|
))
|
2025-08-21 09:41:46 +09:00
|
|
|
)}
|
2025-08-29 10:09:34 +09:00
|
|
|
</div>
|
|
|
|
|
</CardContent>
|
|
|
|
|
</Card>
|
|
|
|
|
|
|
|
|
|
{/* 컬럼 타입 관리 */}
|
2025-09-30 18:28:54 +09:00
|
|
|
<Card className="shadow-sm lg:col-span-4">
|
2025-09-25 09:29:56 +09:00
|
|
|
<CardHeader className="bg-gray-50/50">
|
2025-08-29 10:09:34 +09:00
|
|
|
<CardTitle className="flex items-center gap-2">
|
2025-09-25 09:29:56 +09:00
|
|
|
<Settings className="h-5 w-5 text-gray-600" />
|
2025-09-08 14:20:01 +09:00
|
|
|
{selectedTable ? <>테이블 설정 - {selectedTable}</> : "테이블 타입 관리"}
|
2025-08-29 10:09:34 +09:00
|
|
|
</CardTitle>
|
|
|
|
|
</CardHeader>
|
|
|
|
|
<CardContent>
|
|
|
|
|
{!selectedTable ? (
|
|
|
|
|
<div className="py-12 text-center text-gray-500">
|
|
|
|
|
{getTextFromUI(TABLE_MANAGEMENT_KEYS.SELECT_TABLE_PLACEHOLDER, "테이블을 선택해주세요")}
|
|
|
|
|
</div>
|
|
|
|
|
) : (
|
|
|
|
|
<>
|
2025-09-08 14:20:01 +09:00
|
|
|
{/* 테이블 라벨 설정 */}
|
|
|
|
|
<div className="mb-6 space-y-4 rounded-lg border border-gray-200 p-4">
|
|
|
|
|
<h3 className="text-lg font-medium text-gray-900">테이블 정보</h3>
|
|
|
|
|
<div className="grid grid-cols-1 gap-4 md:grid-cols-2">
|
|
|
|
|
<div>
|
|
|
|
|
<label className="mb-1 block text-sm font-medium text-gray-700">테이블명 (읽기 전용)</label>
|
|
|
|
|
<Input value={selectedTable} disabled className="bg-gray-50" />
|
|
|
|
|
</div>
|
|
|
|
|
<div>
|
|
|
|
|
<label className="mb-1 block text-sm font-medium text-gray-700">표시명</label>
|
|
|
|
|
<Input
|
|
|
|
|
value={tableLabel}
|
|
|
|
|
onChange={(e) => setTableLabel(e.target.value)}
|
|
|
|
|
placeholder="테이블 표시명을 입력하세요"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="md:col-span-2">
|
|
|
|
|
<label className="mb-1 block text-sm font-medium text-gray-700">설명</label>
|
|
|
|
|
<Input
|
|
|
|
|
value={tableDescription}
|
|
|
|
|
onChange={(e) => setTableDescription(e.target.value)}
|
|
|
|
|
placeholder="테이블 설명을 입력하세요"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
2025-08-29 10:09:34 +09:00
|
|
|
{columnsLoading ? (
|
|
|
|
|
<div className="flex items-center justify-center py-8">
|
|
|
|
|
<LoadingSpinner />
|
|
|
|
|
<span className="ml-2 text-sm text-gray-500">
|
|
|
|
|
{getTextFromUI(TABLE_MANAGEMENT_KEYS.MESSAGE_LOADING_COLUMNS, "컬럼 정보 로딩 중...")}
|
2025-08-21 09:41:46 +09:00
|
|
|
</span>
|
|
|
|
|
</div>
|
2025-08-29 10:09:34 +09:00
|
|
|
) : columns.length === 0 ? (
|
|
|
|
|
<div className="py-8 text-center text-gray-500">
|
|
|
|
|
{getTextFromUI(TABLE_MANAGEMENT_KEYS.MESSAGE_NO_COLUMNS, "컬럼이 없습니다")}
|
|
|
|
|
</div>
|
2025-08-21 09:41:46 +09:00
|
|
|
) : (
|
2025-09-08 14:20:01 +09:00
|
|
|
<div className="space-y-4">
|
|
|
|
|
{/* 컬럼 헤더 */}
|
|
|
|
|
<div className="flex items-center border-b border-gray-200 pb-2 text-sm font-medium text-gray-700">
|
|
|
|
|
<div className="w-40 px-4">컬럼명</div>
|
|
|
|
|
<div className="w-48 px-4">라벨</div>
|
2025-09-23 10:40:21 +09:00
|
|
|
<div className="w-48 px-4">입력 타입</div>
|
2025-09-16 15:13:00 +09:00
|
|
|
<div className="flex-1 px-4" style={{ maxWidth: "calc(100% - 808px)" }}>
|
|
|
|
|
상세 설정
|
|
|
|
|
</div>
|
|
|
|
|
<div className="w-80 px-4">설명</div>
|
2025-09-08 14:20:01 +09:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* 컬럼 리스트 */}
|
|
|
|
|
<div
|
|
|
|
|
className="max-h-96 overflow-y-auto rounded-lg border border-gray-200"
|
|
|
|
|
onScroll={(e) => {
|
|
|
|
|
const { scrollTop, scrollHeight, clientHeight } = e.currentTarget;
|
|
|
|
|
// 스크롤이 끝에 가까워지면 더 많은 데이터 로드
|
|
|
|
|
if (scrollHeight - scrollTop <= clientHeight + 100) {
|
|
|
|
|
loadMoreColumns();
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{columns.map((column, index) => (
|
|
|
|
|
<div
|
|
|
|
|
key={column.columnName}
|
2025-09-16 15:13:00 +09:00
|
|
|
className="flex items-center border-b border-gray-200 py-2 hover:bg-gray-50"
|
2025-09-08 14:20:01 +09:00
|
|
|
>
|
|
|
|
|
<div className="w-40 px-4">
|
|
|
|
|
<div className="font-mono text-sm text-gray-700">{column.columnName}</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="w-48 px-4">
|
|
|
|
|
<Input
|
|
|
|
|
value={column.displayName || ""}
|
|
|
|
|
onChange={(e) => handleLabelChange(column.columnName, e.target.value)}
|
|
|
|
|
placeholder={column.columnName}
|
2025-09-16 15:13:00 +09:00
|
|
|
className="h-7 text-xs"
|
2025-09-08 14:20:01 +09:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="w-48 px-4">
|
|
|
|
|
<Select
|
2025-09-23 10:40:21 +09:00
|
|
|
value={column.inputType || "text"}
|
|
|
|
|
onValueChange={(value) => handleInputTypeChange(column.columnName, value)}
|
2025-09-08 14:20:01 +09:00
|
|
|
>
|
2025-09-16 15:13:00 +09:00
|
|
|
<SelectTrigger className="h-7 text-xs">
|
2025-09-23 10:40:21 +09:00
|
|
|
<SelectValue placeholder="입력 타입 선택" />
|
2025-09-08 14:20:01 +09:00
|
|
|
</SelectTrigger>
|
|
|
|
|
<SelectContent>
|
2025-09-23 10:40:21 +09:00
|
|
|
{memoizedInputTypeOptions.map((option) => (
|
2025-09-08 14:20:01 +09:00
|
|
|
<SelectItem key={option.value} value={option.value}>
|
|
|
|
|
{option.label}
|
|
|
|
|
</SelectItem>
|
|
|
|
|
))}
|
|
|
|
|
</SelectContent>
|
|
|
|
|
</Select>
|
|
|
|
|
</div>
|
2025-09-16 15:13:00 +09:00
|
|
|
<div className="flex-1 px-4" style={{ maxWidth: "calc(100% - 808px)" }}>
|
2025-09-15 15:38:48 +09:00
|
|
|
{/* 웹 타입이 'code'인 경우 공통코드 선택 */}
|
2025-09-23 10:40:21 +09:00
|
|
|
{column.inputType === "code" && (
|
2025-09-15 15:38:48 +09:00
|
|
|
<Select
|
|
|
|
|
value={column.codeCategory || "none"}
|
|
|
|
|
onValueChange={(value) => handleDetailSettingsChange(column.columnName, "code", value)}
|
|
|
|
|
>
|
2025-09-16 15:13:00 +09:00
|
|
|
<SelectTrigger className="h-7 text-xs">
|
2025-09-15 15:38:48 +09:00
|
|
|
<SelectValue placeholder="공통코드 선택" />
|
|
|
|
|
</SelectTrigger>
|
|
|
|
|
<SelectContent>
|
|
|
|
|
{commonCodeOptions.map((option, index) => (
|
|
|
|
|
<SelectItem key={`code-${option.value}-${index}`} value={option.value}>
|
|
|
|
|
{option.label}
|
|
|
|
|
</SelectItem>
|
|
|
|
|
))}
|
|
|
|
|
</SelectContent>
|
|
|
|
|
</Select>
|
|
|
|
|
)}
|
|
|
|
|
{/* 웹 타입이 'entity'인 경우 참조 테이블 선택 */}
|
2025-09-23 10:40:21 +09:00
|
|
|
{column.inputType === "entity" && (
|
2025-09-16 15:13:00 +09:00
|
|
|
<div className="space-y-1">
|
|
|
|
|
{/* 🎯 Entity 타입 설정 - 가로 배치 */}
|
|
|
|
|
<div className="rounded-lg border border-blue-200 bg-blue-50 p-2">
|
|
|
|
|
<div className="mb-2 flex items-center gap-2">
|
|
|
|
|
<span className="text-xs font-medium text-blue-800">Entity 설정</span>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="grid grid-cols-3 gap-2">
|
|
|
|
|
{/* 참조 테이블 */}
|
|
|
|
|
<div>
|
|
|
|
|
<label className="mb-1 block text-xs text-gray-600">참조 테이블</label>
|
|
|
|
|
<Select
|
|
|
|
|
value={column.referenceTable || "none"}
|
|
|
|
|
onValueChange={(value) =>
|
|
|
|
|
handleDetailSettingsChange(column.columnName, "entity", value)
|
|
|
|
|
}
|
|
|
|
|
>
|
|
|
|
|
<SelectTrigger className="h-7 bg-white text-xs">
|
|
|
|
|
<SelectValue placeholder="선택" />
|
|
|
|
|
</SelectTrigger>
|
|
|
|
|
<SelectContent>
|
|
|
|
|
{referenceTableOptions.map((option, index) => (
|
|
|
|
|
<SelectItem key={`entity-${option.value}-${index}`} value={option.value}>
|
|
|
|
|
<div className="flex flex-col">
|
|
|
|
|
<span className="font-medium">{option.label}</span>
|
|
|
|
|
<span className="text-xs text-gray-500">{option.value}</span>
|
|
|
|
|
</div>
|
|
|
|
|
</SelectItem>
|
|
|
|
|
))}
|
|
|
|
|
</SelectContent>
|
|
|
|
|
</Select>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* 조인 컬럼 */}
|
|
|
|
|
{column.referenceTable && column.referenceTable !== "none" && (
|
|
|
|
|
<div>
|
|
|
|
|
<label className="mb-1 block text-xs text-gray-600">조인 컬럼</label>
|
|
|
|
|
<Select
|
|
|
|
|
value={column.referenceColumn || "none"}
|
|
|
|
|
onValueChange={(value) =>
|
|
|
|
|
handleDetailSettingsChange(
|
|
|
|
|
column.columnName,
|
|
|
|
|
"entity_reference_column",
|
|
|
|
|
value,
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
>
|
|
|
|
|
<SelectTrigger className="h-7 bg-white text-xs">
|
|
|
|
|
<SelectValue placeholder="선택" />
|
|
|
|
|
</SelectTrigger>
|
|
|
|
|
<SelectContent>
|
|
|
|
|
<SelectItem value="none">-- 선택 안함 --</SelectItem>
|
|
|
|
|
{referenceTableColumns[column.referenceTable]?.map((refCol, index) => (
|
|
|
|
|
<SelectItem
|
|
|
|
|
key={`ref-col-${refCol.columnName}-${index}`}
|
|
|
|
|
value={refCol.columnName}
|
|
|
|
|
>
|
|
|
|
|
<span className="font-medium">{refCol.columnName}</span>
|
|
|
|
|
</SelectItem>
|
|
|
|
|
))}
|
|
|
|
|
{(!referenceTableColumns[column.referenceTable] ||
|
|
|
|
|
referenceTableColumns[column.referenceTable].length === 0) && (
|
|
|
|
|
<SelectItem value="loading" disabled>
|
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
<div className="h-3 w-3 animate-spin rounded-full border border-blue-500 border-t-transparent"></div>
|
|
|
|
|
로딩중
|
|
|
|
|
</div>
|
|
|
|
|
</SelectItem>
|
|
|
|
|
)}
|
|
|
|
|
</SelectContent>
|
|
|
|
|
</Select>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* 설정 완료 표시 - 간소화 */}
|
|
|
|
|
{column.referenceTable &&
|
|
|
|
|
column.referenceTable !== "none" &&
|
|
|
|
|
column.referenceColumn &&
|
|
|
|
|
column.referenceColumn !== "none" &&
|
|
|
|
|
column.displayColumn &&
|
|
|
|
|
column.displayColumn !== "none" && (
|
|
|
|
|
<div className="mt-1 flex items-center gap-1 rounded bg-green-100 px-2 py-1 text-xs text-green-700">
|
|
|
|
|
<span className="text-green-600">✓</span>
|
|
|
|
|
<span className="truncate">
|
|
|
|
|
{column.columnName} → {column.referenceTable}.{column.displayColumn}
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2025-09-15 15:38:48 +09:00
|
|
|
)}
|
|
|
|
|
{/* 다른 웹 타입인 경우 빈 공간 */}
|
2025-09-23 10:40:21 +09:00
|
|
|
{column.inputType !== "code" && column.inputType !== "entity" && (
|
2025-09-16 15:13:00 +09:00
|
|
|
<div className="flex h-7 items-center text-xs text-gray-400">-</div>
|
2025-09-15 15:38:48 +09:00
|
|
|
)}
|
|
|
|
|
</div>
|
2025-09-16 15:13:00 +09:00
|
|
|
<div className="w-80 px-4">
|
2025-09-08 14:20:01 +09:00
|
|
|
<Input
|
|
|
|
|
value={column.description || ""}
|
|
|
|
|
onChange={(e) => handleColumnChange(index, "description", e.target.value)}
|
|
|
|
|
placeholder="설명"
|
2025-09-16 15:13:00 +09:00
|
|
|
className="h-7 text-xs"
|
2025-09-08 14:20:01 +09:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* 로딩 표시 */}
|
|
|
|
|
{columnsLoading && (
|
|
|
|
|
<div className="flex items-center justify-center py-4">
|
|
|
|
|
<LoadingSpinner />
|
|
|
|
|
<span className="ml-2 text-sm text-gray-500">더 많은 컬럼 로딩 중...</span>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{/* 페이지 정보 */}
|
|
|
|
|
<div className="text-center text-sm text-gray-500">
|
|
|
|
|
{columns.length} / {totalColumns} 컬럼 표시됨
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* 전체 저장 버튼 */}
|
|
|
|
|
<div className="flex justify-end pt-4">
|
|
|
|
|
<Button
|
|
|
|
|
onClick={saveAllSettings}
|
|
|
|
|
disabled={!selectedTable || columns.length === 0}
|
|
|
|
|
className="flex items-center gap-2"
|
|
|
|
|
>
|
|
|
|
|
<Settings className="h-4 w-4" />
|
|
|
|
|
전체 설정 저장
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
2025-08-21 09:41:46 +09:00
|
|
|
</div>
|
2025-08-29 10:09:34 +09:00
|
|
|
)}
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
</CardContent>
|
|
|
|
|
</Card>
|
2025-08-21 09:41:46 +09:00
|
|
|
</div>
|
2025-09-22 17:00:59 +09:00
|
|
|
|
|
|
|
|
{/* DDL 모달 컴포넌트들 */}
|
|
|
|
|
{isSuperAdmin && (
|
|
|
|
|
<>
|
|
|
|
|
<CreateTableModal
|
|
|
|
|
isOpen={createTableModalOpen}
|
|
|
|
|
onClose={() => setCreateTableModalOpen(false)}
|
|
|
|
|
onSuccess={async (result) => {
|
|
|
|
|
toast.success("테이블이 성공적으로 생성되었습니다!");
|
|
|
|
|
// 테이블 목록 새로고침
|
|
|
|
|
await loadTables();
|
|
|
|
|
// 새로 생성된 테이블 자동 선택 및 컬럼 로드
|
|
|
|
|
if (result.data?.tableName) {
|
|
|
|
|
setSelectedTable(result.data.tableName);
|
|
|
|
|
setCurrentPage(1);
|
|
|
|
|
setColumns([]);
|
|
|
|
|
await loadColumnTypes(result.data.tableName, 1, pageSize);
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
<AddColumnModal
|
|
|
|
|
isOpen={addColumnModalOpen}
|
|
|
|
|
onClose={() => setAddColumnModalOpen(false)}
|
|
|
|
|
tableName={selectedTable || ""}
|
|
|
|
|
onSuccess={async (result) => {
|
|
|
|
|
toast.success("컬럼이 성공적으로 추가되었습니다!");
|
|
|
|
|
// 테이블 목록 새로고침 (컬럼 수 업데이트)
|
|
|
|
|
await loadTables();
|
|
|
|
|
// 선택된 테이블의 컬럼 목록 새로고침 - 페이지 리셋
|
|
|
|
|
if (selectedTable) {
|
|
|
|
|
setCurrentPage(1);
|
|
|
|
|
setColumns([]); // 기존 컬럼 목록 초기화
|
|
|
|
|
await loadColumnTypes(selectedTable, 1, pageSize);
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
<DDLLogViewer isOpen={ddlLogViewerOpen} onClose={() => setDdlLogViewerOpen(false)} />
|
|
|
|
|
</>
|
|
|
|
|
)}
|
2025-08-21 09:41:46 +09:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|