ERP-node/frontend/components/screen-embedding/ScreenSplitPanel.tsx

133 lines
4.9 KiB
TypeScript
Raw Normal View History

2025-11-27 12:08:32 +09:00
/**
*
* .
*
* transferData .
* : 좌측 TableListComponent + Button(transferData )
*/
"use client";
import React, { useMemo } from "react";
2025-11-27 12:08:32 +09:00
import { EmbeddedScreen } from "./EmbeddedScreen";
import { Columns2 } from "lucide-react";
2025-11-28 14:56:11 +09:00
import { SplitPanelProvider } from "@/contexts/SplitPanelContext";
import { ResponsiveSplitPanel } from "@/components/common/ResponsiveSplitPanel";
2025-11-27 12:08:32 +09:00
interface ScreenSplitPanelProps {
screenId?: number;
config?: any; // 설정 패널에서 오는 config (leftScreenId, rightScreenId, splitRatio, resizable)
initialFormData?: Record<string, any>; // 🆕 수정 모드에서 전달되는 초기 데이터
groupedData?: Record<string, any>[]; // 🆕 그룹 데이터 (수정 모드에서 원본 데이터 추적용)
2025-11-27 12:08:32 +09:00
}
/**
*
* .
*/
export function ScreenSplitPanel({ screenId, config, initialFormData, groupedData }: ScreenSplitPanelProps) {
2025-11-28 14:56:11 +09:00
// config에서 splitRatio 추출 (기본값 50)
const configSplitRatio = config?.splitRatio ?? 50;
2025-11-27 12:08:32 +09:00
// 설정 패널에서 오는 간단한 config를 임베딩 설정으로 변환
const now = new Date().toISOString();
2025-11-27 12:08:32 +09:00
const leftEmbedding = config?.leftScreenId
? {
id: 1,
parentScreenId: screenId || 0,
childScreenId: config.leftScreenId,
position: "left" as const,
mode: "view" as const,
2025-11-27 12:08:32 +09:00
config: {},
companyCode: "*",
createdAt: now,
updatedAt: now,
2025-11-27 12:08:32 +09:00
}
: null;
const rightEmbedding = config?.rightScreenId
? {
id: 2,
parentScreenId: screenId || 0,
childScreenId: config.rightScreenId,
position: "right" as const,
mode: "view" as const,
2025-11-27 12:08:32 +09:00
config: {},
companyCode: "*",
createdAt: now,
updatedAt: now,
2025-11-27 12:08:32 +09:00
}
: null;
2025-11-28 14:56:11 +09:00
// config가 없는 경우 (디자이너 모드 또는 초기 상태)
if (!config) {
2025-11-27 12:08:32 +09:00
return (
<div className="border-muted-foreground/25 flex h-full items-center justify-center rounded-lg border-2 border-dashed">
<div className="space-y-4 p-6 text-center">
<div className="flex items-center justify-center gap-3">
<div className="bg-muted flex h-16 w-16 items-center justify-center rounded-lg">
<Columns2 className="text-muted-foreground h-8 w-8" />
</div>
</div>
<div>
<p className="text-muted-foreground mb-2 text-base font-semibold"> </p>
<p className="text-muted-foreground/60 mb-1 text-xs"> </p>
<p className="text-muted-foreground/60 text-xs">
/
</p>
<p className="text-muted-foreground/60 mt-2 text-[10px]">
💡 전달: 좌측 transferData
</p>
</div>
</div>
</div>
);
}
2025-11-28 14:56:11 +09:00
// 좌측 또는 우측 화면이 설정되지 않은 경우 안내 메시지 표시
const hasLeftScreen = !!leftEmbedding;
const hasRightScreen = !!rightEmbedding;
// 분할 패널 고유 ID 생성
const splitPanelId = useMemo(() => `split-panel-${screenId || "unknown"}-${Date.now()}`, [screenId]);
2025-11-27 12:08:32 +09:00
2025-11-28 14:56:11 +09:00
return (
<SplitPanelProvider
splitPanelId={splitPanelId}
leftScreenId={config?.leftScreenId || null}
rightScreenId={config?.rightScreenId || null}
2025-12-01 18:39:01 +09:00
parentDataMapping={config?.parentDataMapping || []}
linkedFilters={config?.linkedFilters || []}
disableAutoDataTransfer={config?.disableAutoDataTransfer ?? false}
2025-11-28 14:56:11 +09:00
>
<ResponsiveSplitPanel
left={
hasLeftScreen ? (
<EmbeddedScreen embedding={leftEmbedding!} position="left" initialFormData={initialFormData} groupedData={groupedData} />
2025-11-28 14:56:11 +09:00
) : (
<div className="flex h-full items-center justify-center bg-muted/30">
<p className="text-muted-foreground text-sm"> </p>
</div>
)
}
right={
hasRightScreen ? (
<EmbeddedScreen embedding={rightEmbedding!} position="right" initialFormData={initialFormData} groupedData={groupedData} />
2025-11-28 14:56:11 +09:00
) : (
<div className="flex h-full items-center justify-center bg-muted/30">
<p className="text-muted-foreground text-sm"> </p>
</div>
)
}
leftTitle="좌측 패널"
leftWidth={configSplitRatio}
minLeftWidth={20}
maxLeftWidth={80}
showResizer={config?.resizable !== false}
collapsedOnMobile={true}
/>
2025-11-28 14:56:11 +09:00
</SplitPanelProvider>
2025-11-27 12:08:32 +09:00
);
}