2026-03-21 22:05:42 -05:00
|
|
|
import { useDraggable } from '@dnd-kit/core';
|
2026-03-21 21:48:56 -05:00
|
|
|
import type { ModuleType } from '../../types';
|
2026-03-21 22:05:42 -05:00
|
|
|
import {
|
|
|
|
|
MODULE_TYPE_LABELS,
|
|
|
|
|
MODULE_TYPE_COLORS,
|
|
|
|
|
MODULE_U_DEFAULTS,
|
|
|
|
|
MODULE_PORT_DEFAULTS,
|
|
|
|
|
} from '../../lib/constants';
|
2026-03-21 21:48:56 -05:00
|
|
|
import { cn } from '../../lib/utils';
|
|
|
|
|
|
|
|
|
|
const ALL_TYPES: ModuleType[] = [
|
|
|
|
|
'SWITCH', 'AGGREGATE_SWITCH', 'ROUTER', 'FIREWALL', 'PATCH_PANEL',
|
|
|
|
|
'MODEM', 'SERVER', 'NAS', 'PDU', 'AP', 'BLANK', 'OTHER',
|
|
|
|
|
];
|
|
|
|
|
|
2026-03-21 22:05:42 -05:00
|
|
|
function PaletteItem({ type }: { type: ModuleType }) {
|
|
|
|
|
const { attributes, listeners, setNodeRef, isDragging } = useDraggable({
|
|
|
|
|
id: `palette-${type}`,
|
|
|
|
|
data: { type },
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const colors = MODULE_TYPE_COLORS[type];
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div
|
|
|
|
|
ref={setNodeRef}
|
|
|
|
|
{...listeners}
|
|
|
|
|
{...attributes}
|
|
|
|
|
className={cn(
|
|
|
|
|
'flex items-center gap-2 px-2 py-1.5 rounded border text-left w-full cursor-grab active:cursor-grabbing transition-all select-none',
|
|
|
|
|
colors.bg,
|
|
|
|
|
colors.border,
|
|
|
|
|
isDragging ? 'opacity-40' : 'hover:brightness-125'
|
|
|
|
|
)}
|
|
|
|
|
aria-label={`Drag ${MODULE_TYPE_LABELS[type]} onto a rack slot`}
|
|
|
|
|
>
|
|
|
|
|
<div className={cn('w-2 h-2 rounded-sm shrink-0 brightness-150', colors.bg)} />
|
|
|
|
|
<div className="min-w-0 flex-1">
|
|
|
|
|
<div className="text-xs font-medium text-white truncate">
|
|
|
|
|
{MODULE_TYPE_LABELS[type]}
|
|
|
|
|
</div>
|
|
|
|
|
<div className="text-[10px] text-slate-400">
|
|
|
|
|
{MODULE_U_DEFAULTS[type]}U · {MODULE_PORT_DEFAULTS[type]} ports
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
2026-03-21 21:48:56 -05:00
|
|
|
}
|
|
|
|
|
|
2026-03-21 22:05:42 -05:00
|
|
|
export function DevicePalette() {
|
2026-03-21 21:48:56 -05:00
|
|
|
return (
|
|
|
|
|
<aside className="w-44 shrink-0 flex flex-col bg-slate-800 border-r border-slate-700 overflow-y-auto">
|
|
|
|
|
<div className="px-3 py-2 border-b border-slate-700">
|
|
|
|
|
<p className="text-xs font-semibold text-slate-400 uppercase tracking-wider">Devices</p>
|
2026-03-21 22:05:42 -05:00
|
|
|
<p className="text-[10px] text-slate-600 mt-0.5">Drag onto a slot or click a slot</p>
|
2026-03-21 21:48:56 -05:00
|
|
|
</div>
|
|
|
|
|
<div className="flex flex-col gap-1 p-2">
|
2026-03-21 22:05:42 -05:00
|
|
|
{ALL_TYPES.map((type) => (
|
|
|
|
|
<PaletteItem key={type} type={type} />
|
|
|
|
|
))}
|
2026-03-21 21:48:56 -05:00
|
|
|
</div>
|
|
|
|
|
</aside>
|
|
|
|
|
);
|
|
|
|
|
}
|