mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-26 02:31:40 +00:00
refactor(ui): extract shared VaultHostCard and InlineRenameInput components (#4393)
This commit is contained in:
8 files changed
+645
-690
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import React, { useEffect, useRef, useState } from 'react';
|
||||
import React from 'react';
|
||||
|
||||
import { cn } from '../../lib/utils';
|
||||
import { InlineRenameInput } from '../ui/inline-rename-input';
|
||||
|
||||
type HostTreeGroupInlineRenameInputProps = {
|
||||
initialName: string;
|
||||
@@ -10,77 +10,11 @@ type HostTreeGroupInlineRenameInputProps = {
|
||||
style?: React.CSSProperties;
|
||||
};
|
||||
|
||||
export const HostTreeGroupInlineRenameInput: React.FC<HostTreeGroupInlineRenameInputProps> = ({
|
||||
initialName,
|
||||
onCommit,
|
||||
onCancel,
|
||||
className,
|
||||
style,
|
||||
}) => {
|
||||
const inputRef = useRef<HTMLInputElement>(null);
|
||||
const [value, setValue] = useState(initialName);
|
||||
const submittingRef = useRef(false);
|
||||
|
||||
useEffect(() => {
|
||||
const input = inputRef.current;
|
||||
if (!input) return;
|
||||
input.focus();
|
||||
input.select();
|
||||
}, []);
|
||||
|
||||
const commit = async () => {
|
||||
if (submittingRef.current) return;
|
||||
submittingRef.current = true;
|
||||
try {
|
||||
const committed = await onCommit(value);
|
||||
if (committed === false) submittingRef.current = false;
|
||||
} catch {
|
||||
submittingRef.current = false;
|
||||
}
|
||||
};
|
||||
|
||||
const cancel = () => {
|
||||
if (submittingRef.current) return;
|
||||
submittingRef.current = true;
|
||||
onCancel();
|
||||
};
|
||||
|
||||
return (
|
||||
<input
|
||||
ref={inputRef}
|
||||
data-inline-group-edit="true"
|
||||
value={value}
|
||||
draggable={false}
|
||||
onChange={(event) => setValue(event.target.value)}
|
||||
onBlur={() => {
|
||||
queueMicrotask(() => {
|
||||
void commit();
|
||||
});
|
||||
}}
|
||||
onClick={(event) => event.stopPropagation()}
|
||||
onDoubleClick={(event) => event.stopPropagation()}
|
||||
onMouseDown={(event) => event.stopPropagation()}
|
||||
onPointerDown={(event) => event.stopPropagation()}
|
||||
onDragStart={(event) => {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
}}
|
||||
onKeyDown={(event) => {
|
||||
event.stopPropagation();
|
||||
if (event.key === 'Enter') {
|
||||
event.preventDefault();
|
||||
void commit();
|
||||
}
|
||||
if (event.key === 'Escape') {
|
||||
event.preventDefault();
|
||||
cancel();
|
||||
}
|
||||
}}
|
||||
className={cn(
|
||||
'min-w-0 flex-1 truncate select-text rounded-sm border border-primary/50 bg-background/80 px-1 py-0 text-sm font-medium outline-none ring-1 ring-primary/30',
|
||||
className,
|
||||
)}
|
||||
style={style}
|
||||
/>
|
||||
);
|
||||
};
|
||||
export const HostTreeGroupInlineRenameInput: React.FC<HostTreeGroupInlineRenameInputProps> = (
|
||||
props,
|
||||
) => (
|
||||
<InlineRenameInput
|
||||
data-inline-group-edit="true"
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
@@ -1,6 +1,6 @@
|
||||
import React, { useEffect, useRef, useState } from 'react';
|
||||
import React from 'react';
|
||||
|
||||
import { cn } from '../../lib/utils';
|
||||
import { InlineRenameInput } from '../ui/inline-rename-input';
|
||||
|
||||
type SessionInlineRenameInputProps = {
|
||||
initialName: string;
|
||||
@@ -10,72 +10,11 @@ type SessionInlineRenameInputProps = {
|
||||
style?: React.CSSProperties;
|
||||
};
|
||||
|
||||
export const SessionInlineRenameInput: React.FC<SessionInlineRenameInputProps> = ({
|
||||
initialName,
|
||||
onCommit,
|
||||
onCancel,
|
||||
className,
|
||||
style,
|
||||
}) => {
|
||||
const inputRef = useRef<HTMLInputElement>(null);
|
||||
const [value, setValue] = useState(initialName);
|
||||
const committedRef = useRef(false);
|
||||
|
||||
useEffect(() => {
|
||||
const input = inputRef.current;
|
||||
if (!input) return;
|
||||
input.focus();
|
||||
input.select();
|
||||
}, []);
|
||||
|
||||
const commit = () => {
|
||||
if (committedRef.current) return;
|
||||
committedRef.current = true;
|
||||
onCommit(value);
|
||||
};
|
||||
|
||||
const cancel = () => {
|
||||
if (committedRef.current) return;
|
||||
committedRef.current = true;
|
||||
onCancel();
|
||||
};
|
||||
|
||||
return (
|
||||
<input
|
||||
ref={inputRef}
|
||||
data-session-inline-rename="true"
|
||||
value={value}
|
||||
draggable={false}
|
||||
onChange={(event) => setValue(event.target.value)}
|
||||
onBlur={() => {
|
||||
queueMicrotask(() => {
|
||||
commit();
|
||||
});
|
||||
}}
|
||||
onClick={(event) => event.stopPropagation()}
|
||||
onDoubleClick={(event) => event.stopPropagation()}
|
||||
onMouseDown={(event) => event.stopPropagation()}
|
||||
onPointerDown={(event) => event.stopPropagation()}
|
||||
onDragStart={(event) => {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
}}
|
||||
onKeyDown={(event) => {
|
||||
event.stopPropagation();
|
||||
if (event.key === 'Enter') {
|
||||
event.preventDefault();
|
||||
commit();
|
||||
}
|
||||
if (event.key === 'Escape') {
|
||||
event.preventDefault();
|
||||
cancel();
|
||||
}
|
||||
}}
|
||||
className={cn(
|
||||
'min-w-0 flex-1 truncate select-text rounded-sm border border-primary/50 bg-background/80 px-1 py-0 text-sm font-medium outline-none ring-1 ring-primary/30',
|
||||
className,
|
||||
)}
|
||||
style={style}
|
||||
/>
|
||||
);
|
||||
};
|
||||
export const SessionInlineRenameInput: React.FC<SessionInlineRenameInputProps> = (
|
||||
props,
|
||||
) => (
|
||||
<InlineRenameInput
|
||||
data-session-inline-rename="true"
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
@@ -0,0 +1,114 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import React from "react";
|
||||
import { renderToStaticMarkup } from "react-dom/server";
|
||||
import { act, create, type ReactTestRenderer } from "react-test-renderer";
|
||||
|
||||
import { HostTreeGroupInlineRenameInput } from "../host/HostTreeGroupInlineRenameInput";
|
||||
import { SessionInlineRenameInput } from "../terminal/SessionInlineRenameInput";
|
||||
import { VaultTreeInlineRenameInput } from "../vault/VaultTreeRow";
|
||||
import { InlineRenameInput } from "./inline-rename-input";
|
||||
|
||||
test("inline rename wrappers preserve exact data attributes", () => {
|
||||
const groupMarkup = renderToStaticMarkup(
|
||||
<HostTreeGroupInlineRenameInput initialName="Prod" onCommit={() => {}} onCancel={() => {}} />,
|
||||
);
|
||||
assert.match(groupMarkup, /data-inline-group-edit="true"/);
|
||||
assert.doesNotMatch(groupMarkup, /data-vault-tree-inline-edit/);
|
||||
|
||||
const vaultTreeMarkup = renderToStaticMarkup(
|
||||
<VaultTreeInlineRenameInput initialName="Staging" onCommit={() => {}} onCancel={() => {}} />,
|
||||
);
|
||||
assert.match(vaultTreeMarkup, /data-vault-tree-inline-edit="true"/);
|
||||
assert.match(vaultTreeMarkup, /data-inline-group-edit="true"/);
|
||||
|
||||
const sessionMarkup = renderToStaticMarkup(
|
||||
<SessionInlineRenameInput initialName="web-1" onCommit={() => {}} onCancel={() => {}} />,
|
||||
);
|
||||
assert.match(sessionMarkup, /data-session-inline-rename="true"/);
|
||||
});
|
||||
|
||||
test("InlineRenameInput handles Enter, Escape, blur queueMicrotask, stopPropagation, and async retry", async () => {
|
||||
const actEnv = globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT?: boolean };
|
||||
const prevAct = actEnv.IS_REACT_ACT_ENVIRONMENT;
|
||||
actEnv.IS_REACT_ACT_ENVIRONMENT = true;
|
||||
let renderer: ReactTestRenderer | null = null;
|
||||
|
||||
try {
|
||||
// 1. Escape cancels once and suppresses subsequent blur commit.
|
||||
let commits = 0;
|
||||
let cancels = 0;
|
||||
await act(async () => {
|
||||
renderer = create(
|
||||
<InlineRenameInput
|
||||
initialName="alpha"
|
||||
onCommit={() => {
|
||||
commits += 1;
|
||||
}}
|
||||
onCancel={() => {
|
||||
cancels += 1;
|
||||
}}
|
||||
/>,
|
||||
);
|
||||
});
|
||||
const input = renderer!.root.findByType("input");
|
||||
let stopped = 0;
|
||||
let prevented = 0;
|
||||
const stopPropagation = () => { stopped += 1; };
|
||||
const preventDefault = () => { prevented += 1; };
|
||||
input.props.onClick({ stopPropagation });
|
||||
input.props.onDoubleClick({ stopPropagation });
|
||||
input.props.onMouseDown({ stopPropagation });
|
||||
input.props.onPointerDown({ stopPropagation });
|
||||
input.props.onDragStart({ stopPropagation, preventDefault });
|
||||
assert.equal(stopped, 5);
|
||||
assert.equal(prevented, 1);
|
||||
|
||||
await act(async () => {
|
||||
input.props.onKeyDown({ key: "Escape", stopPropagation, preventDefault });
|
||||
input.props.onBlur();
|
||||
await Promise.resolve();
|
||||
});
|
||||
assert.equal(cancels, 1);
|
||||
assert.equal(commits, 0);
|
||||
|
||||
// 2. Blur commits via queueMicrotask and resets submittingRef when onCommit rejects or returns false.
|
||||
let blurAttempts = 0;
|
||||
let committedValue = "";
|
||||
await act(async () => {
|
||||
renderer!.unmount();
|
||||
renderer = create(
|
||||
<InlineRenameInput
|
||||
initialName="beta"
|
||||
onCommit={async (name) => {
|
||||
blurAttempts += 1;
|
||||
committedValue = name;
|
||||
if (blurAttempts === 1) return false;
|
||||
if (blurAttempts === 2) throw new Error("transient");
|
||||
return true;
|
||||
}}
|
||||
onCancel={() => {}}
|
||||
/>,
|
||||
);
|
||||
});
|
||||
const input2 = renderer!.root.findByType("input");
|
||||
await act(async () => {
|
||||
input2.props.onChange({ target: { value: "gamma" } });
|
||||
});
|
||||
for (let i = 0; i < 4; i += 1) {
|
||||
await act(async () => {
|
||||
input2.props.onBlur();
|
||||
await Promise.resolve();
|
||||
await Promise.resolve();
|
||||
});
|
||||
}
|
||||
// Attempts 1 (false) and 2 (throw) unlock; attempt 3 (true) locks so attempt 4 is skipped.
|
||||
assert.equal(blurAttempts, 3);
|
||||
assert.equal(committedValue, "gamma");
|
||||
} finally {
|
||||
await act(async () => {
|
||||
renderer?.unmount();
|
||||
});
|
||||
actEnv.IS_REACT_ACT_ENVIRONMENT = prevAct;
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,91 @@
|
||||
import React, { useEffect, useRef, useState } from "react";
|
||||
|
||||
import { cn } from "../../lib/utils";
|
||||
|
||||
type DataAttributes = {
|
||||
[K in `data-${string}`]?: string | boolean | undefined;
|
||||
};
|
||||
|
||||
export type InlineRenameInputProps = DataAttributes & {
|
||||
initialName: string;
|
||||
onCommit: (name: string) => boolean | void | Promise<boolean | void>;
|
||||
onCancel: () => void;
|
||||
className?: string;
|
||||
style?: React.CSSProperties;
|
||||
};
|
||||
|
||||
export const InlineRenameInput: React.FC<InlineRenameInputProps> = ({
|
||||
initialName,
|
||||
onCommit,
|
||||
onCancel,
|
||||
className,
|
||||
style,
|
||||
...dataProps
|
||||
}) => {
|
||||
const inputRef = useRef<HTMLInputElement>(null);
|
||||
const [value, setValue] = useState(initialName);
|
||||
const submittingRef = useRef(false);
|
||||
|
||||
useEffect(() => {
|
||||
const input = inputRef.current;
|
||||
if (!input) return;
|
||||
input.focus();
|
||||
input.select();
|
||||
}, []);
|
||||
|
||||
const commit = async () => {
|
||||
if (submittingRef.current) return;
|
||||
submittingRef.current = true;
|
||||
try {
|
||||
const committed = await onCommit(value);
|
||||
if (committed === false) submittingRef.current = false;
|
||||
} catch {
|
||||
submittingRef.current = false;
|
||||
}
|
||||
};
|
||||
|
||||
const cancel = () => {
|
||||
if (submittingRef.current) return;
|
||||
submittingRef.current = true;
|
||||
onCancel();
|
||||
};
|
||||
|
||||
return (
|
||||
<input
|
||||
ref={inputRef}
|
||||
{...dataProps}
|
||||
value={value}
|
||||
draggable={false}
|
||||
onChange={(event) => setValue(event.target.value)}
|
||||
onBlur={() => {
|
||||
queueMicrotask(() => {
|
||||
void commit();
|
||||
});
|
||||
}}
|
||||
onClick={(event) => event.stopPropagation()}
|
||||
onDoubleClick={(event) => event.stopPropagation()}
|
||||
onMouseDown={(event) => event.stopPropagation()}
|
||||
onPointerDown={(event) => event.stopPropagation()}
|
||||
onDragStart={(event) => {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
}}
|
||||
onKeyDown={(event) => {
|
||||
event.stopPropagation();
|
||||
if (event.key === "Enter") {
|
||||
event.preventDefault();
|
||||
void commit();
|
||||
}
|
||||
if (event.key === "Escape") {
|
||||
event.preventDefault();
|
||||
cancel();
|
||||
}
|
||||
}}
|
||||
className={cn(
|
||||
"min-w-0 flex-1 truncate select-text rounded-sm border border-primary/50 bg-background/80 px-1 py-0 text-sm font-medium outline-none ring-1 ring-primary/30",
|
||||
className,
|
||||
)}
|
||||
style={style}
|
||||
/>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,287 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import React from "react";
|
||||
|
||||
import { hostCardFocusClassName } from "../../domain/hostClickBehavior";
|
||||
import { getVaultHostRowSubtitle } from "../../domain/localShellHost";
|
||||
import type { Host } from "../../domain/models";
|
||||
import { isPluginHostProtocol } from "../../domain/pluginConnection";
|
||||
import { isVaultHostDraggable } from "../../domain/vaultHostDrag";
|
||||
import { HostNotesIndicator } from "../host/HostNotesIndicator";
|
||||
import { OpenDualPaneSftpMenuItem, OpenHostBrowserMenuItem } from "../host/HostTreeContextMenus";
|
||||
|
||||
export type VaultHostCardSection = "pinned" | "recent" | "grouped" | "main";
|
||||
|
||||
export interface VaultHostCardPrimitives {
|
||||
Badge: React.ComponentType<any>;
|
||||
CheckSquare: React.ComponentType<any>;
|
||||
ClipboardCopy: React.ComponentType<any>;
|
||||
cn: (...inputs: any[]) => string;
|
||||
ContextMenu: React.ComponentType<any>;
|
||||
ContextMenuContent: React.ComponentType<any>;
|
||||
ContextMenuItem: React.ComponentType<any>;
|
||||
ContextMenuTrigger: React.ComponentType<any>;
|
||||
Copy: React.ComponentType<any>;
|
||||
DistroAvatar: React.ComponentType<any>;
|
||||
Edit2: React.ComponentType<any>;
|
||||
Pin: React.ComponentType<any>;
|
||||
Plug: React.ComponentType<any>;
|
||||
Square: React.ComponentType<any>;
|
||||
Star: React.ComponentType<any>;
|
||||
Trash2: React.ComponentType<any>;
|
||||
}
|
||||
|
||||
export interface VaultHostContextMenuProps {
|
||||
host: Host;
|
||||
section: VaultHostCardSection;
|
||||
primitives: Pick<
|
||||
VaultHostCardPrimitives,
|
||||
| "ClipboardCopy"
|
||||
| "ContextMenuContent"
|
||||
| "ContextMenuItem"
|
||||
| "Copy"
|
||||
| "Edit2"
|
||||
| "Pin"
|
||||
| "Plug"
|
||||
| "Trash2"
|
||||
>;
|
||||
t: (key: string, params?: Record<string, unknown>) => string;
|
||||
onConnect: (host: Host) => void;
|
||||
onOpenBrowser?: (host: Host) => void;
|
||||
onEdit: (host: Host) => void;
|
||||
onDuplicate: (host: Host) => void;
|
||||
onCopyHostname: (host: Host) => void;
|
||||
onCopyCredentials: (host: Host) => void;
|
||||
onTogglePinned: (hostId: string) => void;
|
||||
onDelete: (hostId: string) => void;
|
||||
}
|
||||
|
||||
export const VaultHostContextMenu: React.FC<VaultHostContextMenuProps> = ({
|
||||
host,
|
||||
section,
|
||||
primitives,
|
||||
t,
|
||||
onConnect,
|
||||
onOpenBrowser,
|
||||
onEdit,
|
||||
onDuplicate,
|
||||
onCopyHostname,
|
||||
onCopyCredentials,
|
||||
onTogglePinned,
|
||||
onDelete,
|
||||
}) => {
|
||||
const {
|
||||
ClipboardCopy,
|
||||
ContextMenuContent,
|
||||
ContextMenuItem,
|
||||
Copy,
|
||||
Edit2,
|
||||
Pin,
|
||||
Plug,
|
||||
Trash2,
|
||||
} = primitives;
|
||||
const pinLabel = section === "pinned" || host.pinned
|
||||
? t("vault.hosts.unpin")
|
||||
: t("vault.hosts.pinToTop");
|
||||
|
||||
return (
|
||||
<ContextMenuContent>
|
||||
<ContextMenuItem onClick={() => onConnect(host)}>
|
||||
<Plug className="mr-2 h-4 w-4" /> {t("vault.hosts.connect")}
|
||||
</ContextMenuItem>
|
||||
<OpenDualPaneSftpMenuItem host={host} />
|
||||
<OpenHostBrowserMenuItem host={host} onOpenBrowser={onOpenBrowser} />
|
||||
<ContextMenuItem onClick={() => onEdit(host)}>
|
||||
<Edit2 className="mr-2 h-4 w-4" /> {t("action.edit")}
|
||||
</ContextMenuItem>
|
||||
<ContextMenuItem onClick={() => onDuplicate(host)}>
|
||||
<Copy className="mr-2 h-4 w-4" /> {t("action.duplicate")}
|
||||
</ContextMenuItem>
|
||||
{!isPluginHostProtocol(host.protocol) ? (
|
||||
<ContextMenuItem onClick={() => onCopyHostname(host)}>
|
||||
<Copy className="mr-2 h-4 w-4" /> {t("terminal.statusbar.copyHostname.label")}
|
||||
</ContextMenuItem>
|
||||
) : null}
|
||||
<ContextMenuItem onClick={() => onCopyCredentials(host)}>
|
||||
<ClipboardCopy className="mr-2 h-4 w-4" /> {t("vault.hosts.copyCredentials")}
|
||||
</ContextMenuItem>
|
||||
<ContextMenuItem onClick={() => onTogglePinned(host.id)}>
|
||||
<Pin className="mr-2 h-4 w-4" /> {pinLabel}
|
||||
</ContextMenuItem>
|
||||
<ContextMenuItem className="text-destructive" onClick={() => onDelete(host.id)}>
|
||||
<Trash2 className="mr-2 h-4 w-4" /> {t("action.delete")}
|
||||
</ContextMenuItem>
|
||||
</ContextMenuContent>
|
||||
);
|
||||
};
|
||||
|
||||
export interface VaultHostCardProps {
|
||||
host: Host;
|
||||
section: VaultHostCardSection;
|
||||
gridItemKey: string;
|
||||
viewMode: "list" | "grid";
|
||||
isMultiSelectMode: boolean;
|
||||
selectedHostIds: ReadonlySet<string>;
|
||||
draggingHostIds: ReadonlySet<string> | null;
|
||||
isFocusSelected: boolean;
|
||||
tabIndex: number;
|
||||
isPopInAnimated?: boolean;
|
||||
onPopInAnimationEnd?: () => void;
|
||||
sanitizeHost: (host: Host) => Host;
|
||||
getEffectiveHostDistro: (host: Host) => string | undefined;
|
||||
renderEditButton: (host: Host, compact?: boolean) => React.ReactNode;
|
||||
onDragStart: (e: React.DragEvent, hostId: string) => void;
|
||||
onActivate: (safeHost: Host) => void;
|
||||
onConnect: (host: Host) => void;
|
||||
onOpenBrowser?: (host: Host) => void;
|
||||
onEdit: (host: Host) => void;
|
||||
onDuplicate: (host: Host) => void;
|
||||
onCopyHostname: (host: Host) => void;
|
||||
onCopyCredentials: (host: Host) => void;
|
||||
onTogglePinned: (hostId: string) => void;
|
||||
onDelete: (hostId: string) => void;
|
||||
t: (key: string, params?: Record<string, unknown>) => string;
|
||||
primitives: VaultHostCardPrimitives;
|
||||
}
|
||||
|
||||
export const VaultHostCard: React.FC<VaultHostCardProps> = ({
|
||||
host,
|
||||
section,
|
||||
gridItemKey,
|
||||
viewMode,
|
||||
isMultiSelectMode,
|
||||
selectedHostIds,
|
||||
draggingHostIds,
|
||||
isFocusSelected,
|
||||
tabIndex,
|
||||
isPopInAnimated = false,
|
||||
onPopInAnimationEnd,
|
||||
sanitizeHost,
|
||||
getEffectiveHostDistro,
|
||||
renderEditButton,
|
||||
onDragStart,
|
||||
onActivate,
|
||||
onConnect,
|
||||
onOpenBrowser,
|
||||
onEdit,
|
||||
onDuplicate,
|
||||
onCopyHostname,
|
||||
onCopyCredentials,
|
||||
onTogglePinned,
|
||||
onDelete,
|
||||
t,
|
||||
primitives,
|
||||
}) => {
|
||||
const {
|
||||
Badge,
|
||||
CheckSquare,
|
||||
cn,
|
||||
ContextMenu,
|
||||
ContextMenuTrigger,
|
||||
DistroAvatar,
|
||||
Square,
|
||||
Star,
|
||||
} = primitives;
|
||||
|
||||
const safeHost = sanitizeHost(host);
|
||||
const effectiveDistro = getEffectiveHostDistro(safeHost);
|
||||
const distroBadge = {
|
||||
text: (safeHost.os || "L")[0].toUpperCase(),
|
||||
label: effectiveDistro || safeHost.os || "Linux",
|
||||
};
|
||||
const showGridStar = viewMode === "grid"
|
||||
&& (section === "pinned" || (section !== "recent" && Boolean(host.pinned)));
|
||||
const showManagedBadge = (section === "grouped" || section === "main")
|
||||
&& Boolean(safeHost.managedSourceId);
|
||||
const checkboxAriaHidden = section === "grouped" || section === "main" ? true : undefined;
|
||||
|
||||
return (
|
||||
<ContextMenu>
|
||||
<ContextMenuTrigger>
|
||||
<div
|
||||
className={cn(
|
||||
"vault-drop-indicator-row group cursor-pointer relative",
|
||||
viewMode === "grid"
|
||||
? cn(
|
||||
"soft-card elevate rounded-xl h-[68px] px-3 py-2 will-change-transform transition-[opacity,box-shadow,border-color,background-color] duration-150",
|
||||
draggingHostIds?.has(host.id) && "opacity-45",
|
||||
hostCardFocusClassName(viewMode, isFocusSelected),
|
||||
)
|
||||
: cn(
|
||||
"h-14 px-2 py-2 rounded-lg transition-colors",
|
||||
isFocusSelected
|
||||
? hostCardFocusClassName("list", true)
|
||||
: "hover:bg-secondary/60",
|
||||
),
|
||||
)}
|
||||
data-host-id={host.id}
|
||||
data-vault-grid-item={gridItemKey}
|
||||
role={isMultiSelectMode ? "checkbox" : "button"}
|
||||
aria-checked={isMultiSelectMode ? selectedHostIds.has(host.id) : undefined}
|
||||
tabIndex={tabIndex}
|
||||
style={isPopInAnimated
|
||||
? { animation: "pop-in 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) both" }
|
||||
: undefined}
|
||||
onAnimationEnd={onPopInAnimationEnd}
|
||||
draggable={isVaultHostDraggable(Boolean(isMultiSelectMode), selectedHostIds, host.id)}
|
||||
onDragStart={(e) => onDragStart(e, host.id)}
|
||||
onClick={() => {
|
||||
onActivate(safeHost);
|
||||
}}
|
||||
onKeyDown={(event) => {
|
||||
if (event.key !== "Enter" && event.key !== " ") return;
|
||||
event.preventDefault();
|
||||
onActivate(safeHost);
|
||||
}}
|
||||
>
|
||||
{showGridStar && (
|
||||
<Star size={10} className="absolute top-1.5 right-1.5 text-amber-400 fill-amber-400" />
|
||||
)}
|
||||
<div className="flex items-center gap-3 h-full">
|
||||
{isMultiSelectMode && (
|
||||
<div className="shrink-0" aria-hidden={checkboxAriaHidden}>
|
||||
{selectedHostIds.has(host.id) ? (
|
||||
<CheckSquare size={18} className="text-primary" />
|
||||
) : (
|
||||
<Square size={18} className="text-muted-foreground" />
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
<DistroAvatar host={safeHost} fallback={distroBadge.text} size="lg" />
|
||||
<div className="min-w-0 flex flex-col justify-center gap-0.5 flex-1">
|
||||
<div className="flex items-center gap-1.5">
|
||||
<span className="text-sm font-semibold truncate leading-5">
|
||||
{safeHost.label}
|
||||
</span>
|
||||
{viewMode !== "grid" && renderEditButton(host, true)}
|
||||
{showManagedBadge && (
|
||||
<Badge variant="secondary" className="text-[10px] px-1.5 py-0 h-4 shrink-0">
|
||||
managed
|
||||
</Badge>
|
||||
)}
|
||||
<HostNotesIndicator notes={safeHost.notes} />
|
||||
</div>
|
||||
<div className="text-[11px] text-muted-foreground font-mono truncate leading-4">
|
||||
{getVaultHostRowSubtitle(safeHost, { localFallback: t("localShell.subtitle") })}
|
||||
</div>
|
||||
</div>
|
||||
{viewMode === "grid" && renderEditButton(host)}
|
||||
</div>
|
||||
</div>
|
||||
</ContextMenuTrigger>
|
||||
<VaultHostContextMenu
|
||||
host={host}
|
||||
section={section}
|
||||
primitives={primitives}
|
||||
t={t}
|
||||
onConnect={onConnect}
|
||||
onOpenBrowser={onOpenBrowser}
|
||||
onEdit={onEdit}
|
||||
onDuplicate={onDuplicate}
|
||||
onCopyHostname={onCopyHostname}
|
||||
onCopyCredentials={onCopyCredentials}
|
||||
onTogglePinned={onTogglePinned}
|
||||
onDelete={onDelete}
|
||||
/>
|
||||
</ContextMenu>
|
||||
);
|
||||
};
|
||||
@@ -517,15 +517,62 @@ test("VaultHostListSection preserves grouped totals while virtualizing rendered
|
||||
});
|
||||
|
||||
test("VaultHostListSection exposes hostname copy in host context menus, not as a hover button", () => {
|
||||
const source = readFileSync(new URL("./VaultHostListSection.tsx", import.meta.url), "utf8");
|
||||
assert.doesNotMatch(source, /data-vault-host-copy-hostname-button/);
|
||||
assert.doesNotMatch(source, /renderHostCopyHostnameButton/);
|
||||
assert.match(source, /terminal\.statusbar\.copyHostname\.label/);
|
||||
assert.match(source, /handleCopyHostname\(host\)/);
|
||||
assert.match(source, /!isPluginHostProtocol\(host\.protocol\)/);
|
||||
const sectionSource = readFileSync(new URL("./VaultHostListSection.tsx", import.meta.url), "utf8");
|
||||
const cardSource = readFileSync(new URL("./VaultHostCard.tsx", import.meta.url), "utf8");
|
||||
const combinedSource = `${sectionSource}\n${cardSource}`;
|
||||
assert.doesNotMatch(combinedSource, /data-vault-host-copy-hostname-button/);
|
||||
assert.doesNotMatch(combinedSource, /renderHostCopyHostnameButton/);
|
||||
assert.match(cardSource, /terminal\.statusbar\.copyHostname\.label/);
|
||||
assert.match(cardSource, /onCopyHostname\(host\)/);
|
||||
assert.match(cardSource, /!isPluginHostProtocol\(host\.protocol\)/);
|
||||
});
|
||||
|
||||
test("VaultHostListSection opens dual-pane SFTP from host context menus", () => {
|
||||
const source = readFileSync(new URL("./VaultHostListSection.tsx", import.meta.url), "utf8");
|
||||
assert.match(source, /OpenDualPaneSftpMenuItem/);
|
||||
const cardSource = readFileSync(new URL("./VaultHostCard.tsx", import.meta.url), "utf8");
|
||||
assert.match(cardSource, /OpenDualPaneSftpMenuItem/);
|
||||
});
|
||||
|
||||
test("VaultHostListSection preserves section-specific card differences across pinned, recent, grouped, and main", () => {
|
||||
const managedMain = { ...makeHost("managed-main", "Managed Main"), managedSourceId: "src-1", pinned: true };
|
||||
const ungroupedHost = { ...makeHost("ungrouped-host", "Ungrouped Host"), managedSourceId: "src-2" };
|
||||
|
||||
const gridMarkup = renderHostList({
|
||||
viewMode: "grid",
|
||||
displayedGroups: [],
|
||||
displayedHosts: [managedMain, pinnedHost, recentHost],
|
||||
pinnedHosts: [pinnedHost],
|
||||
recentHosts: [{ ...recentHost, pinned: true }],
|
||||
showRecentHosts: true,
|
||||
visibleDisplayedHosts: [managedMain],
|
||||
isMultiSelectMode: true,
|
||||
selectedHostIds: new Set([managedMain.id]),
|
||||
});
|
||||
|
||||
// Pinned card shows star even when host.pinned is undefined, no managed badge, checkbox wrapper has no aria-hidden.
|
||||
const pinnedIdx = gridMarkup.indexOf('data-vault-grid-item="pinned:pinned-host"');
|
||||
const recentIdx = gridMarkup.indexOf('data-vault-grid-item="recent:recent-host"');
|
||||
const mainIdx = gridMarkup.indexOf('data-vault-grid-item="main:managed-main"');
|
||||
assert.ok(pinnedIdx >= 0 && recentIdx > pinnedIdx && mainIdx > recentIdx);
|
||||
const pinnedSlice = gridMarkup.slice(pinnedIdx, recentIdx);
|
||||
const recentSlice = gridMarkup.slice(recentIdx, mainIdx);
|
||||
const mainSlice = gridMarkup.slice(mainIdx);
|
||||
|
||||
assert.match(pinnedSlice, /text-amber-400 fill-amber-400/);
|
||||
assert.match(pinnedSlice, /<div class="shrink-0"><svg[^>]*lucide-square/);
|
||||
assert.doesNotMatch(pinnedSlice, /<div class="shrink-0" aria-hidden="true">/);
|
||||
assert.doesNotMatch(recentSlice, /text-amber-400 fill-amber-400/);
|
||||
assert.match(mainSlice, /text-amber-400 fill-amber-400/);
|
||||
assert.match(mainSlice, /<div class="shrink-0" aria-hidden="true">/);
|
||||
assert.match(mainSlice, />managed</);
|
||||
|
||||
const groupedMarkup = renderHostList({
|
||||
viewMode: "grid",
|
||||
displayedGroups: [],
|
||||
displayedHosts: [ungroupedHost],
|
||||
groupedDisplayHosts: [{ name: "", hosts: [ungroupedHost] }],
|
||||
sortMode: "group",
|
||||
visibleDisplayedHosts: [],
|
||||
});
|
||||
assert.match(groupedMarkup, /data-vault-grid-item="grouped:__ungrouped__:ungrouped-host"/);
|
||||
assert.match(groupedMarkup, />managed</);
|
||||
});
|
||||
@@ -25,12 +25,10 @@ import {
|
||||
type HostClickBehavior,
|
||||
} from "../../domain/hostClickBehavior";
|
||||
import type { GroupNode, Host } from "../../domain/models";
|
||||
import { isPluginHostProtocol } from "../../domain/pluginConnection";
|
||||
import { OpenDualPaneSftpMenuItem, OpenHostBrowserMenuItem } from "../host/HostTreeContextMenus";
|
||||
import { VAULT_HOST_DRAG_IDS, isVaultHostDraggable } from "../../domain/vaultHostDrag";
|
||||
import { getVaultHostRowSubtitle } from "../../domain/localShellHost";
|
||||
import { VAULT_HOST_DRAG_IDS } from "../../domain/vaultHostDrag";
|
||||
import { beginVaultHostCardDrag } from "./vaultHostDragImage";
|
||||
import { useVaultHostMarquee } from "./useVaultHostMarquee";
|
||||
import { VaultHostCard, type VaultHostCardPrimitives, type VaultHostCardSection } from "./VaultHostCard";
|
||||
|
||||
type VaultHostListSectionContext = Record<string, any>;
|
||||
|
||||
@@ -356,6 +354,65 @@ export function VaultHostListSection({ ctx }: { ctx: VaultHostListSectionContext
|
||||
</Button>
|
||||
);
|
||||
|
||||
const hostCardPrimitives: VaultHostCardPrimitives = {
|
||||
Badge,
|
||||
CheckSquare,
|
||||
ClipboardCopy,
|
||||
cn,
|
||||
ContextMenu,
|
||||
ContextMenuContent,
|
||||
ContextMenuItem,
|
||||
ContextMenuTrigger,
|
||||
Copy,
|
||||
DistroAvatar,
|
||||
Edit2,
|
||||
Pin,
|
||||
Plug,
|
||||
Square,
|
||||
Star,
|
||||
Trash2,
|
||||
};
|
||||
|
||||
const renderHostCard = (
|
||||
host: Host,
|
||||
section: VaultHostCardSection,
|
||||
gridItemKey: string,
|
||||
) => (
|
||||
<VaultHostCard
|
||||
key={host.id}
|
||||
host={host}
|
||||
section={section}
|
||||
gridItemKey={gridItemKey}
|
||||
viewMode={viewMode}
|
||||
isMultiSelectMode={Boolean(isMultiSelectMode)}
|
||||
selectedHostIds={selectedHostIds}
|
||||
draggingHostIds={draggingHostIds}
|
||||
isFocusSelected={isHostFocusSelected(host.id)}
|
||||
tabIndex={getHostTabIndex(host.id)}
|
||||
isPopInAnimated={section === "pinned" && lastPinnedId === host.id}
|
||||
onPopInAnimationEnd={section === "pinned"
|
||||
? () => {
|
||||
if (lastPinnedId === host.id) setLastPinnedId(null);
|
||||
}
|
||||
: undefined}
|
||||
sanitizeHost={sanitizeHost}
|
||||
getEffectiveHostDistro={getEffectiveHostDistro}
|
||||
renderEditButton={renderHostEditButton}
|
||||
onDragStart={handleHostDragStart}
|
||||
onActivate={activateHost}
|
||||
onConnect={handleHostConnect}
|
||||
onOpenBrowser={handleOpenHostBrowser}
|
||||
onEdit={handleEditHost}
|
||||
onDuplicate={handleDuplicateHost}
|
||||
onCopyHostname={handleCopyHostname}
|
||||
onCopyCredentials={handleCopyCredentials}
|
||||
onTogglePinned={toggleHostPinned}
|
||||
onDelete={onDeleteHost}
|
||||
t={t}
|
||||
primitives={hostCardPrimitives}
|
||||
/>
|
||||
);
|
||||
|
||||
const renderGroupEditButton = (groupPath: string, compact = false) => (
|
||||
<Button
|
||||
variant="ghost"
|
||||
@@ -587,112 +644,7 @@ export function VaultHostListSection({ ctx }: { ctx: VaultHostListSectionContext
|
||||
onActiveItemChange={focusHost}
|
||||
activeItemKey={focusedHostId}
|
||||
onBoundaryNavigation={(direction) => navigateHostSection("pinned", direction)}
|
||||
renderItem={(host) => {
|
||||
const safeHost = sanitizeHost(host);
|
||||
const effectiveDistro = getEffectiveHostDistro(safeHost);
|
||||
const distroBadge = {
|
||||
text: (safeHost.os || "L")[0].toUpperCase(),
|
||||
label: effectiveDistro || safeHost.os || "Linux",
|
||||
};
|
||||
return (
|
||||
<ContextMenu key={host.id}>
|
||||
<ContextMenuTrigger>
|
||||
<div
|
||||
className={cn(
|
||||
"vault-drop-indicator-row group cursor-pointer relative",
|
||||
viewMode === "grid"
|
||||
? cn(
|
||||
"soft-card elevate rounded-xl h-[68px] px-3 py-2 will-change-transform transition-[opacity,box-shadow,border-color,background-color] duration-150",
|
||||
draggingHostIds?.has(host.id) && "opacity-45",
|
||||
hostCardFocusClassName(viewMode, isHostFocusSelected(host.id)),
|
||||
)
|
||||
: cn(
|
||||
"h-14 px-2 py-2 rounded-lg transition-colors",
|
||||
isHostFocusSelected(host.id)
|
||||
? hostCardFocusClassName("list", true)
|
||||
: "hover:bg-secondary/60",
|
||||
),
|
||||
)}
|
||||
data-host-id={host.id}
|
||||
data-vault-grid-item={`pinned:${host.id}`}
|
||||
role={isMultiSelectMode ? "checkbox" : "button"}
|
||||
aria-checked={isMultiSelectMode
|
||||
? selectedHostIds.has(host.id)
|
||||
: undefined}
|
||||
tabIndex={getHostTabIndex(host.id)}
|
||||
style={lastPinnedId === host.id ? { animation: "pop-in 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) both" } : undefined}
|
||||
onAnimationEnd={() => { if (lastPinnedId === host.id) setLastPinnedId(null); }}
|
||||
draggable={isVaultHostDraggable(Boolean(isMultiSelectMode), selectedHostIds, host.id)}
|
||||
onDragStart={(e) => handleHostDragStart(e, host.id)}
|
||||
onClick={() => {
|
||||
activateHost(safeHost);
|
||||
}}
|
||||
onKeyDown={(event) => {
|
||||
if (event.key !== "Enter" && event.key !== " ") return;
|
||||
event.preventDefault();
|
||||
activateHost(safeHost);
|
||||
}}
|
||||
>
|
||||
{viewMode === "grid" && (
|
||||
<Star size={10} className="absolute top-1.5 right-1.5 text-amber-400 fill-amber-400" />
|
||||
)}
|
||||
<div className="flex items-center gap-3 h-full">
|
||||
{isMultiSelectMode && (
|
||||
<div className="shrink-0">
|
||||
{selectedHostIds.has(host.id) ? (
|
||||
<CheckSquare size={18} className="text-primary" />
|
||||
) : (
|
||||
<Square size={18} className="text-muted-foreground" />
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
<DistroAvatar host={safeHost} fallback={distroBadge.text} size="lg" />
|
||||
<div className="min-w-0 flex flex-col justify-center gap-0.5 flex-1">
|
||||
<div className="flex items-center gap-1.5">
|
||||
<span className="text-sm font-semibold truncate leading-5">
|
||||
{safeHost.label}
|
||||
</span>
|
||||
{viewMode !== "grid" && renderHostEditButton(host, true)}
|
||||
<HostNotesIndicator notes={safeHost.notes} />
|
||||
</div>
|
||||
<div className="text-[11px] text-muted-foreground font-mono truncate leading-4">
|
||||
{getVaultHostRowSubtitle(safeHost, { localFallback: t('localShell.subtitle') })}
|
||||
</div>
|
||||
</div>
|
||||
{viewMode === "grid" && renderHostEditButton(host)}
|
||||
</div>
|
||||
</div>
|
||||
</ContextMenuTrigger>
|
||||
<ContextMenuContent>
|
||||
<ContextMenuItem onClick={() => handleHostConnect(host)}>
|
||||
<Plug className="mr-2 h-4 w-4" /> {t('vault.hosts.connect')}
|
||||
</ContextMenuItem>
|
||||
<OpenDualPaneSftpMenuItem host={host} />
|
||||
<OpenHostBrowserMenuItem host={host} onOpenBrowser={handleOpenHostBrowser} />
|
||||
<ContextMenuItem onClick={() => handleEditHost(host)}>
|
||||
<Edit2 className="mr-2 h-4 w-4" /> {t('action.edit')}
|
||||
</ContextMenuItem>
|
||||
<ContextMenuItem onClick={() => handleDuplicateHost(host)}>
|
||||
<Copy className="mr-2 h-4 w-4" /> {t('action.duplicate')}
|
||||
</ContextMenuItem>
|
||||
{!isPluginHostProtocol(host.protocol) ? (
|
||||
<ContextMenuItem onClick={() => handleCopyHostname(host)}>
|
||||
<Copy className="mr-2 h-4 w-4" /> {t('terminal.statusbar.copyHostname.label')}
|
||||
</ContextMenuItem>
|
||||
) : null}
|
||||
<ContextMenuItem onClick={() => handleCopyCredentials(host)}>
|
||||
<ClipboardCopy className="mr-2 h-4 w-4" /> {t('vault.hosts.copyCredentials')}
|
||||
</ContextMenuItem>
|
||||
<ContextMenuItem onClick={() => toggleHostPinned(host.id)}>
|
||||
<Pin className="mr-2 h-4 w-4" /> {t('vault.hosts.unpin')}
|
||||
</ContextMenuItem>
|
||||
<ContextMenuItem className="text-destructive" onClick={() => onDeleteHost(host.id)}>
|
||||
<Trash2 className="mr-2 h-4 w-4" /> {t('action.delete')}
|
||||
</ContextMenuItem>
|
||||
</ContextMenuContent>
|
||||
</ContextMenu>
|
||||
);
|
||||
}}
|
||||
renderItem={(host) => renderHostCard(host, "pinned", `pinned:${host.id}`)}
|
||||
/>
|
||||
</section>
|
||||
)}
|
||||
@@ -713,107 +665,7 @@ export function VaultHostListSection({ ctx }: { ctx: VaultHostListSectionContext
|
||||
onActiveItemChange={focusHost}
|
||||
activeItemKey={focusedHostId}
|
||||
onBoundaryNavigation={(direction) => navigateHostSection("recent", direction)}
|
||||
renderItem={(host) => {
|
||||
const safeHost = sanitizeHost(host);
|
||||
const effectiveDistro = getEffectiveHostDistro(safeHost);
|
||||
const distroBadge = {
|
||||
text: (safeHost.os || "L")[0].toUpperCase(),
|
||||
label: effectiveDistro || safeHost.os || "Linux",
|
||||
};
|
||||
return (
|
||||
<ContextMenu key={host.id}>
|
||||
<ContextMenuTrigger>
|
||||
<div
|
||||
className={cn(
|
||||
"vault-drop-indicator-row group cursor-pointer relative",
|
||||
viewMode === "grid"
|
||||
? cn(
|
||||
"soft-card elevate rounded-xl h-[68px] px-3 py-2 will-change-transform transition-[opacity,box-shadow,border-color,background-color] duration-150",
|
||||
draggingHostIds?.has(host.id) && "opacity-45",
|
||||
hostCardFocusClassName(viewMode, isHostFocusSelected(host.id)),
|
||||
)
|
||||
: cn(
|
||||
"h-14 px-2 py-2 rounded-lg transition-colors",
|
||||
isHostFocusSelected(host.id)
|
||||
? hostCardFocusClassName("list", true)
|
||||
: "hover:bg-secondary/60",
|
||||
),
|
||||
)}
|
||||
data-host-id={host.id}
|
||||
data-vault-grid-item={`recent:${host.id}`}
|
||||
role={isMultiSelectMode ? "checkbox" : "button"}
|
||||
aria-checked={isMultiSelectMode
|
||||
? selectedHostIds.has(host.id)
|
||||
: undefined}
|
||||
tabIndex={getHostTabIndex(host.id)}
|
||||
draggable={isVaultHostDraggable(Boolean(isMultiSelectMode), selectedHostIds, host.id)}
|
||||
onDragStart={(e) => handleHostDragStart(e, host.id)}
|
||||
onClick={() => {
|
||||
activateHost(safeHost);
|
||||
}}
|
||||
onKeyDown={(event) => {
|
||||
if (event.key !== "Enter" && event.key !== " ") return;
|
||||
event.preventDefault();
|
||||
activateHost(safeHost);
|
||||
}}
|
||||
>
|
||||
<div className="flex items-center gap-3 h-full">
|
||||
{isMultiSelectMode && (
|
||||
<div className="shrink-0">
|
||||
{selectedHostIds.has(host.id) ? (
|
||||
<CheckSquare size={18} className="text-primary" />
|
||||
) : (
|
||||
<Square size={18} className="text-muted-foreground" />
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
<DistroAvatar host={safeHost} fallback={distroBadge.text} size="lg" />
|
||||
<div className="min-w-0 flex flex-col justify-center gap-0.5 flex-1">
|
||||
<div className="flex items-center gap-1.5">
|
||||
<span className="text-sm font-semibold truncate leading-5">
|
||||
{safeHost.label}
|
||||
</span>
|
||||
{viewMode !== "grid" && renderHostEditButton(host, true)}
|
||||
<HostNotesIndicator notes={safeHost.notes} />
|
||||
</div>
|
||||
<div className="text-[11px] text-muted-foreground font-mono truncate leading-4">
|
||||
{getVaultHostRowSubtitle(safeHost, { localFallback: t('localShell.subtitle') })}
|
||||
</div>
|
||||
</div>
|
||||
{viewMode === "grid" && renderHostEditButton(host)}
|
||||
</div>
|
||||
</div>
|
||||
</ContextMenuTrigger>
|
||||
<ContextMenuContent>
|
||||
<ContextMenuItem onClick={() => handleHostConnect(host)}>
|
||||
<Plug className="mr-2 h-4 w-4" /> {t('vault.hosts.connect')}
|
||||
</ContextMenuItem>
|
||||
<OpenDualPaneSftpMenuItem host={host} />
|
||||
<OpenHostBrowserMenuItem host={host} onOpenBrowser={handleOpenHostBrowser} />
|
||||
<ContextMenuItem onClick={() => handleEditHost(host)}>
|
||||
<Edit2 className="mr-2 h-4 w-4" /> {t('action.edit')}
|
||||
</ContextMenuItem>
|
||||
<ContextMenuItem onClick={() => handleDuplicateHost(host)}>
|
||||
<Copy className="mr-2 h-4 w-4" /> {t('action.duplicate')}
|
||||
</ContextMenuItem>
|
||||
{!isPluginHostProtocol(host.protocol) ? (
|
||||
<ContextMenuItem onClick={() => handleCopyHostname(host)}>
|
||||
<Copy className="mr-2 h-4 w-4" /> {t('terminal.statusbar.copyHostname.label')}
|
||||
</ContextMenuItem>
|
||||
) : null}
|
||||
<ContextMenuItem onClick={() => handleCopyCredentials(host)}>
|
||||
<ClipboardCopy className="mr-2 h-4 w-4" /> {t('vault.hosts.copyCredentials')}
|
||||
</ContextMenuItem>
|
||||
<ContextMenuItem onClick={() => toggleHostPinned(host.id)}>
|
||||
<Pin className="mr-2 h-4 w-4" /> {host.pinned ? t('vault.hosts.unpin') : t('vault.hosts.pinToTop')}
|
||||
</ContextMenuItem>
|
||||
<ContextMenuItem className="text-destructive" onClick={() => onDeleteHost(host.id)}>
|
||||
<Trash2 className="mr-2 h-4 w-4" /> {t('action.delete')}
|
||||
</ContextMenuItem>
|
||||
</ContextMenuContent>
|
||||
</ContextMenu>
|
||||
);
|
||||
}}
|
||||
renderItem={(host) => renderHostCard(host, "recent", `recent:${host.id}`)}
|
||||
/>
|
||||
</section>
|
||||
)}
|
||||
@@ -1085,130 +937,9 @@ export function VaultHostListSection({ ctx }: { ctx: VaultHostListSectionContext
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
renderItem={(host: Host, group) => {
|
||||
const safeHost = sanitizeHost(host);
|
||||
const effectiveDistro = getEffectiveHostDistro(safeHost);
|
||||
const distroBadge = {
|
||||
text: (safeHost.os || "L")[0].toUpperCase(),
|
||||
label: effectiveDistro || safeHost.os || "Linux",
|
||||
};
|
||||
return (
|
||||
<ContextMenu key={host.id}>
|
||||
<ContextMenuTrigger>
|
||||
<div
|
||||
className={cn(
|
||||
"vault-drop-indicator-row group cursor-pointer relative",
|
||||
viewMode === "grid"
|
||||
? cn(
|
||||
"soft-card elevate rounded-xl h-[68px] px-3 py-2 will-change-transform transition-[opacity,box-shadow,border-color,background-color] duration-150",
|
||||
draggingHostIds?.has(host.id) && "opacity-45",
|
||||
hostCardFocusClassName(viewMode, isHostFocusSelected(host.id)),
|
||||
)
|
||||
: cn(
|
||||
"h-14 px-2 py-2 rounded-lg transition-colors",
|
||||
isHostFocusSelected(host.id)
|
||||
? hostCardFocusClassName("list", true)
|
||||
: "hover:bg-secondary/60",
|
||||
),
|
||||
)}
|
||||
data-host-id={host.id}
|
||||
data-vault-grid-item={`grouped:${group.name || "__ungrouped__"}:${host.id}`}
|
||||
role={isMultiSelectMode ? "checkbox" : "button"}
|
||||
aria-checked={isMultiSelectMode
|
||||
? selectedHostIds.has(host.id)
|
||||
: undefined}
|
||||
tabIndex={getHostTabIndex(host.id)}
|
||||
draggable={isVaultHostDraggable(Boolean(isMultiSelectMode), selectedHostIds, host.id)}
|
||||
onDragStart={(e) => handleHostDragStart(e, host.id)}
|
||||
onClick={() => {
|
||||
activateHost(safeHost);
|
||||
}}
|
||||
onKeyDown={(event) => {
|
||||
if (event.key !== "Enter" && event.key !== " ") return;
|
||||
event.preventDefault();
|
||||
activateHost(safeHost);
|
||||
}}
|
||||
>
|
||||
{host.pinned && viewMode === "grid" && (
|
||||
<Star size={10} className="absolute top-1.5 right-1.5 text-amber-400 fill-amber-400" />
|
||||
)}
|
||||
<div className="flex items-center gap-3 h-full">
|
||||
{isMultiSelectMode && (
|
||||
<div className="shrink-0" aria-hidden="true">
|
||||
{selectedHostIds.has(host.id) ? (
|
||||
<CheckSquare size={18} className="text-primary" />
|
||||
) : (
|
||||
<Square size={18} className="text-muted-foreground" />
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
<DistroAvatar
|
||||
host={safeHost}
|
||||
fallback={distroBadge.text}
|
||||
size="lg"
|
||||
/>
|
||||
<div className="min-w-0 flex flex-col justify-center gap-0.5 flex-1">
|
||||
<div className="flex items-center gap-1.5">
|
||||
<span className="text-sm font-semibold truncate leading-5">
|
||||
{safeHost.label}
|
||||
</span>
|
||||
{viewMode !== "grid" && renderHostEditButton(host, true)}
|
||||
{safeHost.managedSourceId && (
|
||||
<Badge variant="secondary" className="text-[10px] px-1.5 py-0 h-4 shrink-0">
|
||||
managed
|
||||
</Badge>
|
||||
)}
|
||||
<HostNotesIndicator notes={safeHost.notes} />
|
||||
</div>
|
||||
<div className="text-[11px] text-muted-foreground font-mono truncate leading-4">
|
||||
{getVaultHostRowSubtitle(safeHost, { localFallback: t('localShell.subtitle') })}
|
||||
</div>
|
||||
</div>
|
||||
{viewMode === "grid" && renderHostEditButton(host)}
|
||||
</div>
|
||||
</div>
|
||||
</ContextMenuTrigger>
|
||||
<ContextMenuContent>
|
||||
<ContextMenuItem
|
||||
onClick={() => handleHostConnect(host)}
|
||||
>
|
||||
<Plug className="mr-2 h-4 w-4" /> {t('vault.hosts.connect')}
|
||||
</ContextMenuItem>
|
||||
<OpenDualPaneSftpMenuItem host={host} />
|
||||
<OpenHostBrowserMenuItem host={host} onOpenBrowser={handleOpenHostBrowser} />
|
||||
<ContextMenuItem
|
||||
onClick={() => handleEditHost(host)}
|
||||
>
|
||||
<Edit2 className="mr-2 h-4 w-4" /> {t('action.edit')}
|
||||
</ContextMenuItem>
|
||||
<ContextMenuItem
|
||||
onClick={() => handleDuplicateHost(host)}
|
||||
>
|
||||
<Copy className="mr-2 h-4 w-4" /> {t('action.duplicate')}
|
||||
</ContextMenuItem>
|
||||
{!isPluginHostProtocol(host.protocol) ? (
|
||||
<ContextMenuItem onClick={() => handleCopyHostname(host)}>
|
||||
<Copy className="mr-2 h-4 w-4" /> {t('terminal.statusbar.copyHostname.label')}
|
||||
</ContextMenuItem>
|
||||
) : null}
|
||||
<ContextMenuItem
|
||||
onClick={() => handleCopyCredentials(host)}
|
||||
>
|
||||
<ClipboardCopy className="mr-2 h-4 w-4" /> {t('vault.hosts.copyCredentials')}
|
||||
</ContextMenuItem>
|
||||
<ContextMenuItem onClick={() => toggleHostPinned(host.id)}>
|
||||
<Pin className="mr-2 h-4 w-4" /> {host.pinned ? t('vault.hosts.unpin') : t('vault.hosts.pinToTop')}
|
||||
</ContextMenuItem>
|
||||
<ContextMenuItem
|
||||
className="text-destructive"
|
||||
onClick={() => onDeleteHost(host.id)}
|
||||
>
|
||||
<Trash2 className="mr-2 h-4 w-4" /> {t('action.delete')}
|
||||
</ContextMenuItem>
|
||||
</ContextMenuContent>
|
||||
</ContextMenu>
|
||||
);
|
||||
}}
|
||||
renderItem={(host: Host, group) =>
|
||||
renderHostCard(host, "grouped", `grouped:${group.name || "__ungrouped__"}:${host.id}`)
|
||||
}
|
||||
/>
|
||||
{groupedDisplayHosts.length === 0 && (
|
||||
<div className="col-span-full flex flex-col items-center justify-center py-24 text-muted-foreground">
|
||||
@@ -1236,130 +967,7 @@ export function VaultHostListSection({ ctx }: { ctx: VaultHostListSectionContext
|
||||
onActiveItemChange={focusHost}
|
||||
activeItemKey={focusedHostId}
|
||||
onBoundaryNavigation={(direction) => navigateHostSection("main", direction)}
|
||||
renderItem={(host: Host) => {
|
||||
const safeHost = sanitizeHost(host);
|
||||
const effectiveDistro = getEffectiveHostDistro(safeHost);
|
||||
const distroBadge = {
|
||||
text: (safeHost.os || "L")[0].toUpperCase(),
|
||||
label: effectiveDistro || safeHost.os || "Linux",
|
||||
};
|
||||
return (
|
||||
<ContextMenu key={host.id}>
|
||||
<ContextMenuTrigger>
|
||||
<div
|
||||
className={cn(
|
||||
"vault-drop-indicator-row group cursor-pointer relative",
|
||||
viewMode === "grid"
|
||||
? cn(
|
||||
"soft-card elevate rounded-xl h-[68px] px-3 py-2 will-change-transform transition-[opacity,box-shadow,border-color,background-color] duration-150",
|
||||
draggingHostIds?.has(host.id) && "opacity-45",
|
||||
hostCardFocusClassName(viewMode, isHostFocusSelected(host.id)),
|
||||
)
|
||||
: cn(
|
||||
"h-14 px-2 py-2 rounded-lg transition-colors",
|
||||
isHostFocusSelected(host.id)
|
||||
? hostCardFocusClassName("list", true)
|
||||
: "hover:bg-secondary/60",
|
||||
),
|
||||
)}
|
||||
data-host-id={host.id}
|
||||
data-vault-grid-item={`main:${host.id}`}
|
||||
role={isMultiSelectMode ? "checkbox" : "button"}
|
||||
aria-checked={isMultiSelectMode
|
||||
? selectedHostIds.has(host.id)
|
||||
: undefined}
|
||||
tabIndex={getHostTabIndex(host.id)}
|
||||
draggable={isVaultHostDraggable(Boolean(isMultiSelectMode), selectedHostIds, host.id)}
|
||||
onDragStart={(e) => handleHostDragStart(e, host.id)}
|
||||
onClick={() => {
|
||||
activateHost(safeHost);
|
||||
}}
|
||||
onKeyDown={(event) => {
|
||||
if (event.key !== "Enter" && event.key !== " ") return;
|
||||
event.preventDefault();
|
||||
activateHost(safeHost);
|
||||
}}
|
||||
>
|
||||
{host.pinned && viewMode === "grid" && (
|
||||
<Star size={10} className="absolute top-1.5 right-1.5 text-amber-400 fill-amber-400" />
|
||||
)}
|
||||
<div className="flex items-center gap-3 h-full">
|
||||
{isMultiSelectMode && (
|
||||
<div className="shrink-0" aria-hidden="true">
|
||||
{selectedHostIds.has(host.id) ? (
|
||||
<CheckSquare size={18} className="text-primary" />
|
||||
) : (
|
||||
<Square size={18} className="text-muted-foreground" />
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
<DistroAvatar
|
||||
host={safeHost}
|
||||
fallback={distroBadge.text}
|
||||
size="lg"
|
||||
/>
|
||||
<div className="min-w-0 flex flex-col justify-center gap-0.5 flex-1">
|
||||
<div className="flex items-center gap-1.5">
|
||||
<span className="text-sm font-semibold truncate leading-5">
|
||||
{safeHost.label}
|
||||
</span>
|
||||
{viewMode !== "grid" && renderHostEditButton(host, true)}
|
||||
{safeHost.managedSourceId && (
|
||||
<Badge variant="secondary" className="text-[10px] px-1.5 py-0 h-4 shrink-0">
|
||||
managed
|
||||
</Badge>
|
||||
)}
|
||||
<HostNotesIndicator notes={safeHost.notes} />
|
||||
</div>
|
||||
<div className="text-[11px] text-muted-foreground font-mono truncate leading-4">
|
||||
{getVaultHostRowSubtitle(safeHost, { localFallback: t('localShell.subtitle') })}
|
||||
</div>
|
||||
</div>
|
||||
{viewMode === "grid" && renderHostEditButton(host)}
|
||||
</div>
|
||||
</div>
|
||||
</ContextMenuTrigger>
|
||||
<ContextMenuContent>
|
||||
<ContextMenuItem
|
||||
onClick={() => handleHostConnect(host)}
|
||||
>
|
||||
<Plug className="mr-2 h-4 w-4" /> {t('vault.hosts.connect')}
|
||||
</ContextMenuItem>
|
||||
<OpenDualPaneSftpMenuItem host={host} />
|
||||
<OpenHostBrowserMenuItem host={host} onOpenBrowser={handleOpenHostBrowser} />
|
||||
<ContextMenuItem
|
||||
onClick={() => handleEditHost(host)}
|
||||
>
|
||||
<Edit2 className="mr-2 h-4 w-4" /> {t('action.edit')}
|
||||
</ContextMenuItem>
|
||||
<ContextMenuItem
|
||||
onClick={() => handleDuplicateHost(host)}
|
||||
>
|
||||
<Copy className="mr-2 h-4 w-4" /> {t('action.duplicate')}
|
||||
</ContextMenuItem>
|
||||
{!isPluginHostProtocol(host.protocol) ? (
|
||||
<ContextMenuItem onClick={() => handleCopyHostname(host)}>
|
||||
<Copy className="mr-2 h-4 w-4" /> {t('terminal.statusbar.copyHostname.label')}
|
||||
</ContextMenuItem>
|
||||
) : null}
|
||||
<ContextMenuItem
|
||||
onClick={() => handleCopyCredentials(host)}
|
||||
>
|
||||
<ClipboardCopy className="mr-2 h-4 w-4" /> {t('vault.hosts.copyCredentials')}
|
||||
</ContextMenuItem>
|
||||
<ContextMenuItem onClick={() => toggleHostPinned(host.id)}>
|
||||
<Pin className="mr-2 h-4 w-4" /> {host.pinned ? t('vault.hosts.unpin') : t('vault.hosts.pinToTop')}
|
||||
</ContextMenuItem>
|
||||
<ContextMenuItem
|
||||
className="text-destructive"
|
||||
onClick={() => onDeleteHost(host.id)}
|
||||
>
|
||||
<Trash2 className="mr-2 h-4 w-4" /> {t('action.delete')}
|
||||
</ContextMenuItem>
|
||||
</ContextMenuContent>
|
||||
</ContextMenu>
|
||||
);
|
||||
}}
|
||||
renderItem={(host: Host) => renderHostCard(host, "main", `main:${host.id}`)}
|
||||
/>
|
||||
{displayedHosts.length === 0 && (
|
||||
<div className="col-span-full flex flex-col items-center justify-center py-24 text-muted-foreground">
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { ChevronRight, FileText, Folder, FolderOpen } from "lucide-react";
|
||||
import React, { useEffect, useRef, useState } from "react";
|
||||
import React from "react";
|
||||
|
||||
import { cn } from "../../lib/utils";
|
||||
import { InlineRenameInput } from "../ui/inline-rename-input";
|
||||
|
||||
type VaultTreeInlineRenameInputProps = {
|
||||
initialName: string;
|
||||
@@ -11,81 +12,15 @@ type VaultTreeInlineRenameInputProps = {
|
||||
style?: React.CSSProperties;
|
||||
};
|
||||
|
||||
export const VaultTreeInlineRenameInput: React.FC<VaultTreeInlineRenameInputProps> = ({
|
||||
initialName,
|
||||
onCommit,
|
||||
onCancel,
|
||||
className,
|
||||
style,
|
||||
}) => {
|
||||
const inputRef = useRef<HTMLInputElement>(null);
|
||||
const [value, setValue] = useState(initialName);
|
||||
const submittingRef = useRef(false);
|
||||
|
||||
useEffect(() => {
|
||||
const input = inputRef.current;
|
||||
if (!input) return;
|
||||
input.focus();
|
||||
input.select();
|
||||
}, []);
|
||||
|
||||
const commit = async () => {
|
||||
if (submittingRef.current) return;
|
||||
submittingRef.current = true;
|
||||
try {
|
||||
const committed = await onCommit(value);
|
||||
if (committed === false) submittingRef.current = false;
|
||||
} catch {
|
||||
submittingRef.current = false;
|
||||
}
|
||||
};
|
||||
|
||||
const cancel = () => {
|
||||
if (submittingRef.current) return;
|
||||
submittingRef.current = true;
|
||||
onCancel();
|
||||
};
|
||||
|
||||
return (
|
||||
<input
|
||||
ref={inputRef}
|
||||
data-vault-tree-inline-edit="true"
|
||||
data-inline-group-edit="true"
|
||||
value={value}
|
||||
draggable={false}
|
||||
onChange={(event) => setValue(event.target.value)}
|
||||
onBlur={() => {
|
||||
queueMicrotask(() => {
|
||||
void commit();
|
||||
});
|
||||
}}
|
||||
onClick={(event) => event.stopPropagation()}
|
||||
onDoubleClick={(event) => event.stopPropagation()}
|
||||
onMouseDown={(event) => event.stopPropagation()}
|
||||
onPointerDown={(event) => event.stopPropagation()}
|
||||
onDragStart={(event) => {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
}}
|
||||
onKeyDown={(event) => {
|
||||
event.stopPropagation();
|
||||
if (event.key === "Enter") {
|
||||
event.preventDefault();
|
||||
void commit();
|
||||
}
|
||||
if (event.key === "Escape") {
|
||||
event.preventDefault();
|
||||
cancel();
|
||||
}
|
||||
}}
|
||||
className={cn(
|
||||
"min-w-0 flex-1 truncate select-text rounded-sm border border-primary/50 bg-background/80 px-1 py-0 text-sm font-medium outline-none ring-1 ring-primary/30",
|
||||
className,
|
||||
)}
|
||||
style={style}
|
||||
/>
|
||||
);
|
||||
};
|
||||
export const VaultTreeInlineRenameInput: React.FC<VaultTreeInlineRenameInputProps> = (
|
||||
props,
|
||||
) => (
|
||||
<InlineRenameInput
|
||||
data-vault-tree-inline-edit="true"
|
||||
data-inline-group-edit="true"
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
|
||||
type VaultTreeGroupRowProps = Omit<React.HTMLAttributes<HTMLDivElement>, "children"> & {
|
||||
name: string;
|
||||
|
||||
Reference in new issue
Block a user