feat(file-browser): add copy name and path option to context menu

This commit is contained in:
yiling
2026-07-27 10:23:22 +08:00
parent d81fc09b35
commit f429873362
20 changed files with 284 additions and 13 deletions
@@ -30,6 +30,7 @@ interface FileBrowserContextMenuProps {
onRename: (item: AssetInfo) => void
onDelete: (items: AssetInfo[]) => void
onDownload: (items: AssetInfo[]) => void
onCopyNameAndPath?: (items: AssetInfo[]) => void
onRestore: (items: AssetInfo[]) => void
onNewFolder: (name: string) => void
onUploadFile: () => void
@@ -55,6 +56,7 @@ export function FileBrowserContextMenu({
onRename,
onDelete,
onDownload,
onCopyNameAndPath,
onRestore,
onNewFolder,
onUploadFile,
@@ -98,6 +100,14 @@ export function FileBrowserContextMenu({
}
}
const handleCopyNameAndPath = () => {
if (isItemSelected) {
onCopyNameAndPath?.(selectedItems)
} else if (item) {
onCopyNameAndPath?.([item])
}
}
const handleRestore = () => {
onRestore(itemsToRestore)
}
@@ -110,6 +120,10 @@ export function FileBrowserContextMenu({
<Download className="mr-2 h-4 w-4" />
<span>{m.download()}</span>
</ContextMenuItem>
<ContextMenuItem onSelect={handleCopyNameAndPath}>
<Copy className="mr-2 h-4 w-4" />
<span>{m.copy_name_and_path()}</span>
</ContextMenuItem>
{canEdit && (
<ContextMenuItem
onSelect={() => onRemoveFromShare?.(itemsToModify)}
@@ -177,6 +191,10 @@ export function FileBrowserContextMenu({
<Download className="mr-2 h-4 w-4" />
<span>{m.download()}</span>
</ContextMenuItem>
<ContextMenuItem onSelect={handleCopyNameAndPath}>
<Copy className="mr-2 h-4 w-4" />
<span>{m.copy_name_and_path()}</span>
</ContextMenuItem>
{canEdit && (
<ContextMenuItem onSelect={() => onMoveTo(itemsToModify)}>
<ArrowRight className="mr-2 h-4 w-4" />
@@ -247,6 +265,10 @@ export function FileBrowserContextMenu({
<Download className="mr-2 h-4 w-4" />
<span>{m.download()}</span>
</ContextMenuItem>
<ContextMenuItem onSelect={handleCopyNameAndPath}>
<Copy className="mr-2 h-4 w-4" />
<span>{m.copy_name_and_path()}</span>
</ContextMenuItem>
{canEdit && (
<ContextMenuItem onSelect={() => onMoveTo(itemsToModify)}>
@@ -400,6 +400,7 @@ export function FileBrowser({
handleRename,
handleRestore,
handleDownload,
handleCopyNameAndPath,
handleAction,
onRenameSubmit,
isDeleteDialogOpen,
@@ -1161,6 +1162,7 @@ export function FileBrowser({
onRename={handleRename}
onDelete={handleDelete}
onDownload={handleDownload}
onCopyNameAndPath={handleCopyNameAndPath}
onNewFolder={handleNewFolder}
onUploadFile={handleUploadFilesClick}
onUploadFolder={handleUploadFolderClick}
@@ -6,6 +6,8 @@ import { useMutation, useQueryClient } from '@tanstack/react-query'
import type { InferRequestType, InferResponseType } from 'hono/client'
import { useState } from 'react'
import { toast } from 'sonner'
import { copyToClipboard } from '@/ui/lib/clipboard'
import { m } from '@/ui/paraglide/messages.js'
interface UseFileActionsProps {
teamId: string
@@ -226,6 +228,32 @@ export function useFileActions({
}
}
const handleCopyNameAndPath = async (items: AssetInfo[]) => {
if (items.length === 0) return
try {
const res = await getDownloadLinks({
json: { ids: items.map((i) => i.id!) },
})
const files = res.files
if (files.length === 0) return
let text = ''
if (files.length === 1) {
text = `Name: ${files[0].name}\nPath: ${files[0].url}`
} else {
text = files.map((f) => `${f.name}\t${f.url}`).join('\n')
}
const ok = await copyToClipboard(text)
if (ok) {
toast.success(m.copied_name_and_path_to_clipboard())
}
} catch (error) {
toast.error('Failed to copy name and path')
console.error(error)
}
}
const startDownload = () => {
const files = [...resolvedFiles]
setIsDownloadDialogOpen(false)
@@ -321,7 +349,10 @@ export function useFileActions({
}
}
const handleAction = (action: 'rename' | 'delete' | 'download' | 'restore', item: AssetInfo) => {
const handleAction = (
action: 'rename' | 'delete' | 'download' | 'restore' | 'copy-name-and-path',
item: AssetInfo,
) => {
const isSelected = selectedIds.has(item.id!)
const targetItems = isSelected
? [...folders, ...files].filter((i) => selectedIds.has(i.id!))
@@ -340,6 +371,9 @@ export function useFileActions({
case 'restore':
handleRestore(targetItems)
break
case 'copy-name-and-path':
handleCopyNameAndPath(targetItems)
break
}
}
@@ -350,6 +384,7 @@ export function useFileActions({
handleDelete,
handleRestore,
handleDownload,
handleCopyNameAndPath,
handleNewFolder,
handleAction,
onRenameSubmit,
+6 -3
View File
@@ -22,6 +22,7 @@ import { Input } from '@/ui/components/ui/input'
import { ChevronDown, Copy, Loader2, Trash2 } from 'lucide-react'
import { useState } from 'react'
import { toast } from 'sonner'
import { copyToClipboard as copyTextToClipboard } from '@/ui/lib/clipboard'
import { m } from '@/ui/paraglide/messages.js'
export interface Member {
@@ -131,10 +132,12 @@ export function MembersDialog({
}
}
const copyToClipboard = () => {
const copyToClipboard = async () => {
if (inviteLink) {
navigator.clipboard.writeText(inviteLink)
toast.success(m.invite_link_copied())
const ok = await copyTextToClipboard(inviteLink)
if (ok) {
toast.success(m.invite_link_copied())
}
}
}
@@ -14,6 +14,7 @@ import {
} from '@/ui/components/ui/table'
import { Loader2, Plus, Trash2, Copy, Check } from 'lucide-react'
import { toast } from 'sonner'
import { copyToClipboard } from '@/ui/lib/clipboard'
import type { ApiTokenResponse } from '@shumai/dtos'
import { m } from '@/ui/paraglide/messages.js'
@@ -75,8 +76,8 @@ export function DeveloperSettings({ teamId }: { teamId: string }) {
createToken(tokenName.trim())
}
const handleCopy = (id: string, token: string) => {
navigator.clipboard.writeText(token)
const handleCopy = async (id: string, token: string) => {
await copyToClipboard(token)
setCopiedId(id)
toast.success(m.copied_api_token_to_clipboard())
setTimeout(() => setCopiedId(null), 2000)
@@ -21,6 +21,7 @@ import {
} from 'lucide-react'
import React, { useState } from 'react'
import { toast } from 'sonner'
import { copyToClipboard as copyTextToClipboard } from '@/ui/lib/clipboard'
import { DateTimePicker } from '@/ui/components/datetime-picker'
import {
Select,
@@ -88,9 +89,11 @@ export function ShareSettingsSidebar({
const shareUrl = `${window.location.origin}/share/${shareLink.id}`
const copyToClipboard = (text: string) => {
navigator.clipboard.writeText(text)
toast.success(m.copied_to_clipboard())
const copyToClipboard = async (text: string) => {
const ok = await copyTextToClipboard(text)
if (ok) {
toast.success(m.copied_to_clipboard())
}
}
const toggleFieldVisibility = (fieldId: string) => {