feat(share): allow creating share links from media view with quick share dialog (#548)

* feat(share): allow creating share links from media view with quick share dialog

* fix(share): prevent horizontal overflow in quick share dialog
This commit is contained in:
Yiling-J
2026-11-24 19:39:06 +08:00
committed by GitHub
parent dc9adcf9ac
commit 9c8eb16259
24 changed files with 1457 additions and 266 deletions
@@ -25,7 +25,7 @@ import { selectFileNameWithoutExtension } from '@/ui/lib/rename-utils'
import { m } from '@/ui/paraglide/messages.js'
import { useMemberStore } from '@/ui/stores/members'
import type { Annotation } from '@/ui/types'
import type { AncestorFolder, AssetInfo, CommentInfo, FieldInfo } from '@shumai/dtos'
import type { AncestorFolder, AssetInfo, CommentInfo, FieldInfo, ShareLinkInfo } from '@shumai/dtos'
import { useQuery } from '@tanstack/react-query'
import { Loader2 } from 'lucide-react'
import React, { useEffect, useMemo, useRef, useState } from 'react'
@@ -61,6 +61,10 @@ export interface MobileFileDetailProps {
onDeleteFile?: () => Promise<void>
onArchiveFile?: () => void
onRestoreArchiveFile?: () => void
shareLinks?: ShareLinkInfo[]
onCreateShareLink?: () => void
onAddToShareLink?: (shareId: string) => void
isShareActionPending?: boolean
onSaveField: (fieldId: string, value: unknown) => void
onSelectVersion?: (versionId: string) => void
}
@@ -86,6 +90,10 @@ export function MobileFileDetail({
onDeleteFile,
onArchiveFile,
onRestoreArchiveFile,
shareLinks,
onCreateShareLink,
onAddToShareLink,
isShareActionPending = false,
onSaveField,
onSelectVersion,
}: MobileFileDetailProps) {
@@ -240,6 +248,10 @@ export function MobileFileDetail({
onDelete={() => setIsDeleteDialogOpen(true)}
onArchive={onArchiveFile}
onRestoreArchive={onRestoreArchiveFile}
shareLinks={shareLinks}
onCreateShareLink={onCreateShareLink}
onAddToShareLink={onAddToShareLink}
isShareActionPending={isShareActionPending}
onLinkedTasks={!isPublic ? () => setIsLinkedTasksOpen(true) : undefined}
linkedTaskCount={linkedTaskCount}
/>
@@ -216,4 +216,83 @@ describe('MobileFileHeader', () => {
expect(screen.queryByText('Restoring...')).toBeNull()
expect(screen.queryByText('恢复中...')).toBeNull()
})
it('renders Create Share Link and Add to Share Links at top of three-dot menu above Download for editors', () => {
const onCreateShareLink = vi.fn()
const onAddToShareLink = vi.fn()
render(
<MobileFileHeader
fileName="clip.mp4"
activeFileId="file-1"
canEdit={true}
allowDownload={true}
downloadInfo={{ originalKey: 'clip.mp4' }}
shareLinks={[
{
id: 'share-1',
name: 'Client Review',
isDisabled: false,
allowDownload: true,
hasPassword: false,
rootFolderId: 'rf-1',
projectId: 'proj-1',
isExpired: false,
createdAt: '2026-11-24T00:00:00.000Z',
updatedAt: '2026-11-24T00:00:00.000Z',
},
]}
onCreateShareLink={onCreateShareLink}
onAddToShareLink={onAddToShareLink}
onBack={vi.fn()}
/>,
)
const menuBtn = screen.getByLabelText(/More options/i)
fireEvent.pointerDown(menuBtn, { button: 0, ctrlKey: false })
const items = screen.getAllByRole('menuitem')
expect(items[0].textContent).toContain('Create Share Link')
expect(items[1].textContent).toContain('Add to Share Links')
expect(items[2].textContent).toContain('Download')
fireEvent.click(items[0])
expect(onCreateShareLink).toHaveBeenCalledTimes(1)
fireEvent.pointerDown(menuBtn, { button: 0, ctrlKey: false })
fireEvent.click(screen.getByText('Add to Share Links'))
fireEvent.click(screen.getByText('Client Review'))
expect(onAddToShareLink).toHaveBeenCalledWith('share-1')
})
it('hides share link options when public or when canEdit is false', () => {
const { rerender } = render(
<MobileFileHeader
fileName="clip.mp4"
activeFileId="file-1"
canEdit={false}
onCreateShareLink={vi.fn()}
onAddToShareLink={vi.fn()}
onBack={vi.fn()}
/>,
)
const menuBtn = screen.getByLabelText(/More options/i)
fireEvent.pointerDown(menuBtn, { button: 0, ctrlKey: false })
expect(screen.queryByText('Create Share Link')).toBeNull()
rerender(
<MobileFileHeader
fileName="clip.mp4"
activeFileId="file-1"
canEdit={true}
isPublic={true}
onCreateShareLink={vi.fn()}
onAddToShareLink={vi.fn()}
onBack={vi.fn()}
/>,
)
expect(screen.queryByText('Create Share Link')).toBeNull()
})
})
@@ -15,6 +15,7 @@ import {
} from '@/ui/components/ui/dropdown-menu'
import { cn } from '@/ui/lib/utils'
import { m } from '@/ui/paraglide/messages.js'
import type { ShareLinkInfo } from '@shumai/dtos'
import {
Archive,
ArchiveRestore,
@@ -22,9 +23,11 @@ import {
ChevronLeft,
ChevronRight,
Download,
Link as LinkIcon,
Loader2,
MoreVertical,
Pencil,
Plus,
SquareKanban,
Trash2,
} from 'lucide-react'
@@ -67,6 +70,10 @@ export interface MobileFileHeaderProps {
onDelete?: () => void
onArchive?: () => void
onRestoreArchive?: () => void
shareLinks?: ShareLinkInfo[]
onCreateShareLink?: () => void
onAddToShareLink?: (shareId: string) => void
isShareActionPending?: boolean
onLinkedTasks?: () => void
linkedTaskCount?: number
}
@@ -93,6 +100,10 @@ export function MobileFileHeader({
onDelete,
onArchive,
onRestoreArchive,
shareLinks,
onCreateShareLink,
onAddToShareLink,
isShareActionPending = false,
onLinkedTasks,
linkedTaskCount = 0,
}: MobileFileHeaderProps) {
@@ -279,6 +290,42 @@ export function MobileFileHeader({
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end" className="w-52 z-40">
{/* Share Links */}
{canEdit && !isPublic && onCreateShareLink && (
<>
<DropdownMenuItem
onClick={onCreateShareLink}
disabled={isShareActionPending}
className="flex items-center gap-2 text-xs cursor-pointer"
>
<Plus className="h-3.5 w-3.5" />
<span>{m.create_share_link()}</span>
</DropdownMenuItem>
{shareLinks && shareLinks.length > 0 && onAddToShareLink && (
<DropdownMenuSub>
<DropdownMenuSubTrigger className="flex items-center gap-2 text-xs cursor-pointer">
<LinkIcon className="h-3.5 w-3.5" />
<span>{m.add_to_share_links()}</span>
</DropdownMenuSubTrigger>
<DropdownMenuPortal>
<DropdownMenuSubContent className="w-48 z-50">
{shareLinks.map((share) => (
<DropdownMenuItem
key={share.id}
disabled={isShareActionPending}
onClick={() => onAddToShareLink(share.id)}
className="text-xs cursor-pointer"
>
<span className="truncate">{share.name}</span>
</DropdownMenuItem>
))}
</DropdownMenuSubContent>
</DropdownMenuPortal>
</DropdownMenuSub>
)}
</>
)}
{/* Download */}
{allowDownload &&
(hasVideoTranscodes ? (