feat: customizable connection points per side (issue #243)
Generalize the bottom-only handle machinery to all four sides. Top/Bottom keep their single-handle default; Left/Right are opt-in (default 0) so existing diagrams render unchanged. Handle IDs stay keyed off the bare side name at slot 0, keeping saved edges valid. - handleUtils: side-generic API (handleId, handlePositions, clampHandles, sideDefault, removedHandleIds, sideHandleCount); legacy bottom fns kept as delegating aliases - BaseNode + ProxmoxGroupNode render all sides via new shared SideHandles - updateNode remaps edges on any side's shrink (fallback to slot-0 / bottom) - serializer round-trips top/left/right_handles - NodeModal: spatial cross of -/N/+ steppers around a node preview, replacing the four stacked sliders; seeds per-type defaults - CustomStyleModal: per-type default connection points per side ha-relevant: yes
This commit is contained in:
@@ -9,7 +9,7 @@ let mockZoom = 1
|
||||
|
||||
vi.mock('@xyflow/react', () => ({
|
||||
Handle: () => null,
|
||||
Position: { Top: 'top', Bottom: 'bottom' },
|
||||
Position: { Top: 'top', Bottom: 'bottom', Left: 'left', Right: 'right' },
|
||||
NodeResizer: () => null,
|
||||
useUpdateNodeInternals: () => vi.fn(),
|
||||
useViewport: () => ({ zoom: mockZoom }),
|
||||
@@ -59,14 +59,9 @@ vi.mock('@/utils/propertyIcons', () => ({
|
||||
resolvePropertyIcon: (icon: string | null) => icon ? Server : null,
|
||||
}))
|
||||
|
||||
vi.mock('@/utils/handleUtils', () => ({
|
||||
bottomHandleId: (idx: number) => idx === 0 ? 'bottom' : `bottom-${idx + 1}`,
|
||||
bottomHandlePositions: (count: number) => {
|
||||
const c = typeof count === 'number' && count > 0 ? Math.floor(count) : 1
|
||||
return Array.from({ length: c }, (_, i) => ((i + 1) * 100) / (c + 1))
|
||||
},
|
||||
clampBottomHandles: (n: unknown) => typeof n === 'number' ? n : 1,
|
||||
}))
|
||||
// handleUtils is pure — use the real implementation so the side-generic API
|
||||
// (SIDES, handleId, handlePositions, sideHandleCount, …) stays in sync.
|
||||
vi.mock('@/utils/handleUtils', async (importOriginal) => await importOriginal())
|
||||
|
||||
beforeEach(() => { mockZoom = 1 })
|
||||
|
||||
@@ -176,15 +171,23 @@ describe('BaseNode — properties rendering', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('BaseNode — port numbers (issue #20)', () => {
|
||||
it('renders a number above each bottom handle when show_port_numbers is on', () => {
|
||||
describe('BaseNode — port numbers (issue #20 / #243)', () => {
|
||||
it('renders a number on each connection point when show_port_numbers is on', () => {
|
||||
// bottom=4 → labels 1..4; top defaults to 1 → an extra "1" on top.
|
||||
renderBaseNode({ bottom_handles: 4, show_port_numbers: true })
|
||||
expect(screen.getByText('1')).toBeDefined()
|
||||
expect(screen.getAllByText('1')).toHaveLength(2) // top slot 0 + bottom slot 0
|
||||
expect(screen.getByText('2')).toBeDefined()
|
||||
expect(screen.getByText('3')).toBeDefined()
|
||||
expect(screen.getByText('4')).toBeDefined()
|
||||
})
|
||||
|
||||
it('labels left/right connection points too when enabled', () => {
|
||||
// top=1, bottom=1, left=2, right=0 → labels: two "1" (top+bottom) + "2" (left).
|
||||
renderBaseNode({ bottom_handles: 1, left_handles: 2, show_port_numbers: true })
|
||||
expect(screen.getByText('2')).toBeDefined()
|
||||
expect(screen.getAllByText('1')).toHaveLength(3) // top + bottom + left slot 0
|
||||
})
|
||||
|
||||
it('does not render port numbers when show_port_numbers is off', () => {
|
||||
renderBaseNode({ bottom_handles: 4 })
|
||||
expect(screen.queryByText('1')).toBeNull()
|
||||
@@ -192,8 +195,9 @@ describe('BaseNode — port numbers (issue #20)', () => {
|
||||
})
|
||||
|
||||
it('numbers match the handle count', () => {
|
||||
// bottom=2 → 1,2; top default 1 adds one more "1"; no "3".
|
||||
renderBaseNode({ bottom_handles: 2, show_port_numbers: true })
|
||||
expect(screen.getByText('1')).toBeDefined()
|
||||
expect(screen.getAllByText('1')).toHaveLength(2)
|
||||
expect(screen.getByText('2')).toBeDefined()
|
||||
expect(screen.queryByText('3')).toBeNull()
|
||||
})
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { createElement, useEffect, useMemo } from 'react'
|
||||
import { Handle, Position, NodeResizer, useUpdateNodeInternals, useViewport, type NodeProps, type Node } from '@xyflow/react'
|
||||
import { NodeResizer, useUpdateNodeInternals, useViewport, type NodeProps, type Node } from '@xyflow/react'
|
||||
import { Cpu, MemoryStick, HardDrive, ExternalLink, type LucideIcon } from 'lucide-react'
|
||||
import type { NodeData } from '@/types'
|
||||
import { resolveNodeColors } from '@/utils/nodeColors'
|
||||
@@ -10,7 +10,8 @@ import { useThemeStore } from '@/stores/themeStore'
|
||||
import { THEMES } from '@/utils/themes'
|
||||
import { useCanvasStore, serviceStatusKey } from '@/stores/canvasStore'
|
||||
import { maskIp, primaryIp, splitIps } from '@/utils/maskIp'
|
||||
import { bottomHandleId, bottomHandlePositions, clampBottomHandles } from '@/utils/handleUtils'
|
||||
import { sideHandleCount } from '@/utils/handleUtils'
|
||||
import { SideHandles } from './SideHandles'
|
||||
import { getServiceUrl } from '@/utils/serviceUrl'
|
||||
|
||||
interface BaseNodeProps extends NodeProps<Node<NodeData>> {
|
||||
@@ -24,7 +25,7 @@ function formatStorage(gb: number): string {
|
||||
|
||||
export function BaseNode({ id, data, selected, icon: typeIcon, width, height }: BaseNodeProps) {
|
||||
const updateNodeInternals = useUpdateNodeInternals()
|
||||
useEffect(() => { updateNodeInternals(id) }, [data.bottom_handles, id, updateNodeInternals])
|
||||
useEffect(() => { updateNodeInternals(id) }, [data.top_handles, data.bottom_handles, data.left_handles, data.right_handles, id, updateNodeInternals])
|
||||
|
||||
const { zoom } = useViewport()
|
||||
const borderWidth = useMemo(() => Math.max(1, 1 / zoom), [zoom])
|
||||
@@ -47,6 +48,12 @@ export function BaseNode({ id, data, selected, icon: typeIcon, width, height }:
|
||||
const showLegacyHardware = !data.properties && data.show_hardware &&
|
||||
(data.cpu_count != null || data.cpu_model || data.ram_gb != null || data.disk_gb != null)
|
||||
|
||||
// Resolved per-side connection-point counts (missing field → side default).
|
||||
const topCount = sideHandleCount(data, 'top')
|
||||
const bottomCount = sideHandleCount(data, 'bottom')
|
||||
const leftCount = sideHandleCount(data, 'left')
|
||||
const rightCount = sideHandleCount(data, 'right')
|
||||
|
||||
return (
|
||||
<div
|
||||
className="relative flex flex-col rounded-lg border transition-all duration-200 overflow-hidden"
|
||||
@@ -62,8 +69,9 @@ export function BaseNode({ id, data, selected, icon: typeIcon, width, height }:
|
||||
? `0 0 0 ${borderWidth}px ${colors.border}, 0 0 8px ${colors.border}44`
|
||||
: 'none',
|
||||
opacity: data.status === 'offline' ? 0.55 : 1,
|
||||
// Grow node width when many bottom handles so each stays clickable (~14px slot).
|
||||
minWidth: Math.max(140, clampBottomHandles(data.bottom_handles ?? 1) * 14),
|
||||
// Grow node so each handle stays clickable (~14px slot on each axis).
|
||||
minWidth: Math.max(140, Math.max(topCount, bottomCount) * 14),
|
||||
minHeight: Math.max(50, Math.max(leftCount, rightCount) * 14),
|
||||
width: width ? '100%' : undefined,
|
||||
height: height ? '100%' : undefined,
|
||||
}}
|
||||
@@ -75,13 +83,14 @@ export function BaseNode({ id, data, selected, icon: typeIcon, width, height }:
|
||||
lineStyle={{ borderColor: 'transparent' }}
|
||||
handleStyle={{ borderColor: colors.border, background: colors.border, width: 16, height: 16 }}
|
||||
/>
|
||||
<Handle
|
||||
type="source"
|
||||
position={Position.Top}
|
||||
id="top"
|
||||
style={{ background: theme.colors.handleBackground, borderColor: theme.colors.handleBorder }}
|
||||
<SideHandles
|
||||
data={data}
|
||||
sides={['top', 'left', 'right']}
|
||||
handleBackground={theme.colors.handleBackground}
|
||||
handleBorder={theme.colors.handleBorder}
|
||||
labelColor={theme.colors.nodeSubtextColor}
|
||||
showLabels
|
||||
/>
|
||||
<Handle type="target" position={Position.Top} id="top-t" style={{ opacity: 0, width: 12, height: 12 }} />
|
||||
|
||||
{/* Status dot — absolute to avoid affecting node auto-width */}
|
||||
<div
|
||||
@@ -251,40 +260,14 @@ export function BaseNode({ id, data, selected, icon: typeIcon, width, height }:
|
||||
</>
|
||||
)}
|
||||
|
||||
{bottomHandlePositions(data.bottom_handles ?? 1).map((leftPct, idx) => {
|
||||
const sourceId = bottomHandleId(idx)
|
||||
const targetId = `${sourceId}-t`
|
||||
return (
|
||||
<span key={sourceId}>
|
||||
{data.show_port_numbers && (
|
||||
<span
|
||||
className="absolute font-mono leading-none pointer-events-none select-none"
|
||||
style={{
|
||||
left: `${leftPct}%`,
|
||||
bottom: 3,
|
||||
transform: 'translateX(-50%)',
|
||||
fontSize: 7,
|
||||
color: theme.colors.nodeSubtextColor,
|
||||
}}
|
||||
>
|
||||
{idx + 1}
|
||||
</span>
|
||||
)}
|
||||
<Handle
|
||||
type="source"
|
||||
position={Position.Bottom}
|
||||
id={sourceId}
|
||||
style={{ left: `${leftPct}%`, background: theme.colors.handleBackground, borderColor: theme.colors.handleBorder }}
|
||||
/>
|
||||
<Handle
|
||||
type="target"
|
||||
position={Position.Bottom}
|
||||
id={targetId}
|
||||
style={{ left: `${leftPct}%`, opacity: 0, width: 12, height: 12 }}
|
||||
/>
|
||||
</span>
|
||||
)
|
||||
})}
|
||||
<SideHandles
|
||||
data={data}
|
||||
sides={['bottom']}
|
||||
handleBackground={theme.colors.handleBackground}
|
||||
handleBorder={theme.colors.handleBorder}
|
||||
labelColor={theme.colors.nodeSubtextColor}
|
||||
showLabels
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -10,13 +10,13 @@ import { useCanvasStore } from '@/stores/canvasStore'
|
||||
import { maskIp, splitIps } from '@/utils/maskIp'
|
||||
import { useThemeStore } from '@/stores/themeStore'
|
||||
import { THEMES } from '@/utils/themes'
|
||||
import { bottomHandleId, bottomHandlePositions } from '@/utils/handleUtils'
|
||||
import { BaseNode } from './BaseNode'
|
||||
import { SideHandles } from './SideHandles'
|
||||
|
||||
export function ProxmoxGroupNode(props: NodeProps<Node<NodeData>>) {
|
||||
const { id, data, selected } = props
|
||||
const updateNodeInternals = useUpdateNodeInternals()
|
||||
useEffect(() => { updateNodeInternals(id) }, [data.bottom_handles, id, updateNodeInternals])
|
||||
useEffect(() => { updateNodeInternals(id) }, [data.top_handles, data.bottom_handles, data.left_handles, data.right_handles, id, updateNodeInternals])
|
||||
|
||||
const activeTheme = useThemeStore((s) => s.activeTheme)
|
||||
const hideIp = useCanvasStore((s) => s.hideIp)
|
||||
@@ -145,33 +145,12 @@ export function ProxmoxGroupNode(props: NodeProps<Node<NodeData>>) {
|
||||
<div className="flex-1 relative" />
|
||||
</div>
|
||||
|
||||
<Handle
|
||||
type="source"
|
||||
position={Position.Top}
|
||||
id="top"
|
||||
style={{ background: theme.colors.handleBackground, borderColor: theme.colors.handleBorder }}
|
||||
<SideHandles
|
||||
data={data}
|
||||
handleBackground={theme.colors.handleBackground}
|
||||
handleBorder={theme.colors.handleBorder}
|
||||
labelColor={theme.colors.nodeSubtextColor}
|
||||
/>
|
||||
<Handle type="target" position={Position.Top} id="top-t" style={{ opacity: 0, width: 12, height: 12 }} />
|
||||
{bottomHandlePositions(data.bottom_handles ?? 1).map((leftPct, idx) => {
|
||||
const sourceId = bottomHandleId(idx)
|
||||
const targetId = `${sourceId}-t`
|
||||
return (
|
||||
<span key={sourceId}>
|
||||
<Handle
|
||||
type="source"
|
||||
position={Position.Bottom}
|
||||
id={sourceId}
|
||||
style={{ left: `${leftPct}%`, background: theme.colors.handleBackground, borderColor: theme.colors.handleBorder }}
|
||||
/>
|
||||
<Handle
|
||||
type="target"
|
||||
position={Position.Bottom}
|
||||
id={targetId}
|
||||
style={{ left: `${leftPct}%`, opacity: 0, width: 12, height: 12 }}
|
||||
/>
|
||||
</span>
|
||||
)
|
||||
})}
|
||||
|
||||
{/* Cluster handles */}
|
||||
<Handle
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
import type { CSSProperties } from 'react'
|
||||
import { Handle, Position } from '@xyflow/react'
|
||||
import type { NodeData } from '@/types'
|
||||
import {
|
||||
SIDES,
|
||||
handleId,
|
||||
handlePositions,
|
||||
isVerticalSide,
|
||||
sideHandleCount,
|
||||
type Side,
|
||||
} from '@/utils/handleUtils'
|
||||
|
||||
const POSITION: Record<Side, Position> = {
|
||||
top: Position.Top,
|
||||
bottom: Position.Bottom,
|
||||
left: Position.Left,
|
||||
right: Position.Right,
|
||||
}
|
||||
|
||||
interface SideHandlesProps {
|
||||
data: NodeData
|
||||
handleBackground: string
|
||||
handleBorder: string
|
||||
/** Colour for the optional port-number labels. */
|
||||
labelColor: string
|
||||
/** Which sides to render. Defaults to all four. */
|
||||
sides?: readonly Side[]
|
||||
/** When true, render port-number labels if data.show_port_numbers is set. */
|
||||
showLabels?: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the per-side React Flow handles (visible source + invisible target)
|
||||
* for a node, spaced along each side's axis. Shared by BaseNode and the
|
||||
* container-mode ProxmoxGroupNode so handle IDs stay identical across both.
|
||||
*/
|
||||
export function SideHandles({
|
||||
data,
|
||||
handleBackground,
|
||||
handleBorder,
|
||||
labelColor,
|
||||
sides = SIDES,
|
||||
showLabels = false,
|
||||
}: SideHandlesProps) {
|
||||
return (
|
||||
<>
|
||||
{sides.map((side) => {
|
||||
const vertical = isVerticalSide(side)
|
||||
return handlePositions(side, sideHandleCount(data, side)).map((pct, idx) => {
|
||||
const sourceId = handleId(side, idx)
|
||||
const targetId = `${sourceId}-t`
|
||||
const offset: CSSProperties = vertical ? { top: `${pct}%` } : { left: `${pct}%` }
|
||||
const labelStyle: CSSProperties = vertical
|
||||
? { top: `${pct}%`, [side]: 3, transform: 'translateY(-50%)' }
|
||||
: { left: `${pct}%`, [side]: 3, transform: 'translateX(-50%)' }
|
||||
return (
|
||||
<span key={sourceId}>
|
||||
{showLabels && data.show_port_numbers && (
|
||||
<span
|
||||
className="absolute font-mono leading-none pointer-events-none select-none"
|
||||
style={{ ...labelStyle, fontSize: 7, color: labelColor }}
|
||||
>
|
||||
{idx + 1}
|
||||
</span>
|
||||
)}
|
||||
<Handle
|
||||
type="source"
|
||||
position={POSITION[side]}
|
||||
id={sourceId}
|
||||
style={{ ...offset, background: handleBackground, borderColor: handleBorder }}
|
||||
/>
|
||||
<Handle
|
||||
type="target"
|
||||
position={POSITION[side]}
|
||||
id={targetId}
|
||||
style={{ ...offset, opacity: 0, width: 12, height: 12 }}
|
||||
/>
|
||||
</span>
|
||||
)
|
||||
})
|
||||
})}
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/u
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { useThemeStore } from '@/stores/themeStore'
|
||||
import { useCanvasStore } from '@/stores/canvasStore'
|
||||
import { clampHandles, sideDefault } from '@/utils/handleUtils'
|
||||
import { THEMES } from '@/utils/themes'
|
||||
import { applyOpacity } from '@/utils/colorUtils'
|
||||
import type {
|
||||
@@ -178,6 +179,33 @@ function NodeEditor({ nodeType, style, onChange, onApplyToExisting }: NodeEditor
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="border-t border-[#30363d] pt-3">
|
||||
<div className="text-xs text-[#8b949e] mb-1">Default connection points</div>
|
||||
<div className="text-xs text-[#8b949e]/60 mb-2">New {NODE_TYPE_LABELS[nodeType]} nodes start with these (0–64 per side)</div>
|
||||
<div className="grid grid-cols-2 gap-2">
|
||||
{([
|
||||
['Top', 'top', 'topHandles'],
|
||||
['Right', 'right', 'rightHandles'],
|
||||
['Bottom', 'bottom', 'bottomHandles'],
|
||||
['Left', 'left', 'leftHandles'],
|
||||
] as const).map(([label, side, key]) => (
|
||||
<div key={side} className="flex items-center gap-2">
|
||||
<span className="text-xs text-[#8b949e] w-12">{label}</span>
|
||||
<input
|
||||
type="number"
|
||||
min={sideDefault(side)}
|
||||
max={64}
|
||||
step={1}
|
||||
value={style[key] ?? sideDefault(side)}
|
||||
onChange={(e) => set(key, clampHandles(side, parseInt(e.target.value, 10)))}
|
||||
aria-label={`${label} default connection points`}
|
||||
className="w-16 h-7 text-xs bg-[#0d1117] border border-[#30363d] rounded px-2 text-[#e6edf3]"
|
||||
/>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Button
|
||||
size="sm"
|
||||
className="self-start bg-[#00d4ff] text-[#0d1117] hover:bg-[#00d4ff]/90"
|
||||
|
||||
@@ -6,11 +6,12 @@ import { Button } from '@/components/ui/button'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Label } from '@/components/ui/label'
|
||||
import { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectSeparator, SelectTrigger, SelectValue } from '@/components/ui/select'
|
||||
import { NODE_TYPE_LABELS, type NodeData, type NodeType, type CheckMethod } from '@/types'
|
||||
import { NODE_TYPE_LABELS, type NodeData, type NodeType, type CheckMethod, type NodeTypeStyle } from '@/types'
|
||||
import { useThemeStore } from '@/stores/themeStore'
|
||||
import { resolveNodeColors } from '@/utils/nodeColors'
|
||||
import { ICON_REGISTRY, ICON_CATEGORIES, NODE_TYPE_DEFAULT_ICONS, isBrandIconKey, brandIconSlug, brandIconUrl } from '@/utils/nodeIcons'
|
||||
import { BrandIconPicker } from './BrandIconPicker'
|
||||
import { MIN_BOTTOM_HANDLES, MAX_BOTTOM_HANDLES, clampBottomHandles } from '@/utils/handleUtils'
|
||||
import { MAX_HANDLES, clampHandles, sideDefault, handleCountField, type Side } from '@/utils/handleUtils'
|
||||
import { getValidParentTypes } from '@/utils/virtualEdgeParent'
|
||||
|
||||
const NODE_TYPE_GROUPS: { label: string; types: NodeType[] }[] = [
|
||||
@@ -24,6 +25,65 @@ const NODE_TYPE_GROUPS: { label: string; types: NodeType[] }[] = [
|
||||
{ label: 'Generic', types: ['generic', 'groupRect'] },
|
||||
]
|
||||
|
||||
// Maps a side to its per-type default field on NodeTypeStyle.
|
||||
const SIDE_STYLE_KEY: Record<Side, keyof NodeTypeStyle> = {
|
||||
top: 'topHandles',
|
||||
bottom: 'bottomHandles',
|
||||
left: 'leftHandles',
|
||||
right: 'rightHandles',
|
||||
}
|
||||
|
||||
/**
|
||||
* Compact per-side connection-point control: [− N +] with a typable value.
|
||||
* Placed spatially around a node preview (see the Connection Points section).
|
||||
*/
|
||||
function CPStepper({ label, side, value, onChange }: {
|
||||
label: string
|
||||
side: Side
|
||||
value: number
|
||||
onChange: (v: number) => void
|
||||
}) {
|
||||
const min = sideDefault(side)
|
||||
const labelEl = <span className="text-[10px] text-muted-foreground/80 leading-none">{label}</span>
|
||||
const belowLabel = side === 'bottom'
|
||||
const btn = 'w-6 h-full flex items-center justify-center text-sm text-muted-foreground hover:text-foreground hover:bg-[#21262d] disabled:opacity-30 disabled:hover:bg-transparent disabled:cursor-default'
|
||||
return (
|
||||
<div className="flex flex-col items-center gap-1">
|
||||
{!belowLabel && labelEl}
|
||||
<div className="flex items-center h-7 rounded-md border border-[#30363d] bg-[#0d1117] overflow-hidden">
|
||||
<button
|
||||
type="button"
|
||||
aria-label={`Decrease ${label} connection points`}
|
||||
onClick={() => onChange(clampHandles(side, value - 1))}
|
||||
disabled={value <= min}
|
||||
className={btn}
|
||||
>
|
||||
−
|
||||
</button>
|
||||
<input
|
||||
type="number"
|
||||
min={min}
|
||||
max={MAX_HANDLES}
|
||||
value={value}
|
||||
aria-label={`${label} connection points`}
|
||||
onChange={(e) => onChange(clampHandles(side, Number(e.target.value)))}
|
||||
className="w-9 h-full bg-transparent text-center text-xs font-mono text-foreground outline-none [appearance:textfield] [&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:appearance-none"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
aria-label={`Increase ${label} connection points`}
|
||||
onClick={() => onChange(clampHandles(side, value + 1))}
|
||||
disabled={value >= MAX_HANDLES}
|
||||
className={btn}
|
||||
>
|
||||
+
|
||||
</button>
|
||||
</div>
|
||||
{belowLabel && labelEl}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const CHECK_METHODS: CheckMethod[] = ['none', 'ping', 'http', 'https', 'tcp', 'ssh', 'prometheus', 'health']
|
||||
const CONTAINER_MODE_TYPES: NodeType[] = ['proxmox', 'vm', 'lxc', 'docker_host']
|
||||
const ZIGBEE_TYPES: NodeType[] = ['zigbee_coordinator', 'zigbee_router', 'zigbee_enddevice']
|
||||
@@ -94,6 +154,16 @@ export function NodeModal({ open, onClose, onSubmit, initial, title = 'Add Node'
|
||||
const set = (key: keyof NodeData, value: unknown) =>
|
||||
setForm((f) => ({ ...f, [key]: value }))
|
||||
|
||||
const customStyle = useThemeStore((s) => s.customStyle)
|
||||
// Effective default count for a side: the per-type style default if set,
|
||||
// otherwise the intrinsic side default (top/bottom → 1, left/right → 0).
|
||||
const effectiveSideDefault = (side: Side): number => {
|
||||
const styleVal = customStyle.nodes[(form.type ?? 'generic') as NodeType]?.[SIDE_STYLE_KEY[side]]
|
||||
return clampHandles(side, typeof styleVal === 'number' ? styleVal : sideDefault(side))
|
||||
}
|
||||
const sideValue = (side: Side): number =>
|
||||
clampHandles(side, form[handleCountField(side)] ?? effectiveSideDefault(side))
|
||||
|
||||
const handleSubmit = (e: React.FormEvent) => {
|
||||
e.preventDefault()
|
||||
if (!form.label?.trim()) {
|
||||
@@ -113,8 +183,17 @@ export function NodeModal({ open, onClose, onSubmit, initial, title = 'Add Node'
|
||||
const parent = parentCandidates.find((n) => n.id === safeParentId)
|
||||
if (!parent || !isValidParent(parent)) safeParentId = undefined
|
||||
}
|
||||
const isGroupType = selectedType === 'groupRect' || selectedType === 'group'
|
||||
onSubmit({
|
||||
...form,
|
||||
// Persist the resolved per-side counts so type-style defaults (and
|
||||
// untouched sliders) are baked into the node. Skipped for group types.
|
||||
...(isGroupType ? {} : {
|
||||
top_handles: sideValue('top'),
|
||||
bottom_handles: sideValue('bottom'),
|
||||
left_handles: sideValue('left'),
|
||||
right_handles: sideValue('right'),
|
||||
}),
|
||||
parent_id: safeParentId,
|
||||
container_mode: canUseContainerMode ? !!form.container_mode : false,
|
||||
})
|
||||
@@ -509,31 +588,42 @@ export function NodeModal({ open, onClose, onSubmit, initial, title = 'Add Node'
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Bottom connection points (not for group containers) */}
|
||||
{/* Connection points per side (not for group containers) */}
|
||||
{form.type !== 'groupRect' && form.type !== 'group' && (
|
||||
<div className="flex flex-col gap-1.5 col-span-2">
|
||||
<div className="flex items-center justify-between">
|
||||
<Label className="text-xs text-muted-foreground">Bottom Connection Points</Label>
|
||||
<span className="text-xs font-mono text-foreground">{clampBottomHandles(form.bottom_handles ?? 1)}</span>
|
||||
</div>
|
||||
<input
|
||||
type="range"
|
||||
min={MIN_BOTTOM_HANDLES}
|
||||
max={MAX_BOTTOM_HANDLES}
|
||||
step={1}
|
||||
value={clampBottomHandles(form.bottom_handles ?? 1)}
|
||||
onChange={(e) => set('bottom_handles', clampBottomHandles(Number(e.target.value)))}
|
||||
aria-label="Bottom connection points slider"
|
||||
className="w-full accent-[#00d4ff] cursor-pointer"
|
||||
/>
|
||||
<div className="flex justify-between text-[10px] text-muted-foreground/60 font-mono">
|
||||
<span>{MIN_BOTTOM_HANDLES}</span>
|
||||
<span>{MAX_BOTTOM_HANDLES}</span>
|
||||
<div className="flex flex-col gap-2.5 col-span-2">
|
||||
<Label className="text-xs text-muted-foreground">Connection Points</Label>
|
||||
{/* Spatial cross: each side's stepper sits where that side is. */}
|
||||
<div className="grid grid-cols-[1fr_auto_1fr] items-center justify-items-center gap-x-2 gap-y-2 py-1">
|
||||
<div />
|
||||
<CPStepper label="Top" side="top" value={sideValue('top')}
|
||||
onChange={(v) => set('top_handles', v)} />
|
||||
<div />
|
||||
|
||||
<CPStepper label="Left" side="left" value={sideValue('left')}
|
||||
onChange={(v) => set('left_handles', v)} />
|
||||
<div
|
||||
className="flex items-center justify-center rounded-md border text-[9px] uppercase tracking-wide font-medium select-none"
|
||||
style={{
|
||||
width: 64, height: 40,
|
||||
borderColor: resolvedNodeColors.border,
|
||||
background: `${resolvedNodeColors.background}`,
|
||||
color: resolvedNodeColors.icon,
|
||||
}}
|
||||
>
|
||||
node
|
||||
</div>
|
||||
<CPStepper label="Right" side="right" value={sideValue('right')}
|
||||
onChange={(v) => set('right_handles', v)} />
|
||||
|
||||
<div />
|
||||
<CPStepper label="Bottom" side="bottom" value={sideValue('bottom')}
|
||||
onChange={(v) => set('bottom_handles', v)} />
|
||||
<div />
|
||||
</div>
|
||||
<div className="flex items-center justify-between pt-1">
|
||||
<div className="flex flex-col gap-0.5">
|
||||
<Label className="text-xs text-muted-foreground">Show Port Numbers</Label>
|
||||
<span className="text-[10px] text-muted-foreground/60">Label each bottom connection point</span>
|
||||
<span className="text-[10px] text-muted-foreground/60">Label each connection point</span>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
|
||||
@@ -135,6 +135,34 @@ describe('CustomStyleModal', () => {
|
||||
expect((widthInputs[0] as HTMLInputElement).value).toBe('250')
|
||||
})
|
||||
|
||||
it('shows per-side default connection-point inputs in the node editor', () => {
|
||||
render(<CustomStyleModal open onClose={vi.fn()} />)
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Router' }))
|
||||
expect(screen.getByText('Default connection points')).toBeDefined()
|
||||
expect(screen.getByLabelText('Top default connection points')).toBeDefined()
|
||||
expect(screen.getByLabelText('Left default connection points')).toBeDefined()
|
||||
})
|
||||
|
||||
it('defaults per-side inputs to 1 (top/bottom) and 0 (left/right)', () => {
|
||||
render(<CustomStyleModal open onClose={vi.fn()} />)
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Router' }))
|
||||
expect((screen.getByLabelText('Top default connection points') as HTMLInputElement).value).toBe('1')
|
||||
expect((screen.getByLabelText('Left default connection points') as HTMLInputElement).value).toBe('0')
|
||||
})
|
||||
|
||||
it('editing a per-side default persists via setCustomStyle on Save', () => {
|
||||
const onClose = vi.fn()
|
||||
useCanvasStore.setState({ markUnsaved: vi.fn() })
|
||||
const setCustomStyle = vi.spyOn(useThemeStore.getState(), 'setCustomStyle')
|
||||
render(<CustomStyleModal open onClose={onClose} />)
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Router' }))
|
||||
fireEvent.change(screen.getByLabelText('Left default connection points'), { target: { value: '3' } })
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Save Custom Style' }))
|
||||
expect(setCustomStyle).toHaveBeenCalled()
|
||||
const saved = setCustomStyle.mock.calls.at(-1)?.[0]
|
||||
expect(saved?.nodes.router?.leftHandles).toBe(3)
|
||||
})
|
||||
|
||||
it('resets abandoned edits when reopened after cancel (mounted parent)', () => {
|
||||
// Parent keeps the modal mounted and only toggles `open`, so the reset must
|
||||
// happen on the open-prop edge, not via Radix onOpenChange.
|
||||
|
||||
@@ -435,57 +435,88 @@ describe('NodeModal', () => {
|
||||
expect(screen.getByText(/Using default colors for/)).toBeDefined()
|
||||
})
|
||||
|
||||
// ── Bottom connection points ───────────────────────────────────────────
|
||||
// ── Connection points per side (issue #243) ────────────────────────────
|
||||
|
||||
it('shows Bottom Connection Points for server type', () => {
|
||||
it('shows the Connection Points section for server type', () => {
|
||||
renderModal({ initial: BASE })
|
||||
expect(screen.getByText('Bottom Connection Points')).toBeDefined()
|
||||
expect(screen.getByText('Connection Points')).toBeDefined()
|
||||
expect(screen.getByLabelText('Top connection points')).toBeDefined()
|
||||
expect(screen.getByLabelText('Right connection points')).toBeDefined()
|
||||
expect(screen.getByLabelText('Bottom connection points')).toBeDefined()
|
||||
expect(screen.getByLabelText('Left connection points')).toBeDefined()
|
||||
})
|
||||
|
||||
it('hides Bottom Connection Points for groupRect', () => {
|
||||
it('hides Connection Points for groupRect', () => {
|
||||
renderModal({ initial: { ...BASE, type: 'groupRect' } })
|
||||
expect(screen.queryByText('Bottom Connection Points')).toBeNull()
|
||||
expect(screen.queryByText('Connection Points')).toBeNull()
|
||||
})
|
||||
|
||||
it('hides Bottom Connection Points for group', () => {
|
||||
it('hides Connection Points for group', () => {
|
||||
renderModal({ initial: { ...BASE, type: 'group' } })
|
||||
expect(screen.queryByText('Bottom Connection Points')).toBeNull()
|
||||
expect(screen.queryByText('Connection Points')).toBeNull()
|
||||
})
|
||||
|
||||
it('defaults bottom_handles to 1', () => {
|
||||
it('defaults top/bottom to 1 and left/right to 0', () => {
|
||||
renderModal({ initial: BASE })
|
||||
const slider = screen.getByLabelText('Bottom connection points slider') as HTMLInputElement
|
||||
expect(slider.value).toBe('1')
|
||||
expect((screen.getByLabelText('Top connection points') as HTMLInputElement).value).toBe('1')
|
||||
expect((screen.getByLabelText('Bottom connection points') as HTMLInputElement).value).toBe('1')
|
||||
expect((screen.getByLabelText('Left connection points') as HTMLInputElement).value).toBe('0')
|
||||
expect((screen.getByLabelText('Right connection points') as HTMLInputElement).value).toBe('0')
|
||||
})
|
||||
|
||||
it('pre-fills bottom_handles from initial', () => {
|
||||
renderModal({ initial: { ...BASE, bottom_handles: 3 } })
|
||||
const slider = screen.getByLabelText('Bottom connection points slider') as HTMLInputElement
|
||||
expect(slider.value).toBe('3')
|
||||
it('pre-fills each side from initial', () => {
|
||||
renderModal({ initial: { ...BASE, top_handles: 2, bottom_handles: 3, left_handles: 4, right_handles: 1 } })
|
||||
expect((screen.getByLabelText('Top connection points') as HTMLInputElement).value).toBe('2')
|
||||
expect((screen.getByLabelText('Bottom connection points') as HTMLInputElement).value).toBe('3')
|
||||
expect((screen.getByLabelText('Left connection points') as HTMLInputElement).value).toBe('4')
|
||||
expect((screen.getByLabelText('Right connection points') as HTMLInputElement).value).toBe('1')
|
||||
})
|
||||
|
||||
it('submits updated bottom_handles', () => {
|
||||
it('submits per-side counts edited via the number inputs', () => {
|
||||
const { onSubmit } = renderModal({ initial: BASE })
|
||||
const slider = screen.getByLabelText('Bottom connection points slider') as HTMLInputElement
|
||||
fireEvent.change(slider, { target: { value: '12' } })
|
||||
fireEvent.change(screen.getByLabelText('Bottom connection points'), { target: { value: '12' } })
|
||||
fireEvent.change(screen.getByLabelText('Left connection points'), { target: { value: '3' } })
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Add' }))
|
||||
expect((onSubmit.mock.calls[0][0] as Partial<NodeData>).bottom_handles).toBe(12)
|
||||
const payload = onSubmit.mock.calls[0][0] as Partial<NodeData>
|
||||
expect(payload.bottom_handles).toBe(12)
|
||||
expect(payload.left_handles).toBe(3)
|
||||
expect(payload.top_handles).toBe(1)
|
||||
expect(payload.right_handles).toBe(0)
|
||||
})
|
||||
|
||||
it('supports the full 1..64 range (issue #20)', () => {
|
||||
it('increments a side with the + stepper button', () => {
|
||||
const { onSubmit } = renderModal({ initial: BASE })
|
||||
const slider = screen.getByLabelText('Bottom connection points slider') as HTMLInputElement
|
||||
expect(slider.min).toBe('1')
|
||||
expect(slider.max).toBe('64')
|
||||
fireEvent.change(slider, { target: { value: '52' } })
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Increase Right connection points' }))
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Increase Right connection points' }))
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Add' }))
|
||||
expect((onSubmit.mock.calls[0][0] as Partial<NodeData>).right_handles).toBe(2)
|
||||
})
|
||||
|
||||
it('disables the − button at the side minimum (0 for left/right, 1 for top/bottom)', () => {
|
||||
renderModal({ initial: BASE })
|
||||
expect((screen.getByRole('button', { name: 'Decrease Left connection points' }) as HTMLButtonElement).disabled).toBe(true)
|
||||
expect((screen.getByRole('button', { name: 'Decrease Top connection points' }) as HTMLButtonElement).disabled).toBe(true)
|
||||
})
|
||||
|
||||
it('left/right min is 0, top/bottom min is 1; max is 64 everywhere', () => {
|
||||
renderModal({ initial: BASE })
|
||||
expect((screen.getByLabelText('Bottom connection points') as HTMLInputElement).min).toBe('1')
|
||||
expect((screen.getByLabelText('Left connection points') as HTMLInputElement).min).toBe('0')
|
||||
for (const label of ['Top', 'Right', 'Bottom', 'Left']) {
|
||||
expect((screen.getByLabelText(`${label} connection points`) as HTMLInputElement).max).toBe('64')
|
||||
}
|
||||
})
|
||||
|
||||
it('supports the full range up to 64 (issue #20)', () => {
|
||||
const { onSubmit } = renderModal({ initial: BASE })
|
||||
fireEvent.change(screen.getByLabelText('Bottom connection points'), { target: { value: '52' } })
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Add' }))
|
||||
expect((onSubmit.mock.calls[0][0] as Partial<NodeData>).bottom_handles).toBe(52)
|
||||
})
|
||||
|
||||
it('clamps pre-filled out-of-range values into [1,64]', () => {
|
||||
it('clamps pre-filled out-of-range values into range', () => {
|
||||
renderModal({ initial: { ...BASE, bottom_handles: 9999 } })
|
||||
const slider = screen.getByLabelText('Bottom connection points slider') as HTMLInputElement
|
||||
expect(slider.value).toBe('64')
|
||||
expect((screen.getByLabelText('Bottom connection points') as HTMLInputElement).value).toBe('64')
|
||||
})
|
||||
|
||||
it('toggles show_port_numbers and submits it (issue #20)', () => {
|
||||
|
||||
Reference in New Issue
Block a user