ERP-node/frontend/components/dataflow/node-editor/panels/PropertiesPanel.tsx

151 lines
5.5 KiB
TypeScript
Raw Normal View History

feat: 노드 기반 데이터 플로우 시스템 구현 - 노드 에디터 UI 구현 (React Flow 기반) - TableSource, DataTransform, INSERT, UPDATE, DELETE, UPSERT 노드 - 드래그앤드롭 노드 추가 및 연결 - 속성 패널을 통한 노드 설정 - 실시간 필드 라벨 표시 (column_labels 테이블 연동) - 데이터 변환 노드 (DataTransform) 기능 - EXPLODE: 구분자로 1개 행 → 여러 행 확장 - UPPERCASE, LOWERCASE, TRIM, CONCAT, SPLIT, REPLACE 등 12가지 변환 타입 - In-place 변환 지원 (타겟 필드 생략 시 소스 필드 덮어쓰기) - 변환된 필드가 하위 액션 노드에 자동 전달 - 노드 플로우 실행 엔진 - 위상 정렬을 통한 노드 실행 순서 결정 - 레벨별 병렬 실행 (Promise.allSettled) - 부분 실패 허용 (한 노드 실패 시 연결된 하위 노드만 스킵) - 트랜잭션 기반 안전한 데이터 처리 - UPSERT 액션 로직 구현 - DB 제약 조건 없이 SELECT → UPDATE or INSERT 방식 - 복합 충돌 키 지원 (예: sales_no + product_name) - 파라미터 인덱스 정확한 매핑 - 데이터 소스 자동 감지 - 테이블 선택 데이터 (selectedRowsData) 자동 주입 - 폼 입력 데이터 (formData) 자동 주입 - TableSource 노드가 외부 데이터 우선 사용 - 버튼 컴포넌트 통합 - 기존 관계 실행 + 새 노드 플로우 실행 하이브리드 지원 - 노드 플로우 선택 UI 추가 - API 클라이언트 통합 (Axios) - 개발 문서 작성 - 노드 기반 제어 시스템 개선 계획 - 노드 연결 규칙 설계 - 노드 실행 엔진 설계 - 노드 구조 개선안 - 버튼 통합 분석
2025-10-02 16:22:29 +09:00
"use client";
/**
*
*/
import { X } from "lucide-react";
import { Button } from "@/components/ui/button";
import { useFlowEditorStore } from "@/lib/stores/flowEditorStore";
import { TableSourceProperties } from "./properties/TableSourceProperties";
import { InsertActionProperties } from "./properties/InsertActionProperties";
import { FieldMappingProperties } from "./properties/FieldMappingProperties";
import { ConditionProperties } from "./properties/ConditionProperties";
import { UpdateActionProperties } from "./properties/UpdateActionProperties";
import { DeleteActionProperties } from "./properties/DeleteActionProperties";
import { ExternalDBSourceProperties } from "./properties/ExternalDBSourceProperties";
import { UpsertActionProperties } from "./properties/UpsertActionProperties";
import { DataTransformProperties } from "./properties/DataTransformProperties";
import { RestAPISourceProperties } from "./properties/RestAPISourceProperties";
import { CommentProperties } from "./properties/CommentProperties";
import { LogProperties } from "./properties/LogProperties";
import type { NodeType } from "@/types/node-editor";
export function PropertiesPanel() {
const { nodes, selectedNodes, setShowPropertiesPanel } = useFlowEditorStore();
// 선택된 노드가 하나일 경우 해당 노드 데이터 가져오기
const selectedNode = selectedNodes.length === 1 ? nodes.find((n) => n.id === selectedNodes[0]) : null;
return (
<div className="flex h-full flex-col">
{/* 헤더 */}
<div className="flex items-center justify-between border-b p-4">
<div>
<h3 className="text-sm font-semibold text-gray-900"></h3>
{selectedNode && (
<p className="mt-0.5 text-xs text-gray-500">{getNodeTypeLabel(selectedNode.type as NodeType)}</p>
)}
</div>
<Button variant="ghost" size="sm" onClick={() => setShowPropertiesPanel(false)} className="h-6 w-6 p-0">
<X className="h-4 w-4" />
</Button>
</div>
{/* 내용 */}
<div className="flex-1 overflow-hidden">
{selectedNodes.length === 0 ? (
<div className="flex h-full items-center justify-center p-4">
<div className="text-center text-sm text-gray-500">
<div className="mb-2 text-2xl">📝</div>
<p> </p>
<p> </p>
</div>
</div>
) : selectedNodes.length === 1 && selectedNode ? (
<NodePropertiesRenderer node={selectedNode} />
) : (
<div className="flex h-full items-center justify-center p-4">
<div className="text-center text-sm text-gray-500">
<div className="mb-2 text-2xl">📋</div>
<p>{selectedNodes.length} </p>
<p></p>
<p className="mt-2 text-xs"> </p>
</div>
</div>
)}
</div>
</div>
);
}
/**
*
*/
function NodePropertiesRenderer({ node }: { node: any }) {
switch (node.type) {
case "tableSource":
return <TableSourceProperties nodeId={node.id} data={node.data} />;
case "insertAction":
return <InsertActionProperties nodeId={node.id} data={node.data} />;
case "fieldMapping":
return <FieldMappingProperties nodeId={node.id} data={node.data} />;
case "condition":
return <ConditionProperties nodeId={node.id} data={node.data} />;
case "updateAction":
return <UpdateActionProperties nodeId={node.id} data={node.data} />;
case "deleteAction":
return <DeleteActionProperties nodeId={node.id} data={node.data} />;
case "externalDBSource":
return <ExternalDBSourceProperties nodeId={node.id} data={node.data} />;
case "upsertAction":
return <UpsertActionProperties nodeId={node.id} data={node.data} />;
case "dataTransform":
return <DataTransformProperties nodeId={node.id} data={node.data} />;
case "restAPISource":
return <RestAPISourceProperties nodeId={node.id} data={node.data} />;
case "comment":
return <CommentProperties nodeId={node.id} data={node.data} />;
case "log":
return <LogProperties nodeId={node.id} data={node.data} />;
default:
return (
<div className="p-4">
<div className="rounded border border-yellow-200 bg-yellow-50 p-4 text-sm">
<p className="font-medium text-yellow-800">🚧 </p>
<p className="mt-2 text-xs text-yellow-700">
{getNodeTypeLabel(node.type as NodeType)} UI는 .
</p>
<div className="mt-3 rounded bg-white p-2 text-xs">
<p className="font-medium text-gray-700"> ID:</p>
<p className="font-mono text-gray-600">{node.id}</p>
</div>
</div>
</div>
);
}
}
/**
*
*/
function getNodeTypeLabel(type: NodeType): string {
const labels: Record<NodeType, string> = {
tableSource: "테이블 소스",
externalDBSource: "외부 DB 소스",
restAPISource: "REST API 소스",
condition: "조건 분기",
fieldMapping: "필드 매핑",
dataTransform: "데이터 변환",
insertAction: "INSERT 액션",
updateAction: "UPDATE 액션",
deleteAction: "DELETE 액션",
upsertAction: "UPSERT 액션",
comment: "주석",
log: "로그",
};
return labels[type] || type;
}