mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-10-31 23:55:23 +00:00
fix(file-manager): keep inline rename consistent (#1476)
* fix(ci): build plugin SDK before dependent checks * fix(mysql): keep plugin settings scope indexes within limits * test(mysql): refresh reviewed plugin upgrade SQL * fix(file-manager): keep inline rename consistent
This commit is contained in:
1 parent
f05f626507
commit
488e940c1a
3 files changed
+107
-8
No files matched your search
@@ -378,7 +378,7 @@ export function FileManagerContextMenu({
|
|||||||
icon: <Edit3 className="size-3.5" />,
|
icon: <Edit3 className="size-3.5" />,
|
||||||
label: t("fileManager.rename"),
|
label: t("fileManager.rename"),
|
||||||
action: () => onRename(files[0]),
|
action: () => onRename(files[0]),
|
||||||
shortcut: "F6",
|
shortcut: "F2",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1032,6 +1032,7 @@ export function FileManagerGrid({
|
|||||||
onDelete(selectedFiles);
|
onDelete(selectedFiles);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case "F2":
|
||||||
case "F6":
|
case "F6":
|
||||||
if (selectedFiles.length === 1 && onStartEdit) {
|
if (selectedFiles.length === 1 && onStartEdit) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
@@ -1418,6 +1419,7 @@ export function FileManagerGrid({
|
|||||||
const isSelected = selectedFiles.some(
|
const isSelected = selectedFiles.some(
|
||||||
(f) => f.path === file.path,
|
(f) => f.path === file.path,
|
||||||
);
|
);
|
||||||
|
const isEditing = editingFile?.path === file.path;
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
key={vItem.key}
|
key={vItem.key}
|
||||||
@@ -1432,7 +1434,9 @@ export function FileManagerGrid({
|
|||||||
data-file-path={file.path}
|
data-file-path={file.path}
|
||||||
draggable={true}
|
draggable={true}
|
||||||
style={{
|
style={{
|
||||||
gridTemplateColumns: listColumns.gridTemplateColumns,
|
gridTemplateColumns: isEditing
|
||||||
|
? "minmax(0, 1fr)"
|
||||||
|
: listColumns.gridTemplateColumns,
|
||||||
}}
|
}}
|
||||||
className={cn(
|
className={cn(
|
||||||
"grid gap-2 items-center cursor-pointer border-b border-border hover:bg-muted/50 rounded-none select-none transition-colors",
|
"grid gap-2 items-center cursor-pointer border-b border-border hover:bg-muted/50 rounded-none select-none transition-colors",
|
||||||
@@ -1461,12 +1465,13 @@ export function FileManagerGrid({
|
|||||||
className={cn(
|
className={cn(
|
||||||
"flex items-center overflow-hidden pointer-events-none",
|
"flex items-center overflow-hidden pointer-events-none",
|
||||||
compact ? "gap-2" : "gap-3",
|
compact ? "gap-2" : "gap-3",
|
||||||
|
isEditing && "col-span-full",
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<div className="shrink-0">
|
<div className="shrink-0">
|
||||||
{getFileIcon(file, viewMode, compact)}
|
{getFileIcon(file, viewMode, compact)}
|
||||||
</div>
|
</div>
|
||||||
{editingFile?.path === file.path ? (
|
{isEditing ? (
|
||||||
<input
|
<input
|
||||||
ref={editInputRef}
|
ref={editInputRef}
|
||||||
type="text"
|
type="text"
|
||||||
@@ -1474,7 +1479,10 @@ export function FileManagerGrid({
|
|||||||
onChange={(e) => setEditingName(e.target.value)}
|
onChange={(e) => setEditingName(e.target.value)}
|
||||||
onKeyDown={handleEditKeyDown}
|
onKeyDown={handleEditKeyDown}
|
||||||
onBlur={handleEditConfirm}
|
onBlur={handleEditConfirm}
|
||||||
className="flex-1 min-w-0 max-w-[200px] border border-accent-brand/60 bg-card px-2 py-1 text-xs rounded-none outline-none focus:ring-1 focus:ring-accent-brand/50 pointer-events-auto"
|
className={cn(
|
||||||
|
"flex-1 min-w-0 border border-accent-brand/60 bg-card px-2 py-0 rounded-none outline-none focus:ring-1 focus:ring-accent-brand/50 pointer-events-auto",
|
||||||
|
compact ? "h-5 text-[11px]" : "h-6 text-xs",
|
||||||
|
)}
|
||||||
onClick={(e) => e.stopPropagation()}
|
onClick={(e) => e.stopPropagation()}
|
||||||
onMouseDown={(e) => e.stopPropagation()}
|
onMouseDown={(e) => e.stopPropagation()}
|
||||||
/>
|
/>
|
||||||
@@ -1493,13 +1501,13 @@ export function FileManagerGrid({
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{listColumns.isVisible("modified") && (
|
{!isEditing && listColumns.isVisible("modified") && (
|
||||||
<span className="text-[10px] text-muted-foreground pointer-events-none truncate">
|
<span className="text-[10px] text-muted-foreground pointer-events-none truncate">
|
||||||
{file.modified || "—"}
|
{file.modified || "—"}
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{listColumns.isVisible("owner") && (
|
{!isEditing && listColumns.isVisible("owner") && (
|
||||||
<span className="text-[10px] text-muted-foreground truncate hidden md:block pointer-events-none">
|
<span className="text-[10px] text-muted-foreground truncate hidden md:block pointer-events-none">
|
||||||
{file.owner
|
{file.owner
|
||||||
? `${file.owner}${file.group ? `:${file.group}` : ""}`
|
? `${file.owner}${file.group ? `:${file.group}` : ""}`
|
||||||
@@ -1507,7 +1515,7 @@ export function FileManagerGrid({
|
|||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{listColumns.isVisible("size") && (
|
{!isEditing && listColumns.isVisible("size") && (
|
||||||
<span className="text-[10px] text-right text-muted-foreground tabular-nums pointer-events-none">
|
<span className="text-[10px] text-right text-muted-foreground tabular-nums pointer-events-none">
|
||||||
{file.type === "file" &&
|
{file.type === "file" &&
|
||||||
file.size !== undefined &&
|
file.size !== undefined &&
|
||||||
@@ -1517,7 +1525,7 @@ export function FileManagerGrid({
|
|||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{listColumns.isVisible("permissions") && (
|
{!isEditing && listColumns.isVisible("permissions") && (
|
||||||
<span className="text-[10px] text-right font-mono text-muted-foreground/60 pointer-events-none truncate">
|
<span className="text-[10px] text-right font-mono text-muted-foreground/60 pointer-events-none truncate">
|
||||||
{file.permissions || "—"}
|
{file.permissions || "—"}
|
||||||
</span>
|
</span>
|
||||||
|
|||||||
@@ -0,0 +1,91 @@
|
|||||||
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||||
|
import { cleanup, fireEvent, render, screen } from "@testing-library/react";
|
||||||
|
import "@testing-library/jest-dom/vitest";
|
||||||
|
import { FileManagerGrid } from "../../src/frontend/FileManagerGrid";
|
||||||
|
import type { FileItem } from "../../src/frontend/host-types";
|
||||||
|
|
||||||
|
vi.mock("react-i18next", () => ({
|
||||||
|
useTranslation: () => ({ t: (key: string) => key }),
|
||||||
|
initReactI18next: { type: "3rdParty", init: () => {} },
|
||||||
|
}));
|
||||||
|
|
||||||
|
vi.mock("@tanstack/react-virtual", () => ({
|
||||||
|
useVirtualizer: ({ count }: { count: number }) => ({
|
||||||
|
getTotalSize: () => count * 29,
|
||||||
|
getVirtualItems: () =>
|
||||||
|
Array.from({ length: count }, (_, index) => ({
|
||||||
|
index,
|
||||||
|
key: index,
|
||||||
|
start: index * 29,
|
||||||
|
size: 29,
|
||||||
|
})),
|
||||||
|
measureElement: () => {},
|
||||||
|
measure: () => {},
|
||||||
|
}),
|
||||||
|
}));
|
||||||
|
|
||||||
|
const file: FileItem = {
|
||||||
|
name: "notes.txt",
|
||||||
|
path: "/notes.txt",
|
||||||
|
type: "file",
|
||||||
|
modified: "2026-09-01",
|
||||||
|
owner: "owner",
|
||||||
|
permissions: "-rw-r--r--",
|
||||||
|
};
|
||||||
|
const props = {
|
||||||
|
files: [file],
|
||||||
|
selectedFiles: [file],
|
||||||
|
viewMode: "list" as const,
|
||||||
|
onFileOpen: vi.fn(),
|
||||||
|
onSelectionChange: vi.fn(),
|
||||||
|
onRefresh: vi.fn(),
|
||||||
|
};
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
cleanup();
|
||||||
|
vi.restoreAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("remote file rename", () => {
|
||||||
|
it.each(["F2", "F6"])("starts rename with %s in the visible pane", (key) => {
|
||||||
|
vi.spyOn(HTMLElement.prototype, "offsetParent", "get").mockReturnValue(
|
||||||
|
document.body,
|
||||||
|
);
|
||||||
|
const onStartEdit = vi.fn();
|
||||||
|
render(<FileManagerGrid {...props} onStartEdit={onStartEdit} />);
|
||||||
|
fireEvent.keyDown(document, { key });
|
||||||
|
expect(onStartEdit).toHaveBeenCalledExactlyOnceWith(file);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("does not rename files in a hidden pane", () => {
|
||||||
|
vi.spyOn(HTMLElement.prototype, "offsetParent", "get").mockReturnValue(
|
||||||
|
null,
|
||||||
|
);
|
||||||
|
const onStartEdit = vi.fn();
|
||||||
|
render(<FileManagerGrid {...props} onStartEdit={onStartEdit} />);
|
||||||
|
fireEvent.keyDown(document, { key: "F2" });
|
||||||
|
expect(onStartEdit).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("hides metadata while editing and commits the new name", () => {
|
||||||
|
const onRename = vi.fn();
|
||||||
|
const { rerender } = render(<FileManagerGrid {...props} />);
|
||||||
|
expect(screen.getByText(file.modified!)).toBeInTheDocument();
|
||||||
|
rerender(
|
||||||
|
<FileManagerGrid
|
||||||
|
{...props}
|
||||||
|
density="compact"
|
||||||
|
editingFile={file}
|
||||||
|
onRename={onRename}
|
||||||
|
/>,
|
||||||
|
);
|
||||||
|
expect(screen.queryByText(file.modified!)).not.toBeInTheDocument();
|
||||||
|
expect(screen.queryByText(file.permissions!)).not.toBeInTheDocument();
|
||||||
|
const input = screen.getByRole("textbox");
|
||||||
|
fireEvent.change(input, { target: { value: "renamed.txt" } });
|
||||||
|
fireEvent.keyDown(input, { key: "Enter" });
|
||||||
|
expect(onRename).toHaveBeenCalledWith(file, "renamed.txt");
|
||||||
|
rerender(<FileManagerGrid {...props} />);
|
||||||
|
expect(screen.getByText(file.modified!)).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in new issue
Block a user