feat(file-browser): add context-aware copy submenu (#517)

* feat(file-browser): add context-aware copy submenu

* refactor(file-browser): address code review feedback for copy submenu

* fix(webui): align submenu trigger text and widen file context menu

* test(e2e): guard clipboard permissions in copy-menu spec for cross-browser support
This commit is contained in:
Yiling-J
2026-11-05 09:57:34 +08:00
committed by GitHub
parent 2ecbd49d18
commit 0dc0bbeb03
30 changed files with 2285 additions and 106 deletions
@@ -26,6 +26,8 @@ import {
Copy,
Layers,
} from 'lucide-react'
import { CopyContextMenuSub } from './copy-submenu'
import type { CopyKind } from './copy-options'
interface FileBrowserContextMenuProps {
item: AssetInfo | null
@@ -33,11 +35,13 @@ interface FileBrowserContextMenuProps {
onRename: (item: AssetInfo) => void
onDelete: (items: AssetInfo[]) => void
onDownload: (items: AssetInfo[]) => void
onCopyNameAndDownloadLink?: (items: AssetInfo[]) => void
onCopy?: (kind: CopyKind, items: AssetInfo[]) => void
onRestore: (items: AssetInfo[]) => void
onArchive?: (items: AssetInfo[]) => void
onRestoreArchive?: (items: AssetInfo[]) => void
archiveStorageEnabled?: boolean
isTeamOwner?: boolean
allowDownload?: boolean
onNewFolder: (name: string) => void
onUploadFile: () => void
onUploadFolder: () => void
@@ -64,11 +68,13 @@ export function FileBrowserContextMenu({
onRename,
onDelete,
onDownload,
onCopyNameAndDownloadLink,
onCopy,
onRestore,
onArchive,
onRestoreArchive,
archiveStorageEnabled = false,
isTeamOwner = false,
allowDownload = true,
onNewFolder,
onUploadFile,
onUploadFolder,
@@ -113,14 +119,6 @@ export function FileBrowserContextMenu({
}
}
const handleCopyNameAndDownloadLink = () => {
if (isItemSelected) {
onCopyNameAndDownloadLink?.(selectedItems)
} else if (item) {
onCopyNameAndDownloadLink?.([item])
}
}
const handleRestore = () => {
onRestore(itemsToRestore)
}
@@ -162,15 +160,11 @@ export function FileBrowserContextMenu({
if (isShareView) {
if (!item) return null
return (
<ContextMenuContent>
<ContextMenuContent className="w-52">
<ContextMenuItem onSelect={handleDownload}>
<Download className="mr-2 h-4 w-4" />
<span>{m.download()}</span>
</ContextMenuItem>
<ContextMenuItem onSelect={handleCopyNameAndDownloadLink}>
<Copy className="mr-2 h-4 w-4" />
<span>{m.copy_name_and_download_link()}</span>
</ContextMenuItem>
{canEdit && (
<ContextMenuItem
onSelect={() => onRemoveFromShare?.(itemsToModify)}
@@ -189,7 +183,7 @@ export function FileBrowserContextMenu({
return null
}
return (
<ContextMenuContent>
<ContextMenuContent className="w-52">
<ContextMenuItem onSelect={handleRestore}>
<History className="mr-2 h-4 w-4" />
<span>{m.restore()}</span>
@@ -203,6 +197,7 @@ export function FileBrowserContextMenu({
// Right-click on empty area
return (
<ContextMenuContent
className="w-52"
onCloseAutoFocus={(e) => {
e.preventDefault()
}}
@@ -230,6 +225,7 @@ export function FileBrowserContextMenu({
const contextMenuContent =
isItemSelected && selectedIds.size > 1 ? (
<ContextMenuContent
className="w-52"
onCloseAutoFocus={(e) => {
e.preventDefault()
}}
@@ -238,10 +234,14 @@ export function FileBrowserContextMenu({
<Download className="mr-2 h-4 w-4" />
<span>{m.download()}</span>
</ContextMenuItem>
<ContextMenuItem onSelect={handleCopyNameAndDownloadLink} disabled={isDownloadUnavailable}>
<Copy className="mr-2 h-4 w-4" />
<span>{m.copy_name_and_download_link()}</span>
</ContextMenuItem>
<CopyContextMenuSub
items={itemsToModify}
context={{
isTeamOwner,
allowDownload,
}}
onCopy={(kind, targetItems) => onCopy?.(kind, targetItems)}
/>
{canEdit && (
<ContextMenuItem onSelect={() => onMoveTo(itemsToModify)}>
<ArrowRight className="mr-2 h-4 w-4" />
@@ -294,7 +294,7 @@ export function FileBrowserContextMenu({
<span>{m.add_to_share_links()}</span>
</ContextMenuSubTrigger>
<ContextMenuPortal>
<ContextMenuSubContent className="w-48">
<ContextMenuSubContent className="w-52">
{shareLinks.map((share) => (
<ContextMenuItem
key={share.id}
@@ -312,6 +312,7 @@ export function FileBrowserContextMenu({
</ContextMenuContent>
) : (
<ContextMenuContent
className="w-52"
onCloseAutoFocus={(e) => {
e.preventDefault()
}}
@@ -330,10 +331,14 @@ export function FileBrowserContextMenu({
<Download className="mr-2 h-4 w-4" />
<span>{m.download()}</span>
</ContextMenuItem>
<ContextMenuItem onSelect={handleCopyNameAndDownloadLink} disabled={isDownloadUnavailable}>
<Copy className="mr-2 h-4 w-4" />
<span>{m.copy_name_and_download_link()}</span>
</ContextMenuItem>
<CopyContextMenuSub
items={itemsToModify}
context={{
isTeamOwner,
allowDownload,
}}
onCopy={(kind, targetItems) => onCopy?.(kind, targetItems)}
/>
{canEdit && (
<ContextMenuItem onSelect={() => onMoveTo(itemsToModify)}>
@@ -409,7 +414,7 @@ export function FileBrowserContextMenu({
<span>{m.add_to_share_links()}</span>
</ContextMenuSubTrigger>
<ContextMenuPortal>
<ContextMenuSubContent className="w-48">
<ContextMenuSubContent className="w-52">
{shareLinks.map((share) => (
<ContextMenuItem
key={share.id}