mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-01 05:14:25 +00:00
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:
@@ -1,5 +1,14 @@
|
||||
import { type ReactElement, useCallback, useEffect, useRef, useState } from 'react'
|
||||
import ReactDOM from 'react-dom/client'
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
||||
import {
|
||||
RouterProvider,
|
||||
createMemoryHistory,
|
||||
createRootRoute,
|
||||
createRouter,
|
||||
} from '@tanstack/react-router'
|
||||
import type { ShareLinkInfo } from '@shumai/dtos'
|
||||
import { ShareLinkCreatedDialog } from '@/ui/components/share-link-created-dialog'
|
||||
import type { MediaController } from '@/ui/components/viewers/types'
|
||||
import VideoPlayer from '@/ui/components/viewers/video/video-viewer'
|
||||
import ModelViewer from '@/ui/components/viewers/model/model-viewer'
|
||||
@@ -269,6 +278,67 @@ function UploaderHarness(): ReactElement {
|
||||
)
|
||||
}
|
||||
|
||||
function ShareDialogHarness(): ReactElement {
|
||||
const nameParam =
|
||||
typeof window !== 'undefined' ? new URLSearchParams(window.location.search).get('name') : null
|
||||
const shareName =
|
||||
nameParam || 'Client_Delivery_2026_11_24_Final_Master_ProRes422HQ_v04_ColorGraded_Stereo.mov'
|
||||
|
||||
const [queryClient] = useState(
|
||||
() =>
|
||||
new QueryClient({
|
||||
defaultOptions: {
|
||||
queries: { retry: false, enabled: false },
|
||||
},
|
||||
}),
|
||||
)
|
||||
|
||||
const [router] = useState(() => {
|
||||
const rootRoute = createRootRoute({
|
||||
component: () => {
|
||||
const mockShare: ShareLinkInfo = {
|
||||
id: '01K9XYZABCDEFGHJKLMNPQRSTV',
|
||||
name: shareName,
|
||||
isDisabled: false,
|
||||
allowDownload: true,
|
||||
hasPassword: false,
|
||||
password: null,
|
||||
rootFolderId: 'rf-1',
|
||||
projectId: 'proj-1',
|
||||
isExpired: false,
|
||||
watermarkConfigId: null,
|
||||
watermarkStatus: 'disabled',
|
||||
watermarkConfig: null,
|
||||
createdAt: '2026-11-24T00:00:00.000Z',
|
||||
updatedAt: '2026-11-24T00:00:00.000Z',
|
||||
creator: null,
|
||||
}
|
||||
return (
|
||||
<div className="p-6">
|
||||
<Toaster position="top-right" />
|
||||
<ShareLinkCreatedDialog
|
||||
open={true}
|
||||
onOpenChange={() => {}}
|
||||
shareLink={mockShare}
|
||||
projectId="proj-1"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
},
|
||||
})
|
||||
return createRouter({
|
||||
routeTree: rootRoute,
|
||||
history: createMemoryHistory({ initialEntries: ['/'] }),
|
||||
})
|
||||
})
|
||||
|
||||
return (
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<RouterProvider router={router} />
|
||||
</QueryClientProvider>
|
||||
)
|
||||
}
|
||||
|
||||
const rootElement = document.getElementById('root')
|
||||
if (!rootElement) {
|
||||
throw new Error('Harness root element not found')
|
||||
@@ -278,5 +348,11 @@ const currentView =
|
||||
typeof window !== 'undefined' ? new URLSearchParams(window.location.search).get('view') : null
|
||||
|
||||
ReactDOM.createRoot(rootElement).render(
|
||||
currentView === 'uploader' ? <UploaderHarness /> : <Harness />,
|
||||
currentView === 'uploader' ? (
|
||||
<UploaderHarness />
|
||||
) : currentView === 'share-dialog' ? (
|
||||
<ShareDialogHarness />
|
||||
) : (
|
||||
<Harness />
|
||||
),
|
||||
)
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
import { expect, test, type Locator } from '@playwright/test'
|
||||
|
||||
async function assertNoHorizontalOverflow(dialog: Locator, viewportWidth: number) {
|
||||
const metrics = await dialog.evaluate((el) => {
|
||||
const dialogRect = el.getBoundingClientRect()
|
||||
const overflowing: Array<{ tag: string; text: string; right: number; dialogRight: number }> = []
|
||||
for (const child of el.querySelectorAll('*')) {
|
||||
const rect = child.getBoundingClientRect()
|
||||
if (rect.width === 0 || rect.height === 0) continue
|
||||
if (rect.right > dialogRect.right + 1 || rect.left < dialogRect.left - 1) {
|
||||
overflowing.push({
|
||||
tag: child.tagName.toLowerCase(),
|
||||
text: (child.textContent || '').trim().slice(0, 60),
|
||||
right: Math.round(rect.right),
|
||||
dialogRight: Math.round(dialogRect.right),
|
||||
})
|
||||
}
|
||||
}
|
||||
return {
|
||||
clientWidth: el.clientWidth,
|
||||
scrollWidth: el.scrollWidth,
|
||||
dialogWidth: Math.round(dialogRect.width),
|
||||
overflowing,
|
||||
}
|
||||
})
|
||||
|
||||
expect(metrics.dialogWidth).toBeLessThanOrEqual(viewportWidth)
|
||||
expect(metrics.scrollWidth, JSON.stringify(metrics)).toBeLessThanOrEqual(metrics.clientWidth)
|
||||
expect(metrics.overflowing, JSON.stringify(metrics)).toEqual([])
|
||||
}
|
||||
|
||||
test.describe('ShareLinkCreatedDialog layout', () => {
|
||||
for (const viewport of [
|
||||
{ name: 'desktop', width: 1280, height: 800 },
|
||||
{ name: 'mobile', width: 375, height: 812 },
|
||||
]) {
|
||||
test(`does not overflow horizontally on ${viewport.name} across default, edit, and expanded security states`, async ({
|
||||
page,
|
||||
}) => {
|
||||
await page.setViewportSize({ width: viewport.width, height: viewport.height })
|
||||
await page.goto('/?view=share-dialog')
|
||||
|
||||
const dialog = page.getByRole('dialog')
|
||||
await expect(dialog).toBeVisible()
|
||||
|
||||
// Default state with a very long unbroken share name
|
||||
await assertNoHorizontalOverflow(dialog, viewport.width)
|
||||
|
||||
// Inline edit mode
|
||||
await dialog.getByRole('button', { name: 'Rename Share Link' }).click()
|
||||
await expect(dialog.getByRole('textbox', { name: 'Rename Share Link' })).toBeVisible()
|
||||
await assertNoHorizontalOverflow(dialog, viewport.width)
|
||||
await dialog.getByRole('textbox', { name: 'Rename Share Link' }).press('Escape')
|
||||
|
||||
// Expanded Password and Expiration Date controls
|
||||
const switches = dialog.getByRole('switch')
|
||||
await switches.nth(0).click()
|
||||
await switches.nth(1).click()
|
||||
await expect(dialog.getByPlaceholder('Enter password')).toBeVisible()
|
||||
await assertNoHorizontalOverflow(dialog, viewport.width)
|
||||
})
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user