mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-02 05:54:44 +00:00
feat(webui): open projects and assets in new tabs (#558)
This commit is contained in:
@@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
||||
### Added
|
||||
|
||||
- **sessions**: See total tokens and estimated cost in the session logs footer, with a breakdown of input, output, and cached tokens.
|
||||
- **projects**: Middle-click or Command/Ctrl-click a project to open it in a new tab. Use **Open in new tab** in a file or folder's context menu to keep your current view open.
|
||||
|
||||
### Fixed
|
||||
|
||||
|
||||
@@ -74,6 +74,8 @@ apps/web/e2e/
|
||||
| Test | File |
|
||||
|---|---|
|
||||
| Owner creates a project with a cover image | `tests/project/create-project.spec.ts` |
|
||||
| Owner opens project cards in new tabs with middle-click and modifier-click | `tests/project/open-in-new-tab.spec.ts` |
|
||||
| Owner opens a folder card and a file row in new tabs from the context menu | `tests/project/open-in-new-tab.spec.ts` |
|
||||
| Owner uploads a file or an unsupported file via the "Upload File" context menu action | `tests/project/upload-file.spec.ts` |
|
||||
| Owner deletes a file, finds it in recently deleted, and restores it | `tests/project/delete-restore.spec.ts` |
|
||||
| Owner deletes a folder and still sees its contents preview and countdown in recently deleted | `tests/project/delete-restore.spec.ts` |
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
import { expect, test } from '../../fixtures'
|
||||
import { seedFolder } from '../../helpers/assets'
|
||||
import { fileCard } from '../../helpers/files'
|
||||
|
||||
test('project cards open in a new tab with middle-click and modifier-click', async ({
|
||||
project,
|
||||
}) => {
|
||||
const { page, context, teamId, projectId, projectName } = project
|
||||
await page.reload()
|
||||
const projectLink = page.getByRole('link', { name: projectName, exact: true })
|
||||
|
||||
const [middleClickTab] = await Promise.all([
|
||||
context.waitForEvent('page'),
|
||||
projectLink.click({ button: 'middle' }),
|
||||
])
|
||||
await expect(middleClickTab).toHaveURL(`/projects/${projectId}`)
|
||||
await expect(page).toHaveURL(`/teams/${teamId}`)
|
||||
await middleClickTab.close()
|
||||
|
||||
const [modifierClickTab] = await Promise.all([
|
||||
context.waitForEvent('page'),
|
||||
projectLink.click({ modifiers: ['ControlOrMeta'] }),
|
||||
])
|
||||
await expect(modifierClickTab).toHaveURL(`/projects/${projectId}`)
|
||||
await expect(page).toHaveURL(`/teams/${teamId}`)
|
||||
await modifierClickTab.close()
|
||||
|
||||
await page.getByRole('button', { name: 'More options' }).click()
|
||||
await expect(page.getByRole('menuitem', { name: 'Project Settings' })).toBeVisible()
|
||||
await expect(page).toHaveURL(`/teams/${teamId}`)
|
||||
await page.keyboard.press('Escape')
|
||||
|
||||
await projectLink.click()
|
||||
await expect(page).toHaveURL(`/projects/${projectId}`)
|
||||
})
|
||||
|
||||
test('the context menu opens a folder card and a file row in new tabs', async ({
|
||||
file,
|
||||
prisma,
|
||||
}) => {
|
||||
const { page, context, projectId, rootFolderId, fileId, fileName } = file
|
||||
const projectPath = `/projects/${projectId}`
|
||||
const folder = await seedFolder(prisma, projectId, rootFolderId, 'Test folder')
|
||||
await page.goto(projectPath)
|
||||
|
||||
const openInNewTab = page.getByRole('menuitem', { name: 'Open in new tab' })
|
||||
await fileCard(page, folder.name).click({ button: 'right' })
|
||||
await expect(openInNewTab).toBeVisible()
|
||||
expect(context.pages()).toHaveLength(1)
|
||||
const [folderTab] = await Promise.all([context.waitForEvent('page'), openInNewTab.click()])
|
||||
await expect(folderTab).toHaveURL(`${projectPath}/folders/${folder.id}`)
|
||||
await expect(page).toHaveURL(projectPath)
|
||||
await folderTab.close()
|
||||
|
||||
await page.getByRole('button', { name: 'List View' }).click()
|
||||
const fileRow = fileCard(page, fileName)
|
||||
const fileLabel = fileRow.getByText(fileName, { exact: true })
|
||||
const selected = fileRow.getByRole('checkbox')
|
||||
await fileLabel.click()
|
||||
await expect(selected).toBeChecked()
|
||||
await expect(page).toHaveURL(projectPath)
|
||||
|
||||
await fileLabel.click({ button: 'right' })
|
||||
const [fileTab] = await Promise.all([context.waitForEvent('page'), openInNewTab.press('Enter')])
|
||||
await expect(fileTab).toHaveURL(`${projectPath}/files/${fileId}`)
|
||||
await expect(page).toHaveURL(projectPath)
|
||||
await expect(selected).toBeChecked()
|
||||
})
|
||||
@@ -9,6 +9,7 @@ import type { AssetInfo } from '@shumai/dtos'
|
||||
describe('FileBrowserContextMenu', () => {
|
||||
afterEach(() => {
|
||||
cleanup()
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
|
||||
const stackItem: AssetInfo = {
|
||||
@@ -60,6 +61,32 @@ describe('FileBrowserContextMenu', () => {
|
||||
)
|
||||
}
|
||||
|
||||
it('opens the supplied URL in a new tab for a read-only member', () => {
|
||||
const url = '/projects/project-123/files/file-123'
|
||||
const open = vi.spyOn(window, 'open').mockReturnValue(null)
|
||||
renderWithMenu(fileItem, { canEdit: false, openInNewTabHref: url })
|
||||
|
||||
fireEvent.contextMenu(screen.getByTestId('context-trigger'))
|
||||
const newTabItem = screen.getByRole('menuitem', { name: 'Open in new tab' })
|
||||
fireEvent.pointerUp(newTabItem, { button: 2, pointerType: 'mouse' })
|
||||
expect(open).not.toHaveBeenCalled()
|
||||
|
||||
fireEvent.click(newTabItem)
|
||||
expect(open).toHaveBeenCalledWith(url, '_blank', 'noopener,noreferrer')
|
||||
})
|
||||
|
||||
it('omits the new-tab action for a multi-item selection', () => {
|
||||
renderWithMenu(fileItem, {
|
||||
files: [fileItem, stackItem],
|
||||
selectedIds: new Set([fileItem.id, stackItem.id]),
|
||||
openInNewTabHref: '/projects/project-123/files/file-123',
|
||||
})
|
||||
|
||||
fireEvent.contextMenu(screen.getByTestId('context-trigger'))
|
||||
|
||||
expect(screen.queryByRole('menuitem', { name: 'Open in new tab' })).toBeNull()
|
||||
})
|
||||
|
||||
it('renders Manage versions for version_stack item when canEdit is true', () => {
|
||||
const onManageVersions = vi.fn()
|
||||
renderWithMenu(stackItem, { onManageVersions })
|
||||
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
ArchiveRestore,
|
||||
Download,
|
||||
Edit,
|
||||
ExternalLink,
|
||||
FolderPlus,
|
||||
Trash2,
|
||||
UploadCloud,
|
||||
@@ -33,6 +34,7 @@ import { isImageItem, type CopyKind } from './copy-options'
|
||||
interface FileBrowserContextMenuProps {
|
||||
item: AssetInfo | null
|
||||
selectedIds: Set<string>
|
||||
openInNewTabHref?: string
|
||||
onRename: (item: AssetInfo) => void
|
||||
onDelete: (items: AssetInfo[]) => void
|
||||
onDownload: (items: AssetInfo[]) => void
|
||||
@@ -67,6 +69,7 @@ interface FileBrowserContextMenuProps {
|
||||
export function FileBrowserContextMenu({
|
||||
item,
|
||||
selectedIds,
|
||||
openInNewTabHref,
|
||||
onRename,
|
||||
onDelete,
|
||||
onDownload,
|
||||
@@ -330,6 +333,18 @@ export function FileBrowserContextMenu({
|
||||
e.preventDefault()
|
||||
}}
|
||||
>
|
||||
{openInNewTabHref && (
|
||||
<ContextMenuItem
|
||||
onPointerUp={(event) => {
|
||||
// Radix can synthesize a click as the right button that opened the menu is released.
|
||||
if (event.button !== 0) event.preventDefault()
|
||||
}}
|
||||
onSelect={() => window.open(openInNewTabHref, '_blank', 'noopener,noreferrer')}
|
||||
>
|
||||
<ExternalLink className="mr-2 h-4 w-4" />
|
||||
<span>{m.open_in_new_tab()}</span>
|
||||
</ContextMenuItem>
|
||||
)}
|
||||
{canEdit && (
|
||||
<ContextMenuItem
|
||||
onSelect={() => {
|
||||
|
||||
@@ -30,6 +30,7 @@ import { FilePreviewDialog } from '../file-preview-dialog'
|
||||
import { ShareLinkCreatedDialog } from '../share-link-created-dialog'
|
||||
import { FileBrowserContentSkeleton } from '../loading-skeletons'
|
||||
import { FileBrowserContextMenu } from './context-menu'
|
||||
import { getItemInAppUrl } from './copy-options'
|
||||
import { FindSimilarDialog } from '../search/find-similar-dialog'
|
||||
import { useSemanticSearchEnabled } from '../search/use-semantic-search-enabled'
|
||||
|
||||
@@ -1111,6 +1112,9 @@ export function FileBrowser({
|
||||
<FileBrowserContextMenu
|
||||
item={contextMenuItem}
|
||||
selectedIds={selectedIds}
|
||||
openInNewTabHref={
|
||||
contextMenuItem ? getItemInAppUrl(contextMenuItem, '', projectId) : undefined
|
||||
}
|
||||
folders={folders}
|
||||
files={displayedFiles}
|
||||
onRename={handleRename}
|
||||
|
||||
@@ -432,6 +432,7 @@
|
||||
"copy_image": "Image",
|
||||
"copy_name": "Name",
|
||||
"copy_app_link": "Link",
|
||||
"open_in_new_tab": "Open in new tab",
|
||||
"copy_download_link": "Download link",
|
||||
"copy_id": "ID",
|
||||
"copy_markdown_link": "Markdown link",
|
||||
|
||||
@@ -418,6 +418,7 @@
|
||||
"copy_image": "이미지",
|
||||
"copy_name": "이름",
|
||||
"copy_app_link": "링크",
|
||||
"open_in_new_tab": "새 탭에서 열기",
|
||||
"copy_download_link": "다운로드 링크",
|
||||
"copy_id": "ID",
|
||||
"copy_markdown_link": "Markdown 링크",
|
||||
|
||||
@@ -432,6 +432,7 @@
|
||||
"copy_image": "图片",
|
||||
"copy_name": "名称",
|
||||
"copy_app_link": "链接",
|
||||
"open_in_new_tab": "在新标签页中打开",
|
||||
"copy_download_link": "下载链接",
|
||||
"copy_id": "ID",
|
||||
"copy_markdown_link": "Markdown 链接",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { createLazyFileRoute } from '@tanstack/react-router'
|
||||
import { createLazyFileRoute, Link } from '@tanstack/react-router'
|
||||
import type { ProjectInfo } from '@shumai/dtos'
|
||||
import { usePermissions } from '@/ui/hooks/use-permissions'
|
||||
import { client } from '@/ui/api/client'
|
||||
@@ -30,7 +30,6 @@ import { formatDateAgo } from '@/ui/lib/time'
|
||||
import { cn } from '@/ui/lib/utils'
|
||||
import { useUserMetadataStore } from '@/ui/stores/user-metadata'
|
||||
import { keepPreviousData, useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import { useNavigate } from '@tanstack/react-router'
|
||||
import type { InferRequestType, InferResponseType } from 'hono/client'
|
||||
import { MoreHorizontal, PlusIcon } from 'lucide-react'
|
||||
import { useEffect, useState } from 'react'
|
||||
@@ -39,11 +38,9 @@ import { toast } from 'sonner'
|
||||
function TeamPage() {
|
||||
const { teamId } = Route.useParams()
|
||||
const { canEdit, canAdmin } = usePermissions()
|
||||
const navigate = useNavigate()
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
// State for clicked project for animation
|
||||
const [clickedProjectId, setClickedProjectId] = useState<string | null>(null)
|
||||
const [isCreateCardPressed, setIsCreateCardPressed] = useState(false)
|
||||
|
||||
// State for Project Dialog
|
||||
const [isProjectDialogOpen, setIsProjectDialogOpen] = useState(false)
|
||||
@@ -169,9 +166,9 @@ function TeamPage() {
|
||||
}
|
||||
|
||||
const handleCreateCardClick = () => {
|
||||
setClickedProjectId('create')
|
||||
setIsCreateCardPressed(true)
|
||||
setTimeout(() => {
|
||||
setClickedProjectId(null)
|
||||
setIsCreateCardPressed(false)
|
||||
}, 100)
|
||||
|
||||
setTimeout(() => {
|
||||
@@ -202,25 +199,6 @@ function TeamPage() {
|
||||
}
|
||||
}
|
||||
|
||||
const handleCardClick = (projectId: string, e: React.MouseEvent) => {
|
||||
if (e.detail > 1) return
|
||||
|
||||
setClickedProjectId(projectId)
|
||||
|
||||
// Restore scale after 100ms for "shrink and restore" effect
|
||||
setTimeout(() => {
|
||||
setClickedProjectId(null)
|
||||
}, 100)
|
||||
|
||||
// Navigate after 200ms
|
||||
setTimeout(() => {
|
||||
navigate({
|
||||
to: '/projects/$projectId',
|
||||
params: { projectId },
|
||||
})
|
||||
}, 200)
|
||||
}
|
||||
|
||||
const handleInvite = async (role: 'editor' | 'reviewer') => {
|
||||
const res = await inviteMutation.mutateAsync({
|
||||
param: { teamId: teamId },
|
||||
@@ -316,13 +294,14 @@ function TeamPage() {
|
||||
{projects?.data?.map((project: ProjectInfo) => (
|
||||
<div
|
||||
key={project.id}
|
||||
className={cn(
|
||||
'shadow-md relative border rounded-xl overflow-hidden cursor-pointer transition-transform duration-100 ease-in-out',
|
||||
clickedProjectId === project.id ? 'scale-95' : 'scale-100',
|
||||
)}
|
||||
onClick={(e) => handleCardClick(project.id!, e)}
|
||||
className="shadow-md relative border rounded-xl overflow-hidden transition-transform duration-100 ease-in-out has-[a:active]:scale-95"
|
||||
>
|
||||
<div className="flex flex-col">
|
||||
<Link
|
||||
to="/projects/$projectId"
|
||||
params={{ projectId: project.id! }}
|
||||
aria-label={project.name}
|
||||
className="flex flex-col focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-ring"
|
||||
>
|
||||
<div className="relative w-full h-full aspect-square flex items-center justify-center bg-zinc-400/20">
|
||||
{project.coverImage ? (
|
||||
<img
|
||||
@@ -377,53 +356,52 @@ function TeamPage() {
|
||||
<div className="absolute bottom-0 left-0 w-full h-[65%] bg-linear-to-t from-black/35 to-black/0" />
|
||||
<p className="absolute left-1 bottom-2 text-white">{project.name}</p>
|
||||
</div>
|
||||
<div className="px-2 h-10 flex justify-between items-center">
|
||||
<p className="truncate pr-1 text-xs text-muted-foreground">
|
||||
<div className="pl-2 pr-10 h-10 flex items-center">
|
||||
<p className="truncate text-xs text-muted-foreground">
|
||||
{m.updated_ago()} {formatDateAgo((project.updatedAt as string) ?? '')}
|
||||
</p>
|
||||
<div onClick={(e) => e.stopPropagation()}>
|
||||
<DropdownMenu modal={false}>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<button className="hover:bg-muted outline-none flex px-1">
|
||||
<MoreHorizontal className="w-5 h-5 text-muted-foreground" />
|
||||
</button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
{canEdit && (
|
||||
<DropdownMenuItem
|
||||
onClick={(e) => {
|
||||
e.stopPropagation()
|
||||
handleEditProjectClick(project)
|
||||
}}
|
||||
>
|
||||
{m.project_settings()}
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
<DropdownMenuItem
|
||||
className="flex items-center justify-between gap-4 cursor-pointer"
|
||||
onSelect={(e) => {
|
||||
e.preventDefault()
|
||||
toggleProjectNotificationsMutation.mutate(project)
|
||||
}}
|
||||
>
|
||||
<span>{m.notification()}</span>
|
||||
<Switch
|
||||
checked={project.enableNotification ?? true}
|
||||
className="pointer-events-none"
|
||||
/>
|
||||
</DropdownMenuItem>
|
||||
{canAdmin && (
|
||||
<DropdownMenuItem
|
||||
className="text-destructive focus:text-destructive"
|
||||
onClick={() => handleDeleteProjectClick(project)}
|
||||
>
|
||||
{m.delete()}
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
</div>
|
||||
</Link>
|
||||
<div className="absolute right-2 bottom-0 flex h-10 items-center">
|
||||
<DropdownMenu modal={false}>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<button
|
||||
type="button"
|
||||
aria-label={m.more_options()}
|
||||
className="hover:bg-muted flex px-1"
|
||||
>
|
||||
<MoreHorizontal className="w-5 h-5 text-muted-foreground" />
|
||||
</button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
{canEdit && (
|
||||
<DropdownMenuItem onClick={() => handleEditProjectClick(project)}>
|
||||
{m.project_settings()}
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
<DropdownMenuItem
|
||||
className="flex items-center justify-between gap-4 cursor-pointer"
|
||||
onSelect={(e) => {
|
||||
e.preventDefault()
|
||||
toggleProjectNotificationsMutation.mutate(project)
|
||||
}}
|
||||
>
|
||||
<span>{m.notification()}</span>
|
||||
<Switch
|
||||
checked={project.enableNotification ?? true}
|
||||
className="pointer-events-none"
|
||||
/>
|
||||
</DropdownMenuItem>
|
||||
{canAdmin && (
|
||||
<DropdownMenuItem
|
||||
className="text-destructive focus:text-destructive"
|
||||
onClick={() => handleDeleteProjectClick(project)}
|
||||
>
|
||||
{m.delete()}
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
@@ -431,7 +409,7 @@ function TeamPage() {
|
||||
<div
|
||||
className={cn(
|
||||
'shadow-md relative border rounded-xl overflow-hidden cursor-pointer transition-transform duration-100 ease-in-out border-dashed hover:border-orange-600/50 group',
|
||||
clickedProjectId === 'create' ? 'scale-95' : 'scale-100',
|
||||
isCreateCardPressed ? 'scale-95' : 'scale-100',
|
||||
)}
|
||||
onClick={handleCreateCardClick}
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user