mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-17 04:50:52 +00:00
* Fix #954: unify Tooltip styling + replace native selects Replace native HTML title= tooltips and native <select> dropdowns with the existing Radix-based Tooltip / Select components so they share the app's rounded styling, theme tokens and i18n pipeline. Adds a global TooltipProvider in AppWithProviders so every descendant Tooltip works without a per-file Provider wrapper. Scope (driven by the issue #954 examples and "全部都处理" follow-up): - TerminalLayer toolbar: Add Terminal / Split View / SFTP / Scripts / Theme / AI Chat / Move panel / Close panel. - TopTabs middle bar: quick switcher, more tabs, AI assistant, theme toggle, settings; window-control buttons (min/max/close), tray close and hotkey reset/disable have their native title dropped per the user's explicit opt-out ("可以不用Tooltip,直接全局禁用 原生title 属性"). - AI panels: AIChatSidePanel session history / new chat / delete, ConversationExport, AgentSelector, ChatInput attach / expand / permission, ModelSelector, ProviderCard, ai-elements/tool-call. - SFTP: SftpSidePanel header, SftpBreadcrumb, SftpFileRow, SftpPaneToolbar, SftpTabBar, SftpTransferQueue. - Settings: SettingsPage close, SettingsAppearanceTab theme/accent swatches, SettingsFileAssociationsTab edit/remove, SettingsSystemTab crash-log paths and global hotkey reset. - Host vault: HostDetailsPanel (clear / suggestions / show-password / key path / browse key), GroupDetailsPanel, KnownHostsManager, ConnectionLogsManager, KeychainManager, SyncStatusButton, CloudSyncSettings, LogView, QuickSwitcher, ScriptsSidePanel, Terminal status bar copy-host + broadcast/focus, ZmodemProgressIndicator. - Terminal subcomponents: HostKeywordHighlightPopover, TerminalComposeBar, TerminalConnectionDialog, TerminalSearchBar. - Editor: TextEditorPane (subtitle, search, wrap, promote-to-tab). - TrayPanel session rows and port-forwarding rows. Native <select> migrated to custom Select component: - SerialConnectModal (data bits, stop bits, parity, flow control) - SerialHostDetailsPanel (same four fields) - HostDetailsPanel backspace behavior - GroupDetailsPanel backspace behavior - SettingsTerminalTab local shell picker - terminal/ThemeSidePanel font weight Hardcoded English strings extracted to i18n. New keys for both en and zh-CN: terminal.layer.*, topTabs.*, ai.chat.* (sessionHistory, attach, collapse, expand, enableAgent), zmodem.*, settings.shortcuts. resetToDefault. Inline help text on SnippetsManager package-name input removed because the same hint is already shown in a visible <p> below the input. Existing per-file <TooltipProvider> wrappers (SnippetsManager, ScriptsSidePanel, SelectHostPanel, RuleCard, HostDetailsPanel proxy section) are left in place — they nest harmlessly under the global provider and stay self-sufficient for component tests. Tests: - tsc clean for changed files (pre-existing repo-wide errors unrelated to this PR). - All 802 tests pass (3 skipped pre-existing). - HostDetailsPanel.proxyProfile.test and TextEditorPane.test updated to wrap with TooltipProvider, matching the runtime context now needed by the migrated components. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * Fix #954: wrap Settings + Tray windows with TooltipProvider Settings and the tray panel mount as separate Electron windows with their own React root in index.tsx, so they do not inherit the global TooltipProvider added under AppWithProviders. After the unified Tooltip migration, any settings tab that used a Tooltip (Appearance, Application, FileAssociations, System, Shortcuts, Terminal, AI ProviderCard, AI ModelSelector) — and TrayPanel — threw "Tooltip must be used within TooltipProvider" and rendered nothing. Wrap both branches with TooltipProvider at the same level as ToastProvider in index.tsx. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
195 lines
9.6 KiB
TypeScript
195 lines
9.6 KiB
TypeScript
/**
|
|
* Port Forwarding Rule Card
|
|
* Displays a single port forwarding rule in grid or list view
|
|
*/
|
|
import { Copy,Loader2,Pencil,Play,Square,Trash2 } from 'lucide-react';
|
|
import React from 'react';
|
|
import { useI18n } from '../../application/i18n/I18nProvider';
|
|
import { Host, PortForwardingRule } from '../../domain/models';
|
|
import { cn } from '../../lib/utils';
|
|
import { Button } from '../ui/button';
|
|
import { ContextMenu,ContextMenuContent,ContextMenuItem,ContextMenuSeparator,ContextMenuTrigger } from '../ui/context-menu';
|
|
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '../ui/tooltip';
|
|
import { getStatusColor,getTypeColor } from './utils';
|
|
|
|
export type ViewMode = 'grid' | 'list';
|
|
|
|
export interface RuleCardProps {
|
|
rule: PortForwardingRule;
|
|
host?: Host; // The relay host for this rule (for tooltip display)
|
|
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,
|
|
host,
|
|
viewMode,
|
|
isSelected,
|
|
isPending,
|
|
onSelect,
|
|
onEdit,
|
|
onDuplicate,
|
|
onDelete,
|
|
onStart,
|
|
onStop,
|
|
}) => {
|
|
const { t } = useI18n();
|
|
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>
|
|
{rule.status === 'error' && rule.error ? (
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<span
|
|
className={cn(
|
|
"h-2 w-2 rounded-full flex-shrink-0 cursor-default",
|
|
getStatusColor(rule.status)
|
|
)}
|
|
/>
|
|
</TooltipTrigger>
|
|
<TooltipContent>{rule.error}</TooltipContent>
|
|
</Tooltip>
|
|
) : (
|
|
<span
|
|
className={cn(
|
|
"h-2 w-2 rounded-full flex-shrink-0",
|
|
getStatusColor(rule.status)
|
|
)}
|
|
/>
|
|
)}
|
|
</div>
|
|
<div className="flex items-center gap-2 text-[11px] text-muted-foreground">
|
|
<TooltipProvider delayDuration={300}>
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<span className="truncate cursor-default">
|
|
{rule.type === 'dynamic'
|
|
? t('pf.rule.summary.dynamic', { bindAddress: rule.bindAddress, localPort: rule.localPort })
|
|
: t('pf.rule.summary.default', { bindAddress: rule.bindAddress, localPort: rule.localPort, remoteHost: rule.remoteHost, remotePort: rule.remotePort })
|
|
}
|
|
</span>
|
|
</TooltipTrigger>
|
|
<TooltipContent side="bottom" align="start" className="max-w-xs">
|
|
<div className="space-y-1 text-xs">
|
|
{host ? (
|
|
<>
|
|
<div className="font-medium">{t('pf.tooltip.relayHost')}</div>
|
|
<div>{t('pf.tooltip.hostLabel')}: {host.label}</div>
|
|
<div>{t('pf.tooltip.hostAddress')}: {host.username}@{host.hostname}:{host.port}</div>
|
|
</>
|
|
) : (
|
|
<div className="text-muted-foreground">{t('pf.tooltip.noHost')}</div>
|
|
)}
|
|
<div className="border-t border-border/40 pt-1 mt-1">
|
|
{rule.type === 'dynamic'
|
|
? t('pf.tooltip.dynamicDesc')
|
|
: rule.type === 'local'
|
|
? t('pf.tooltip.localDesc')
|
|
: t('pf.tooltip.remoteDesc')
|
|
}
|
|
</div>
|
|
</div>
|
|
</TooltipContent>
|
|
</Tooltip>
|
|
</TooltipProvider>
|
|
</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" /> {t('action.edit')}
|
|
</ContextMenuItem>
|
|
<ContextMenuItem onClick={onDuplicate}>
|
|
<Copy className="mr-2 h-4 w-4" /> {t('action.duplicate')}
|
|
</ContextMenuItem>
|
|
<ContextMenuSeparator />
|
|
{isInactive && (
|
|
<ContextMenuItem onClick={onStart}>
|
|
<Play className="mr-2 h-4 w-4" /> {t('action.start')}
|
|
</ContextMenuItem>
|
|
)}
|
|
{(rule.status === 'active' || rule.status === 'connecting') && (
|
|
<ContextMenuItem onClick={onStop}>
|
|
<Square className="mr-2 h-4 w-4" /> {t('action.stop')}
|
|
</ContextMenuItem>
|
|
)}
|
|
<ContextMenuSeparator />
|
|
<ContextMenuItem className="text-destructive" onClick={onDelete}>
|
|
<Trash2 className="mr-2 h-4 w-4" /> {t('action.delete')}
|
|
</ContextMenuItem>
|
|
</ContextMenuContent>
|
|
</ContextMenu>
|
|
);
|
|
};
|
|
|
|
export default RuleCard;
|