mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-25 01:40:45 +00:00
Extracts major UI panels, file transfer, terminal controls, and SFTP logic into dedicated subcomponents for improved maintainability and clarity. Modularizes Electron main process, delegating SSH, SFTP, terminal, port forwarding, and window management to bridge modules, reducing complexity and centralizing IPC registration. Enables easier future development, clearer separation of concerns, and better scalability by making both frontend and backend architectures more modular and easier to reason about.
150 lines
6.3 KiB
TypeScript
150 lines
6.3 KiB
TypeScript
/**
|
|
* Port Forwarding Rule Card
|
|
* Displays a single port forwarding rule in grid or list view
|
|
*/
|
|
import React from 'react';
|
|
import { Play, Square, Loader2, Pencil, Copy, Trash2 } from 'lucide-react';
|
|
import { PortForwardingRule } from '../../domain/models';
|
|
import { Button } from '../ui/button';
|
|
import { ContextMenu, ContextMenuContent, ContextMenuItem, ContextMenuTrigger, ContextMenuSeparator } from '../ui/context-menu';
|
|
import { cn } from '../../lib/utils';
|
|
import { getStatusColor, getTypeColor } from './utils';
|
|
|
|
export type ViewMode = 'grid' | 'list';
|
|
|
|
export interface RuleCardProps {
|
|
rule: PortForwardingRule;
|
|
viewMode: ViewMode;
|
|
isSelected: boolean;
|
|
isPending: boolean;
|
|
onSelect: () => void;
|
|
onEdit: () => void;
|
|
onDuplicate: () => void;
|
|
onDelete: () => void;
|
|
onStart: () => void;
|
|
onStop: () => void;
|
|
}
|
|
|
|
export const RuleCard: React.FC<RuleCardProps> = ({
|
|
rule,
|
|
viewMode,
|
|
isSelected,
|
|
isPending,
|
|
onSelect,
|
|
onEdit,
|
|
onDuplicate,
|
|
onDelete,
|
|
onStart,
|
|
onStop,
|
|
}) => {
|
|
const isActive = rule.status === 'active';
|
|
const isInactive = rule.status === 'inactive' || rule.status === 'error';
|
|
|
|
return (
|
|
<ContextMenu>
|
|
<ContextMenuTrigger>
|
|
<div
|
|
className={cn(
|
|
"group cursor-pointer",
|
|
viewMode === 'grid'
|
|
? "soft-card elevate rounded-xl h-[68px] px-3 py-2"
|
|
: "h-14 px-3 py-2 hover:bg-secondary/60 rounded-lg transition-colors",
|
|
isSelected && "ring-2 ring-primary"
|
|
)}
|
|
onClick={onSelect}
|
|
>
|
|
<div className="flex items-center gap-3 h-full">
|
|
<div className={cn(
|
|
"h-11 w-11 rounded-xl flex items-center justify-center text-sm font-bold transition-colors",
|
|
getTypeColor(rule.type, isActive)
|
|
)}>
|
|
{rule.type[0].toUpperCase()}
|
|
</div>
|
|
<div className="flex-1 min-w-0">
|
|
<div className="flex items-center gap-2">
|
|
<span className="text-sm font-semibold truncate">{rule.label}</span>
|
|
<span
|
|
className={cn(
|
|
"h-2 w-2 rounded-full flex-shrink-0",
|
|
getStatusColor(rule.status)
|
|
)}
|
|
title={rule.status === 'error' && rule.error ? rule.error : undefined}
|
|
/>
|
|
</div>
|
|
<div className="flex items-center gap-2 text-[11px] text-muted-foreground">
|
|
<span className="truncate">
|
|
{rule.type === 'dynamic'
|
|
? `SOCKS on ${rule.bindAddress}:${rule.localPort}`
|
|
: `${rule.bindAddress}:${rule.localPort} → ${rule.remoteHost}:${rule.remotePort}`
|
|
}
|
|
</span>
|
|
</div>
|
|
</div>
|
|
<div className="flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity">
|
|
{isPending ? (
|
|
<Button
|
|
size="icon"
|
|
variant="ghost"
|
|
className="h-7 w-7"
|
|
disabled
|
|
>
|
|
<Loader2 size={12} className="animate-spin" />
|
|
</Button>
|
|
) : isInactive ? (
|
|
<Button
|
|
size="icon"
|
|
variant="ghost"
|
|
className="h-7 w-7"
|
|
onClick={(e) => {
|
|
e.stopPropagation();
|
|
onStart();
|
|
}}
|
|
>
|
|
<Play size={12} />
|
|
</Button>
|
|
) : (rule.status === 'active' || rule.status === 'connecting') ? (
|
|
<Button
|
|
size="icon"
|
|
variant="ghost"
|
|
className="h-7 w-7"
|
|
onClick={(e) => {
|
|
e.stopPropagation();
|
|
onStop();
|
|
}}
|
|
>
|
|
<Square size={12} />
|
|
</Button>
|
|
) : null}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</ContextMenuTrigger>
|
|
<ContextMenuContent>
|
|
<ContextMenuItem onClick={onEdit}>
|
|
<Pencil className="mr-2 h-4 w-4" /> Edit
|
|
</ContextMenuItem>
|
|
<ContextMenuItem onClick={onDuplicate}>
|
|
<Copy className="mr-2 h-4 w-4" /> Duplicate
|
|
</ContextMenuItem>
|
|
<ContextMenuSeparator />
|
|
{isInactive && (
|
|
<ContextMenuItem onClick={onStart}>
|
|
<Play className="mr-2 h-4 w-4" /> Start
|
|
</ContextMenuItem>
|
|
)}
|
|
{(rule.status === 'active' || rule.status === 'connecting') && (
|
|
<ContextMenuItem onClick={onStop}>
|
|
<Square className="mr-2 h-4 w-4" /> Stop
|
|
</ContextMenuItem>
|
|
)}
|
|
<ContextMenuSeparator />
|
|
<ContextMenuItem className="text-destructive" onClick={onDelete}>
|
|
<Trash2 className="mr-2 h-4 w-4" /> Delete
|
|
</ContextMenuItem>
|
|
</ContextMenuContent>
|
|
</ContextMenu>
|
|
);
|
|
};
|
|
|
|
export default RuleCard;
|