ERP-node/lib/registry/DynamicConfigPanel.tsx

101 lines
2.8 KiB
TypeScript
Raw Permalink Normal View History

2025-09-09 14:29:04 +09:00
"use client";
import React from "react";
import { WebTypeRegistry } from "./WebTypeRegistry";
import { WebTypeConfigPanelProps } from "./types";
import { Alert, AlertDescription } from "@/components/ui/alert";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { Settings } from "lucide-react";
interface DynamicConfigPanelProps extends WebTypeConfigPanelProps {
widgetType: string;
showFallback?: boolean;
}
/**
*
*
*/
export const DynamicConfigPanel: React.FC<DynamicConfigPanelProps> = React.memo(
({
widgetType,
component,
onUpdateComponent,
onUpdateProperty,
showFallback = true,
}) => {
// 웹타입 정의 조회
const definition = WebTypeRegistry.get(widgetType);
// 웹타입이 등록되지 않은 경우
if (!definition) {
console.warn(`Unknown web type for config panel: ${widgetType}`);
if (!showFallback) {
return null;
}
return (
<Alert variant="secondary" className="w-full">
<Settings className="h-4 w-4" />
<AlertDescription>
<code>{widgetType}</code> .
</AlertDescription>
</Alert>
);
}
// 설정 패널이 정의되지 않은 경우
if (!definition.configPanel) {
if (!showFallback) {
return null;
}
return (
<Card className="w-full">
<CardHeader className="pb-3">
<CardTitle className="text-sm flex items-center gap-2">
<Settings className="h-4 w-4" />
{definition.name}
</CardTitle>
</CardHeader>
<CardContent className="pt-0">
<Alert variant="secondary">
<AlertDescription className="text-xs">
.
</AlertDescription>
</Alert>
</CardContent>
</Card>
);
}
// 비활성화된 웹타입인 경우
if (definition.isActive === false) {
return (
<Alert variant="secondary" className="w-full">
<Settings className="h-4 w-4" />
<AlertDescription>
: <code>{widgetType}</code>
</AlertDescription>
</Alert>
);
}
// 등록된 설정 패널 컴포넌트 렌더링
const ConfigPanelComponent = definition.configPanel;
return (
<ConfigPanelComponent
component={component}
onUpdateComponent={onUpdateComponent}
onUpdateProperty={onUpdateProperty}
/>
);
}
);
DynamicConfigPanel.displayName = "DynamicConfigPanel";