ERP-node/frontend/components/dataflow/connection/redesigned/RightPanel/TableStep.tsx

205 lines
7.7 KiB
TypeScript
Raw Normal View History

"use client";
2025-10-01 16:15:53 +09:00
import React, { useState } from "react";
import { Table, ArrowLeft, ArrowRight, CheckCircle, Database } from "lucide-react";
import { Connection, TableInfo } from "../types/redesigned";
interface TableStepProps {
fromConnection?: Connection;
toConnection?: Connection;
fromTable?: TableInfo;
toTable?: TableInfo;
2025-10-01 16:15:53 +09:00
onFromTableChange: (table: TableInfo) => void;
onToTableChange: (table: TableInfo) => void;
onNext: () => void;
onBack: () => void;
}
2025-10-01 16:15:53 +09:00
// 임시 테이블 데이터
const mockTables: TableInfo[] = [
{
name: "users",
schema: "public",
columns: [
{ name: "id", type: "integer", nullable: false, primaryKey: true },
{ name: "name", type: "varchar", nullable: false, primaryKey: false },
{ name: "email", type: "varchar", nullable: true, primaryKey: false },
{ name: "created_at", type: "timestamp", nullable: false, primaryKey: false },
2025-10-01 16:15:53 +09:00
],
rowCount: 1250,
2025-10-01 16:15:53 +09:00
},
{
name: "orders",
schema: "public",
2025-10-01 16:15:53 +09:00
columns: [
{ name: "id", type: "integer", nullable: false, primaryKey: true },
{ name: "user_id", type: "integer", nullable: false, primaryKey: false, foreignKey: true },
{ name: "product_name", type: "varchar", nullable: false, primaryKey: false },
{ name: "amount", type: "decimal", nullable: false, primaryKey: false },
{ name: "order_date", type: "timestamp", nullable: false, primaryKey: false },
2025-10-01 16:15:53 +09:00
],
rowCount: 3420,
2025-10-01 16:15:53 +09:00
},
{
name: "products",
schema: "public",
columns: [
{ name: "id", type: "integer", nullable: false, primaryKey: true },
{ name: "name", type: "varchar", nullable: false, primaryKey: false },
{ name: "price", type: "decimal", nullable: false, primaryKey: false },
{ name: "category", type: "varchar", nullable: true, primaryKey: false },
2025-10-01 16:15:53 +09:00
],
rowCount: 156,
},
2025-10-01 16:15:53 +09:00
];
export const TableStep: React.FC<TableStepProps> = ({
fromConnection,
toConnection,
fromTable,
toTable,
2025-10-01 16:15:53 +09:00
onFromTableChange,
onToTableChange,
onNext,
onBack,
}) => {
2025-10-01 16:15:53 +09:00
const [selectedFromTable, setSelectedFromTable] = useState<string>(fromTable?.name || "");
const [selectedToTable, setSelectedToTable] = useState<string>(toTable?.name || "");
2025-10-01 16:15:53 +09:00
const handleFromTableSelect = (tableName: string) => {
const table = mockTables.find((t) => t.name === tableName);
2025-10-01 16:15:53 +09:00
if (table) {
setSelectedFromTable(tableName);
onFromTableChange(table);
}
2025-10-01 16:15:53 +09:00
};
2025-10-01 16:15:53 +09:00
const handleToTableSelect = (tableName: string) => {
const table = mockTables.find((t) => t.name === tableName);
if (table) {
2025-10-01 16:15:53 +09:00
setSelectedToTable(tableName);
onToTableChange(table);
}
};
2025-10-01 16:15:53 +09:00
const canProceed = selectedFromTable && selectedToTable;
return (
2025-10-01 16:15:53 +09:00
<div className="space-y-8">
<div className="text-center">
<h2 className="mb-2 text-2xl font-bold text-gray-900"> </h2>
<p className="text-muted-foreground"> </p>
2025-10-01 16:15:53 +09:00
</div>
2025-10-01 16:15:53 +09:00
{/* 연결 정보 표시 */}
<div className="rounded-lg bg-gray-50 p-4">
2025-10-01 16:15:53 +09:00
<div className="flex items-center justify-between">
<div className="flex items-center gap-3">
<Database className="text-primary h-5 w-5" />
2025-10-01 16:15:53 +09:00
<span className="font-medium text-gray-900">{fromConnection?.name}</span>
<span className="text-sm text-gray-500"></span>
<Database className="h-5 w-5 text-green-600" />
2025-10-01 16:15:53 +09:00
<span className="font-medium text-gray-900">{toConnection?.name}</span>
</div>
</div>
2025-10-01 16:15:53 +09:00
</div>
<div className="grid grid-cols-1 gap-8 lg:grid-cols-2">
2025-10-01 16:15:53 +09:00
{/* FROM 테이블 */}
<div className="space-y-4">
<div className="flex items-center gap-2">
<div className="bg-primary/20 flex h-8 w-8 items-center justify-center rounded-full">
<span className="text-primary font-bold">1</span>
</div>
2025-10-01 16:15:53 +09:00
<h3 className="text-lg font-semibold text-gray-900"> </h3>
<span className="text-sm text-gray-500">(FROM)</span>
</div>
2025-10-01 16:15:53 +09:00
<div className="space-y-2">
{mockTables.map((table) => (
<div
key={table.name}
className={`cursor-pointer rounded-lg border-2 p-4 transition-all duration-200 ${
2025-10-01 16:15:53 +09:00
selectedFromTable === table.name
? "border-primary bg-accent shadow-md"
: "hover:bg-blue-25 border-gray-200 bg-white hover:border-blue-300"
2025-10-01 16:15:53 +09:00
}`}
onClick={() => handleFromTableSelect(table.name)}
>
<div className="flex items-center gap-3">
<Table className="text-primary h-6 w-6" />
2025-10-01 16:15:53 +09:00
<div className="flex-1">
<h4 className="font-medium text-gray-900">{table.name}</h4>
<p className="text-muted-foreground text-sm">{table.columns.length} </p>
2025-10-01 16:15:53 +09:00
<p className="text-xs text-gray-500">{table.rowCount?.toLocaleString()} </p>
</div>
{selectedFromTable === table.name && <CheckCircle className="text-primary h-5 w-5" />}
</div>
</div>
2025-10-01 16:15:53 +09:00
))}
</div>
</div>
2025-10-01 16:15:53 +09:00
{/* TO 테이블 */}
<div className="space-y-4">
<div className="flex items-center gap-2">
<div className="flex h-8 w-8 items-center justify-center rounded-full bg-green-100">
<span className="font-bold text-green-600">2</span>
2025-10-01 16:15:53 +09:00
</div>
<h3 className="text-lg font-semibold text-gray-900"> </h3>
<span className="text-sm text-gray-500">(TO)</span>
</div>
2025-10-01 16:15:53 +09:00
<div className="space-y-2">
{mockTables.map((table) => (
<div
key={table.name}
className={`cursor-pointer rounded-lg border-2 p-4 transition-all duration-200 ${
2025-10-01 16:15:53 +09:00
selectedToTable === table.name
? "border-green-500 bg-green-50 shadow-md"
: "hover:bg-green-25 border-gray-200 bg-white hover:border-green-300"
2025-10-01 16:15:53 +09:00
}`}
onClick={() => handleToTableSelect(table.name)}
>
<div className="flex items-center gap-3">
<Table className="h-6 w-6 text-green-600" />
2025-10-01 16:15:53 +09:00
<div className="flex-1">
<h4 className="font-medium text-gray-900">{table.name}</h4>
<p className="text-muted-foreground text-sm">{table.columns.length} </p>
2025-10-01 16:15:53 +09:00
<p className="text-xs text-gray-500">{table.rowCount?.toLocaleString()} </p>
</div>
{selectedToTable === table.name && <CheckCircle className="h-5 w-5 text-green-600" />}
</div>
</div>
2025-10-01 16:15:53 +09:00
))}
</div>
</div>
2025-10-01 16:15:53 +09:00
</div>
2025-10-01 16:15:53 +09:00
{/* 버튼들 */}
<div className="flex justify-between">
<button
onClick={onBack}
className="text-muted-foreground flex items-center gap-2 rounded-lg bg-gray-100 px-6 py-3 font-medium transition-all duration-200 hover:bg-gray-200"
2025-10-01 16:15:53 +09:00
>
<ArrowLeft className="h-4 w-4" />
2025-10-01 16:15:53 +09:00
</button>
2025-10-01 16:15:53 +09:00
<button
onClick={onNext}
disabled={!canProceed}
className={`flex items-center gap-2 rounded-lg px-6 py-3 font-medium transition-all duration-200 ${
2025-10-01 16:15:53 +09:00
canProceed
? "bg-orange-500 text-white shadow-md hover:bg-orange-600 hover:shadow-lg"
: "cursor-not-allowed bg-gray-300 text-gray-500"
2025-10-01 16:15:53 +09:00
}`}
>
단계: 필드
<ArrowRight className="h-4 w-4" />
2025-10-01 16:15:53 +09:00
</button>
</div>
</div>
);
};