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>
206 lines
8.8 KiB
TypeScript
206 lines
8.8 KiB
TypeScript
/**
|
|
* Port Forwarding New Form Panel
|
|
* All-in-one form for creating new port forwarding rules (skip wizard mode)
|
|
*/
|
|
import { ChevronDown,Zap } from 'lucide-react';
|
|
import React from 'react';
|
|
import { useI18n } from '../../application/i18n/I18nProvider';
|
|
import { Host,PortForwardingRule,PortForwardingType } from '../../domain/models';
|
|
import { cn } from '../../lib/utils';
|
|
import { DistroAvatar } from '../DistroAvatar';
|
|
import { TrafficDiagram } from '../TrafficDiagram';
|
|
import { AsidePanel,AsidePanelContent,AsidePanelFooter } from '../ui/aside-panel';
|
|
import { Button } from '../ui/button';
|
|
import { Input } from '../ui/input';
|
|
import { Tooltip, TooltipContent, TooltipTrigger } from '../ui/tooltip';
|
|
import { Label } from '../ui/label';
|
|
import { Switch } from '../ui/switch';
|
|
import { getTypeLabel } from './utils';
|
|
|
|
export interface NewFormPanelProps {
|
|
draft: Partial<PortForwardingRule>;
|
|
hosts: Host[];
|
|
onDraftChange: (updates: Partial<PortForwardingRule>) => void;
|
|
onSave: () => void;
|
|
onClose: () => void;
|
|
onOpenHostSelector: () => void;
|
|
onOpenWizard: () => void;
|
|
isValid: boolean;
|
|
}
|
|
|
|
export const NewFormPanel: React.FC<NewFormPanelProps> = ({
|
|
draft,
|
|
hosts,
|
|
onDraftChange,
|
|
onSave,
|
|
onClose,
|
|
onOpenHostSelector,
|
|
onOpenWizard,
|
|
isValid,
|
|
}) => {
|
|
const { t } = useI18n();
|
|
const selectedHost = hosts.find(h => h.id === draft.hostId);
|
|
|
|
return (
|
|
<AsidePanel
|
|
open={true}
|
|
onClose={onClose}
|
|
title={t('pf.wizard.newTitle')}
|
|
width="w-[360px]"
|
|
>
|
|
<AsidePanelContent>
|
|
{/* Type Selector */}
|
|
<div className="flex gap-1 p-1 bg-secondary/80 rounded-lg border border-border/60">
|
|
{(['local', 'remote', 'dynamic'] as PortForwardingType[]).map((type) => (
|
|
<Button
|
|
key={type}
|
|
variant={draft.type === type ? 'default' : 'ghost'}
|
|
size="sm"
|
|
className={cn(
|
|
"flex-1 h-9",
|
|
draft.type === type ? "bg-primary text-primary-foreground" : ""
|
|
)}
|
|
onClick={() => onDraftChange({ type })}
|
|
>
|
|
{getTypeLabel(t, type)}
|
|
</Button>
|
|
))}
|
|
</div>
|
|
|
|
{/* Traffic Diagram */}
|
|
<div className="-my-1">
|
|
<TrafficDiagram type={draft.type || 'local'} isAnimating={true} />
|
|
</div>
|
|
|
|
{/* Label */}
|
|
<div className="space-y-1">
|
|
<Label className="text-[10px] text-muted-foreground">{t('field.label')}</Label>
|
|
<Input
|
|
placeholder={t('pf.form.labelPlaceholder')}
|
|
className="h-10"
|
|
value={draft.label || ''}
|
|
onChange={e => onDraftChange({ label: e.target.value })}
|
|
/>
|
|
</div>
|
|
|
|
{/* Local Port */}
|
|
<div className="space-y-1">
|
|
<Label className="text-[10px] text-muted-foreground">{t('pf.wizard.localConfig.localPort')}</Label>
|
|
<Input
|
|
type="number"
|
|
placeholder={t('pf.wizard.placeholders.portExample', { port: 8080 })}
|
|
className="h-10"
|
|
value={draft.localPort || ''}
|
|
onChange={e => onDraftChange({ localPort: parseInt(e.target.value) || undefined })}
|
|
/>
|
|
</div>
|
|
|
|
{/* Bind Address */}
|
|
<div className="space-y-1">
|
|
<Label className="text-[10px] text-muted-foreground">{t('pf.wizard.bindAddress')}</Label>
|
|
<Input
|
|
placeholder="127.0.0.1"
|
|
className="h-10"
|
|
value={draft.bindAddress || ''}
|
|
onChange={e => onDraftChange({ bindAddress: e.target.value })}
|
|
/>
|
|
</div>
|
|
|
|
{/* Intermediate Host */}
|
|
<div className="space-y-1">
|
|
<Label className="text-[10px] text-muted-foreground">{t('pf.form.intermediateHost')}</Label>
|
|
<Button
|
|
variant="secondary"
|
|
className="w-full h-10 justify-between"
|
|
onClick={onOpenHostSelector}
|
|
>
|
|
{selectedHost ? (
|
|
<div className="flex items-center gap-2">
|
|
<DistroAvatar
|
|
host={selectedHost}
|
|
fallback={selectedHost.os[0].toUpperCase()}
|
|
className="h-6 w-6"
|
|
/>
|
|
<span>{selectedHost.label}</span>
|
|
</div>
|
|
) : (
|
|
<span className="text-muted-foreground">{t('common.selectAHost')}</span>
|
|
)}
|
|
<ChevronDown size={14} />
|
|
</Button>
|
|
</div>
|
|
|
|
{/* Destination - for local/remote only */}
|
|
{(draft.type === 'local' || draft.type === 'remote') && (
|
|
<>
|
|
<div className="space-y-1">
|
|
<Label className="text-[10px] text-muted-foreground">{t('pf.wizard.destination.address')}</Label>
|
|
<Input
|
|
placeholder={t('pf.wizard.destination.addressPlaceholder')}
|
|
className="h-10"
|
|
value={draft.remoteHost || ''}
|
|
onChange={e => onDraftChange({ remoteHost: e.target.value })}
|
|
/>
|
|
</div>
|
|
|
|
<div className="space-y-1">
|
|
<Label className="text-[10px] text-muted-foreground">{t('pf.wizard.destination.port')}</Label>
|
|
<Input
|
|
type="number"
|
|
placeholder={t('pf.wizard.placeholders.portExample', { port: 3306 })}
|
|
className="h-10"
|
|
value={draft.remotePort || ''}
|
|
onChange={e => onDraftChange({ remotePort: parseInt(e.target.value) || undefined })}
|
|
/>
|
|
</div>
|
|
</>
|
|
)}
|
|
|
|
{/* Auto Start Toggle */}
|
|
<div className="flex items-center justify-between py-2">
|
|
<div className="space-y-0.5">
|
|
<Label className="text-sm font-medium">{t('pf.form.autoStart')}</Label>
|
|
<p className="text-[10px] text-muted-foreground">{t('pf.form.autoStartDesc')}</p>
|
|
</div>
|
|
<Switch
|
|
checked={draft.autoStart ?? false}
|
|
onCheckedChange={checked => onDraftChange({ autoStart: checked })}
|
|
/>
|
|
</div>
|
|
</AsidePanelContent>
|
|
<AsidePanelFooter className="space-y-2">
|
|
<Button
|
|
className="w-full h-10"
|
|
disabled={!isValid}
|
|
onClick={onSave}
|
|
>
|
|
{t('pf.form.createRule')}
|
|
</Button>
|
|
<div className="flex items-center justify-between">
|
|
<Button
|
|
variant="ghost"
|
|
className="h-10 text-muted-foreground hover:text-foreground hover:bg-foreground/5"
|
|
onClick={onClose}
|
|
>
|
|
{t('common.cancel')}
|
|
</Button>
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<button
|
|
className="text-xs text-muted-foreground hover:text-foreground/80 flex items-center gap-1 px-2 py-1 rounded hover:bg-foreground/5 transition-colors"
|
|
onClick={onOpenWizard}
|
|
>
|
|
<Zap size={12} />
|
|
{t('pf.form.openWizard')}
|
|
</button>
|
|
</TooltipTrigger>
|
|
<TooltipContent>{t('pf.form.openWizardTitle')}</TooltipContent>
|
|
</Tooltip>
|
|
</div>
|
|
</AsidePanelFooter>
|
|
</AsidePanel>
|
|
);
|
|
};
|
|
|
|
export default NewFormPanel;
|