From e98f40d3999dbf04832a22012951d47de8681d36 Mon Sep 17 00:00:00 2001 From: mapxn <16299874+mapxn@users.noreply.github.com> Date: Thu, 19 Nov 2026 22:39:30 +0800 Subject: [PATCH 1/2] feat(web): add rename and move file dialogs and rework usage bar - add rename and move to menu items in file table - implement rename dialog with basename selection and 409 conflict handling - implement move dialog with folder hierarchy tree and root option - rework usage bar to compact width and critical red state at >=90% - update zh/en locales and pass test suite and linters Checkpoint: 9QzawQWw5r8p0eGysOwmy --- web/src/components/ui/progress.tsx | 13 +- web/src/components/workbench/file-table.tsx | 14 + .../components/workbench/move-file-dialog.tsx | 245 ++++++++++++++++++ .../workbench/rename-file-dialog.tsx | 148 +++++++++++ web/src/components/workbench/usage-bar.tsx | 32 ++- web/src/lib/api-types.ts | 6 + web/src/lib/api.ts | 7 + web/src/locales/en.json | 16 ++ web/src/locales/zh.json | 16 ++ web/src/pages/workbench.test.tsx | 180 +++++++++++++ web/src/pages/workbench.tsx | 24 ++ 11 files changed, 689 insertions(+), 12 deletions(-) create mode 100644 web/src/components/workbench/move-file-dialog.tsx create mode 100644 web/src/components/workbench/rename-file-dialog.tsx diff --git a/web/src/components/ui/progress.tsx b/web/src/components/ui/progress.tsx index ea75c4e..4240eb3 100644 --- a/web/src/components/ui/progress.tsx +++ b/web/src/components/ui/progress.tsx @@ -4,11 +4,17 @@ import * as React from "react" import { cn } from "cn" import { Progress as ProgressPrimitive } from "radix-ui" +interface ProgressProps + extends React.ComponentProps { + indicatorClassName?: string +} + function Progress({ className, value, + indicatorClassName, ...props -}: React.ComponentProps) { +}: ProgressProps) { return ( diff --git a/web/src/components/workbench/file-table.tsx b/web/src/components/workbench/file-table.tsx index 85125b0..f15a6f9 100644 --- a/web/src/components/workbench/file-table.tsx +++ b/web/src/components/workbench/file-table.tsx @@ -3,8 +3,10 @@ import { DownloadIcon, FileIcon, FolderIcon, + FolderInputIcon, FolderOpenIcon, MoreHorizontalIcon, + PencilIcon, Share2Icon, Trash2Icon } from "lucide-react" @@ -36,6 +38,8 @@ interface FileTableProps { onOpenFolder: (folderId: string) => void onDeleteFolder: (folder: FolderItem) => void onShareFile: (file: FileItem) => void + onRenameFile: (file: FileItem) => void + onMoveFile: (file: FileItem) => void onEditExpiration: (file: FileItem) => void onDeleteFile: (file: FileItem) => void } @@ -46,6 +50,8 @@ export function FileTable({ onOpenFolder, onDeleteFolder, onShareFile, + onRenameFile, + onMoveFile, onEditExpiration, onDeleteFile }: FileTableProps) { @@ -209,6 +215,14 @@ export function FileTable({ {t("workbench.actions.share")} + onRenameFile(file)}> + + {t("workbench.actions.rename")} + + onMoveFile(file)}> + + {t("workbench.actions.moveTo")} + onEditExpiration(file)} > diff --git a/web/src/components/workbench/move-file-dialog.tsx b/web/src/components/workbench/move-file-dialog.tsx new file mode 100644 index 0000000..249dd43 --- /dev/null +++ b/web/src/components/workbench/move-file-dialog.tsx @@ -0,0 +1,245 @@ +import { CheckIcon, FolderIcon, Loader2Icon } from "lucide-react" +import { useCallback, useEffect, useState } from "react" +import { useTranslation } from "react-i18next" +import { cn } from "cn" +import { Button } from "@/components/ui/button" +import { + Dialog, + DialogContent, + DialogFooter, + DialogHeader, + DialogTitle +} from "@/components/ui/dialog" +import { filesApi, foldersApi } from "@/lib/api" +import { describeApiError } from "@/lib/api-errors" +import type { FileItem } from "@/lib/api-types" + +interface MoveFileDialogProps { + open: boolean + onOpenChange: (open: boolean) => void + file: FileItem | null + onSuccess: () => void +} + +interface FolderTreeNode { + id: string + name: string + parentId: string | null + children: FolderTreeNode[] +} + +interface FlatFolderItem { + id: string | null + name: string + depth: number +} + +function flattenTree(nodes: FolderTreeNode[], depth = 1): FlatFolderItem[] { + const result: FlatFolderItem[] = [] + for (const node of nodes) { + result.push({ id: node.id, name: node.name, depth }) + if (node.children && node.children.length > 0) { + result.push(...flattenTree(node.children, depth + 1)) + } + } + return result +} + +export function MoveFileDialog({ + open, + onOpenChange, + file, + onSuccess +}: MoveFileDialogProps) { + const { t } = useTranslation() + const [loading, setLoading] = useState(false) + const [busy, setBusy] = useState(false) + const [error, setError] = useState("") + const [folders, setFolders] = useState([]) + const [selectedFolderId, setSelectedFolderId] = useState< + string | null | undefined + >(undefined) + + const loadTree = useCallback(async () => { + setLoading(true) + setError("") + setSelectedFolderId(undefined) + const visited = new Set() + + async function getChildren( + parentId: string | null + ): Promise { + try { + const res = await foldersApi.list(parentId) + const validFolders = (res.folders || []).filter( + (f) => f.parentId === parentId && !visited.has(f.id) + ) + for (const f of validFolders) { + visited.add(f.id) + } + return await Promise.all( + validFolders.map(async (f) => ({ + id: f.id, + name: f.name, + parentId: f.parentId, + children: await getChildren(f.id) + })) + ) + } catch { + return [] + } + } + + try { + const rootFolders = await getChildren(null) + setFolders(rootFolders) + } catch (err) { + setError(describeApiError(t, err)) + } finally { + setLoading(false) + } + }, [t]) + + useEffect(() => { + if (open && file) { + void loadTree() + } else if (!open) { + setSelectedFolderId(undefined) + setError("") + setFolders([]) + setBusy(false) + } + }, [open, file, loadTree]) + + const handleOpenChange = (nextOpen: boolean) => { + if (!nextOpen) { + setSelectedFolderId(undefined) + setError("") + setFolders([]) + setBusy(false) + } + onOpenChange(nextOpen) + } + + const handleSelect = (folderId: string | null) => { + if (!file || file.folderId === folderId) return + setSelectedFolderId(folderId) + } + + const handleSubmit = async (e: React.FormEvent) => { + e.preventDefault() + if ( + !file || + selectedFolderId === undefined || + selectedFolderId === file.folderId + ) { + return + } + + setBusy(true) + setError("") + + try { + await filesApi.patch(file.id, { folderId: selectedFolderId }) + handleOpenChange(false) + onSuccess() + } catch (err) { + setError(describeApiError(t, err)) + } finally { + setBusy(false) + } + } + + const rootItem: FlatFolderItem = { + id: null, + name: t("workbench.moveDialog.rootDir"), + depth: 0 + } + const allItems: FlatFolderItem[] = [rootItem, ...flattenTree(folders)] + + const canSubmit = + !busy && + !loading && + file !== null && + selectedFolderId !== undefined && + selectedFolderId !== file.folderId + + return ( + + + + {t("workbench.moveDialog.title")} + +
+
+ {loading ? ( +
+ + {t("workbench.moveDialog.loading")} +
+ ) : ( + allItems.map((item) => { + const isCurrent = file ? file.folderId === item.id : false + const isSelected = selectedFolderId === item.id + + return ( + + ) + }) + )} +
+ + {error && ( +

+ {error} +

+ )} + + + + + +
+
+
+ ) +} diff --git a/web/src/components/workbench/rename-file-dialog.tsx b/web/src/components/workbench/rename-file-dialog.tsx new file mode 100644 index 0000000..3d274e1 --- /dev/null +++ b/web/src/components/workbench/rename-file-dialog.tsx @@ -0,0 +1,148 @@ +import { useCallback, useEffect, useRef, useState } from "react" +import { useTranslation } from "react-i18next" +import { Button } from "@/components/ui/button" +import { + Dialog, + DialogContent, + DialogFooter, + DialogHeader, + DialogTitle +} from "@/components/ui/dialog" +import { Input } from "@/components/ui/input" +import { filesApi } from "@/lib/api" +import { describeApiError } from "@/lib/api-errors" +import type { FileItem } from "@/lib/api-types" + +interface RenameFileDialogProps { + open: boolean + onOpenChange: (open: boolean) => void + file: FileItem | null + onSuccess: () => void +} + +export function RenameFileDialog({ + open, + onOpenChange, + file, + onSuccess +}: RenameFileDialogProps) { + const { t } = useTranslation() + const [name, setName] = useState("") + const [busy, setBusy] = useState(false) + const [error, setError] = useState("") + const inputRef = useRef(null) + + const selectBaseName = useCallback(() => { + const el = inputRef.current + if (!el) return + const val = el.value + const lastDot = val.lastIndexOf(".") + const end = lastDot > 0 ? lastDot : val.length + el.focus() + el.setSelectionRange(0, end) + }, []) + + useEffect(() => { + if (open && file) { + setName(file.name) + setError("") + } + }, [open, file]) + + useEffect(() => { + if (open && file && name === file.name) { + selectBaseName() + } + }, [open, file, name, selectBaseName]) + + const handleOpenChange = (nextOpen: boolean) => { + if (!nextOpen) { + setName("") + setError("") + setBusy(false) + } + onOpenChange(nextOpen) + } + + const handleSubmit = async (e: React.FormEvent) => { + e.preventDefault() + if (!file) return + + const trimmed = name.trim() + if (!trimmed) return + + if (trimmed === file.name) { + handleOpenChange(false) + return + } + + setBusy(true) + setError("") + + try { + await filesApi.patch(file.id, { name: trimmed }) + handleOpenChange(false) + onSuccess() + } catch (err) { + setError(describeApiError(t, err)) + } finally { + setBusy(false) + } + } + + return ( + + { + e.preventDefault() + selectBaseName() + }} + > + + {t("workbench.renameDialog.title")} + +
+ { + inputRef.current = node + if (node) { + node.select = () => { + const val = node.value + const lastDot = val.lastIndexOf(".") + const end = lastDot > 0 ? lastDot : val.length + node.setSelectionRange(0, end) + } + } + }} + value={name} + onChange={(e) => setName(e.target.value)} + placeholder={t("workbench.renameDialog.placeholder")} + disabled={busy} + data-testid="rename-file-input" + /> + {error && ( +

+ {error} +

+ )} + + + + +
+
+
+ ) +} diff --git a/web/src/components/workbench/usage-bar.tsx b/web/src/components/workbench/usage-bar.tsx index afe7025..1d16dcf 100644 --- a/web/src/components/workbench/usage-bar.tsx +++ b/web/src/components/workbench/usage-bar.tsx @@ -1,3 +1,4 @@ +import { cn } from "cn" import { useTranslation } from "react-i18next" import { Progress } from "@/components/ui/progress" import { formatBytes } from "@/lib/format" @@ -19,26 +20,37 @@ export function UsageBar({ quotaBytes > 0 ? Math.min(100, Math.round((usedBytes / quotaBytes) * 100)) : 0 + const isCritical = percent >= 90 return ( -
-
-
- {t("workbench.usage.label")} +
+
+ + {t("workbench.usage.label")} + +
{t("workbench.usage.detail", { used: formatBytes(usedBytes), total: formatBytes(quotaBytes) })} + · + + {t("workbench.usage.singleMax", { + size: formatBytes(singleMaxBytes) + })} +
- -
-
- {t("workbench.usage.singleMax", { - size: formatBytes(singleMaxBytes) - })}
+
) } diff --git a/web/src/lib/api-types.ts b/web/src/lib/api-types.ts index 7e3e7d8..ddd4346 100644 --- a/web/src/lib/api-types.ts +++ b/web/src/lib/api-types.ts @@ -263,6 +263,12 @@ export interface FileItem { } } +export interface PatchFileInput { + name?: string + folderId?: string | null + expiresIn?: string | null +} + export interface FolderListResponse { folder: FolderItem | null breadcrumbs: BreadcrumbItem[] diff --git a/web/src/lib/api.ts b/web/src/lib/api.ts index 03d1521..8080d33 100644 --- a/web/src/lib/api.ts +++ b/web/src/lib/api.ts @@ -16,6 +16,7 @@ import type { Me, MeUpdateInput, PasskeySummary, + PatchFileInput, PublicInfo, RegisterResult, SetupOwnerInput, @@ -631,6 +632,12 @@ export const filesApi = { } }, + patch: (id: string, input: PatchFileInput) => + request(`/files/${encodeURIComponent(id)}`, { + method: "PATCH", + body: input + }), + patchExpiration: (id: string, expiresIn?: string | null) => request<{ id: string; expiresAt: string | null }>( `/files/${encodeURIComponent(id)}`, diff --git a/web/src/locales/en.json b/web/src/locales/en.json index ddc726c..85f9d06 100644 --- a/web/src/locales/en.json +++ b/web/src/locales/en.json @@ -94,6 +94,7 @@ "QUOTA_EXCEEDED": "Storage quota exceeded", "FILE_NAME_CONFLICT": "A file with the same name already exists in this folder", "FOLDER_NAME_CONFLICT": "A folder with the same name already exists in this folder", + "INVALID_FILENAME": "Invalid file name", "FOLDER_NOT_FOUND": "Folder not found", "FILE_NOT_FOUND": "File not found or expired", "SHARE_NOT_FOUND": "Share link not found or expired", @@ -209,6 +210,8 @@ "newFolder": "New folder", "download": "Download", "share": "Share", + "rename": "Rename", + "moveTo": "Move to", "changeExpiration": "Change expiration", "delete": "Delete", "open": "Open", @@ -275,6 +278,19 @@ "expiration": "Expiration preset", "submit": "Save" }, + "renameDialog": { + "title": "Rename file", + "placeholder": "File name", + "submit": "Save" + }, + "moveDialog": { + "title": "Move file", + "rootDir": "Root folder", + "currentFolder": "Current folder", + "empty": "No other folders", + "loading": "Loading folders…", + "submit": "Move" + }, "deleteDialog": { "deleteFileTitle": "Delete file", "deleteFolderTitle": "Delete folder", diff --git a/web/src/locales/zh.json b/web/src/locales/zh.json index f50deda..63c1ea1 100644 --- a/web/src/locales/zh.json +++ b/web/src/locales/zh.json @@ -94,6 +94,7 @@ "QUOTA_EXCEEDED": "可用空间不足", "FILE_NAME_CONFLICT": "当前文件夹下已存在同名文件", "FOLDER_NAME_CONFLICT": "当前文件夹下已存在同名文件夹", + "INVALID_FILENAME": "文件名不合法", "FOLDER_NOT_FOUND": "文件夹不存在", "FILE_NOT_FOUND": "文件不存在或已失效", "SHARE_NOT_FOUND": "分享链接不存在或已失效", @@ -209,6 +210,8 @@ "newFolder": "新建文件夹", "download": "下载", "share": "分享", + "rename": "重命名", + "moveTo": "移动到", "changeExpiration": "修改过期", "delete": "删除", "open": "打开", @@ -275,6 +278,19 @@ "expiration": "过期预设", "submit": "保存" }, + "renameDialog": { + "title": "重命名文件", + "placeholder": "文件名", + "submit": "保存" + }, + "moveDialog": { + "title": "移动文件", + "rootDir": "根目录", + "currentFolder": "当前文件夹", + "empty": "无其他文件夹", + "loading": "正在加载文件夹…", + "submit": "移动" + }, "deleteDialog": { "deleteFileTitle": "删除文件", "deleteFolderTitle": "删除文件夹", diff --git a/web/src/pages/workbench.test.tsx b/web/src/pages/workbench.test.tsx index 19eba2f..95b7cba 100644 --- a/web/src/pages/workbench.test.tsx +++ b/web/src/pages/workbench.test.tsx @@ -19,6 +19,7 @@ vi.mock("@/lib/api", async (importOriginal) => { filesApi: { ...actual.filesApi, upload: vi.fn(), + patch: vi.fn(), patchExpiration: vi.fn(), delete: vi.fn() }, @@ -303,4 +304,183 @@ describe("WorkbenchPage", () => { await screen.findByText("文件大小超过单文件上限") ).toBeInTheDocument() }) + + it("重命名弹窗预填文件名并默认选中扩展名前缀,提交调用 patch name", async () => { + const user = userEvent.setup() + vi.mocked(filesApi.patch).mockResolvedValue({ + ...mockFolderData.files[0], + name: "renamed.jar" + }) + + render( + + + + ) + + await screen.findByText("app.jar") + await user.click(screen.getByTestId("file-menu-file-1")) + + const renameItem = await screen.findByText("重命名") + await user.click(renameItem) + + expect(await screen.findByText("重命名文件")).toBeInTheDocument() + const input = screen.getByTestId("rename-file-input") as HTMLInputElement + await waitFor(() => { + expect(input.selectionStart).toBe(0) + expect(input.selectionEnd).toBe(3) + }) + + await user.clear(input) + await user.type(input, "renamed.jar") + await user.click(screen.getByRole("button", { name: "保存" })) + + await waitFor(() => { + expect(filesApi.patch).toHaveBeenCalledWith("file-1", { + name: "renamed.jar" + }) + }) + }) + + it("重命名冲突(409)时弹窗内报错且不关闭弹窗", async () => { + const user = userEvent.setup() + vi.mocked(filesApi.patch).mockRejectedValue( + new ApiError({ + status: 409, + code: "FILE_NAME_CONFLICT", + message: "A file with the same name already exists in this folder" + }) + ) + + render( + + + + ) + + await screen.findByText("app.jar") + await user.click(screen.getByTestId("file-menu-file-1")) + await user.click(await screen.findByText("重命名")) + + const input = screen.getByTestId("rename-file-input") + await user.clear(input) + await user.type(input, "conflict.jar") + await user.click(screen.getByRole("button", { name: "保存" })) + + expect( + await screen.findByText("当前文件夹下已存在同名文件") + ).toBeInTheDocument() + expect(screen.getByText("重命名文件")).toBeInTheDocument() + }) + + it("移动文件弹窗展示根目录与文件夹树,当前所在标注且不可选,提交 patch folderId", async () => { + const user = userEvent.setup() + vi.mocked(filesApi.patch).mockResolvedValue({ + ...mockFolderData.files[0], + folderId: "f1" + }) + + render( + + + + ) + + await screen.findByText("app.jar") + await user.click(screen.getByTestId("file-menu-file-1")) + + const moveItem = await screen.findByText("移动到") + await user.click(moveItem) + + expect(await screen.findByText("移动文件")).toBeInTheDocument() + expect(await screen.findByText("根目录")).toBeInTheDocument() + expect(screen.getByTestId("move-target-f1")).toHaveTextContent( + "subfolder-1" + ) + + // 文件当前在根目录(folderId 为 null),根目录被标注且 disabled + const rootBtn = screen.getByTestId("move-target-root") + expect(rootBtn).toBeDisabled() + expect(rootBtn).toHaveTextContent("当前文件夹") + + const subfolderBtn = screen.getByTestId("move-target-f1") + expect(subfolderBtn).not.toBeDisabled() + + await user.click(subfolderBtn) + await user.click(screen.getByRole("button", { name: "移动" })) + + await waitFor(() => { + expect(filesApi.patch).toHaveBeenCalledWith("file-1", { + folderId: "f1" + }) + }) + }) + + it("文件在子文件夹中时移动到根目录提交 folderId 为 null", async () => { + const user = userEvent.setup() + const folderDataWithFileInSubfolder: FolderListResponse = { + ...mockFolderData, + files: [ + { + ...mockFolderData.files[0], + folderId: "f1" + } + ] + } + vi.mocked(foldersApi.list).mockResolvedValue(folderDataWithFileInSubfolder) + vi.mocked(filesApi.patch).mockResolvedValue({ + ...folderDataWithFileInSubfolder.files[0], + folderId: null + }) + + render( + + + + ) + + await screen.findByText("app.jar") + await user.click(screen.getByTestId("file-menu-file-1")) + await user.click(await screen.findByText("移动到")) + + expect(await screen.findByText("移动文件")).toBeInTheDocument() + const subfolderBtn = await screen.findByTestId("move-target-f1") + expect(subfolderBtn).toBeDisabled() + expect(subfolderBtn).toHaveTextContent("当前文件夹") + + const rootBtn = screen.getByTestId("move-target-root") + expect(rootBtn).not.toBeDisabled() + + await user.click(rootBtn) + await user.click(screen.getByRole("button", { name: "移动" })) + + await waitFor(() => { + expect(filesApi.patch).toHaveBeenCalledWith("file-1", { + folderId: null + }) + }) + }) + + it("用量条在 ≥90% 时使用红色警示样式", async () => { + const highUsageData: FolderListResponse = { + ...mockFolderData, + usage: { + usedBytes: 95 * 1048576, + quotaBytes: 100 * 1048576, + singleMaxBytes: 100 * 1048576 + } + } + vi.mocked(foldersApi.list).mockResolvedValue(highUsageData) + + render( + + + + ) + + await screen.findByText("app.jar") + const usageBar = screen.getByTestId("usage-bar") + expect(usageBar).toBeInTheDocument() + expect(usageBar.querySelector(".bg-destructive")).toBeInTheDocument() + }) }) diff --git a/web/src/pages/workbench.tsx b/web/src/pages/workbench.tsx index 3fcb4c7..317dcb3 100644 --- a/web/src/pages/workbench.tsx +++ b/web/src/pages/workbench.tsx @@ -12,6 +12,8 @@ import { } from "@/components/workbench/delete-confirm-dialog" import { EditExpirationDialog } from "@/components/workbench/edit-expiration-dialog" import { FileTable } from "@/components/workbench/file-table" +import { MoveFileDialog } from "@/components/workbench/move-file-dialog" +import { RenameFileDialog } from "@/components/workbench/rename-file-dialog" import { ShareDialog } from "@/components/workbench/share-dialog" import { UploadDialog } from "@/components/workbench/upload-dialog" import { UsageBar } from "@/components/workbench/usage-bar" @@ -43,6 +45,8 @@ export function WorkbenchPage() { const [createFolderOpen, setCreateFolderOpen] = useState(false) const [uploadOpen, setUploadOpen] = useState(false) const [shareFile, setShareFile] = useState(null) + const [renameFile, setRenameFile] = useState(null) + const [moveFile, setMoveFile] = useState(null) const [editExpFile, setEditExpFile] = useState(null) const [deleteTarget, setDeleteTarget] = useState(null) @@ -130,6 +134,8 @@ export function WorkbenchPage() { onOpenFolder={handleSelectFolder} onDeleteFolder={(f) => setDeleteTarget({ type: "folder", item: f })} onShareFile={(file) => setShareFile(file)} + onRenameFile={(file) => setRenameFile(file)} + onMoveFile={(file) => setMoveFile(file)} onEditExpiration={(file) => setEditExpFile(file)} onDeleteFile={(file) => setDeleteTarget({ type: "file", item: file }) @@ -164,6 +170,24 @@ export function WorkbenchPage() { file={shareFile} /> + { + if (!open) setRenameFile(null) + }} + file={renameFile} + onSuccess={loadData} + /> + + { + if (!open) setMoveFile(null) + }} + file={moveFile} + onSuccess={loadData} + /> + { From 8be510e1b75e23cb042100311966401098a927f2 Mon Sep 17 00:00:00 2001 From: mapxn <16299874+mapxn@users.noreply.github.com> Date: Thu, 19 Nov 2026 23:10:31 +0800 Subject: [PATCH 2/2] fix(web): surface move tree root error, drop unused key and rebase on main --- .../components/workbench/move-file-dialog.tsx | 22 ++++++++++---- web/src/locales/en.json | 1 - web/src/locales/zh.json | 1 - web/src/pages/workbench.test.tsx | 29 +++++++++++++++++++ 4 files changed, 46 insertions(+), 7 deletions(-) diff --git a/web/src/components/workbench/move-file-dialog.tsx b/web/src/components/workbench/move-file-dialog.tsx index 249dd43..3bb08bd 100644 --- a/web/src/components/workbench/move-file-dialog.tsx +++ b/web/src/components/workbench/move-file-dialog.tsx @@ -66,9 +66,7 @@ export function MoveFileDialog({ setSelectedFolderId(undefined) const visited = new Set() - async function getChildren( - parentId: string | null - ): Promise { + async function getSubTree(parentId: string): Promise { try { const res = await foldersApi.list(parentId) const validFolders = (res.folders || []).filter( @@ -82,7 +80,7 @@ export function MoveFileDialog({ id: f.id, name: f.name, parentId: f.parentId, - children: await getChildren(f.id) + children: await getSubTree(f.id) })) ) } catch { @@ -91,7 +89,21 @@ export function MoveFileDialog({ } try { - const rootFolders = await getChildren(null) + const res = await foldersApi.list(null) + const validFolders = (res.folders || []).filter( + (f) => f.parentId === null && !visited.has(f.id) + ) + for (const f of validFolders) { + visited.add(f.id) + } + const rootFolders = await Promise.all( + validFolders.map(async (f) => ({ + id: f.id, + name: f.name, + parentId: f.parentId, + children: await getSubTree(f.id) + })) + ) setFolders(rootFolders) } catch (err) { setError(describeApiError(t, err)) diff --git a/web/src/locales/en.json b/web/src/locales/en.json index 85f9d06..d400957 100644 --- a/web/src/locales/en.json +++ b/web/src/locales/en.json @@ -287,7 +287,6 @@ "title": "Move file", "rootDir": "Root folder", "currentFolder": "Current folder", - "empty": "No other folders", "loading": "Loading folders…", "submit": "Move" }, diff --git a/web/src/locales/zh.json b/web/src/locales/zh.json index 63c1ea1..d7c6bb2 100644 --- a/web/src/locales/zh.json +++ b/web/src/locales/zh.json @@ -287,7 +287,6 @@ "title": "移动文件", "rootDir": "根目录", "currentFolder": "当前文件夹", - "empty": "无其他文件夹", "loading": "正在加载文件夹…", "submit": "移动" }, diff --git a/web/src/pages/workbench.test.tsx b/web/src/pages/workbench.test.tsx index 95b7cba..d18ddc5 100644 --- a/web/src/pages/workbench.test.tsx +++ b/web/src/pages/workbench.test.tsx @@ -461,6 +461,35 @@ describe("WorkbenchPage", () => { }) }) + it("移动弹窗在根目录文件夹列表拉取失败时呈现错误提示", async () => { + const user = userEvent.setup() + vi.mocked(foldersApi.list) + .mockResolvedValueOnce(mockFolderData) + .mockRejectedValueOnce( + new ApiError({ + status: 500, + code: "INTERNAL_ERROR", + message: "Database error" + }) + ) + + render( + + + + ) + + await screen.findByText("app.jar") + await user.click(screen.getByTestId("file-menu-file-1")) + await user.click(await screen.findByText("移动到")) + + expect(await screen.findByText("移动文件")).toBeInTheDocument() + const errorEl = await screen.findByTestId("move-error") + expect(errorEl).toBeInTheDocument() + expect(errorEl.textContent).toBeTruthy() + expect(screen.getByRole("button", { name: "移动" })).toBeDisabled() + }) + it("用量条在 ≥90% 时使用红色警示样式", async () => { const highUsageData: FolderListResponse = { ...mockFolderData,