diff --git a/apps/web/e2e/README.md b/apps/web/e2e/README.md index d257baa5..e9bb5042 100644 --- a/apps/web/e2e/README.md +++ b/apps/web/e2e/README.md @@ -80,6 +80,10 @@ apps/web/e2e/ | Owner drags a file into a folder and a folder into another folder | `tests/project/move-folder-file.spec.ts` | | Owner drags a file onto a file to create a version stack | `tests/project/version-stack-create.spec.ts` | | Owner drags a file onto a version stack to add a new version | `tests/project/version-stack-add-version.spec.ts` | +| Owner manages version stack: removes version from 3-version stack | `tests/project/version-stack-manage.spec.ts` | +| Owner removes version from 2-version stack which dissolves into standalone files | `tests/project/version-stack-manage.spec.ts` | +| Dissolving a shared version stack renders the remaining standalone file name on the share page | `tests/project/version-stack-manage.spec.ts` | +| Moving a shared file into a shared version stack leaves only 1 stack card on the share page | `tests/project/version-stack-manage.spec.ts` | | Owner searches the file list by an English name keyword | `tests/project/search-file-list.spec.ts` | | Owner searches the file list by Chinese, Japanese, and Korean name keywords | `tests/project/search-file-list.spec.ts` | | Owner searches the file list with a keyword and a filter condition | `tests/project/search-file-list.spec.ts` | diff --git a/apps/web/e2e/tests/project/version-stack-manage.spec.ts b/apps/web/e2e/tests/project/version-stack-manage.spec.ts new file mode 100644 index 00000000..8221a39b --- /dev/null +++ b/apps/web/e2e/tests/project/version-stack-manage.spec.ts @@ -0,0 +1,233 @@ +import { expect, test } from '../../fixtures' +import { seedFile } from '../../helpers/assets' +import { dragCard } from '../../helpers/dnd' +import { apiAddAssetsToShare, apiCreateShare, fileCard } from '../../helpers/files' + +test('owner manages versions: removes a version from a 3-version stack', async ({ + project, + prisma, +}) => { + const { page, projectId, rootFolderId } = project + + const fileA = await seedFile(prisma, projectId, rootFolderId, `e2e-mng-a-${Date.now()}`) + const fileB = await seedFile(prisma, projectId, rootFolderId, `e2e-mng-b-${Date.now()}`) + const fileC = await seedFile(prisma, projectId, rootFolderId, `e2e-mng-c-${Date.now()}`) + + await page.goto(`/projects/${projectId}`) + await expect(fileCard(page, fileA.name)).toBeVisible() + await expect(fileCard(page, fileB.name)).toBeVisible() + await expect(fileCard(page, fileC.name)).toBeVisible() + + // 1. Create a 3-version stack: B on A -> stack (v2), then C on stack -> stack (v3) + await dragCard(page, fileCard(page, fileB.name), fileCard(page, fileA.name)) + await expect(page.getByText('v2', { exact: true })).toBeVisible() + + await dragCard(page, fileCard(page, fileC.name), fileCard(page, fileB.name)) + await expect(page.getByText('v3', { exact: true })).toBeVisible() + + const stack = await prisma.asset.findFirstOrThrow({ + where: { projectId, parentId: rootFolderId, type: 'version_stack' }, + }) + expect(stack.fileCount).toBe(3) + + // 2. Navigate to file viewer for the stack + await page.goto(`/projects/${projectId}/files/${stack.id}`) + + // 3. Open breadcrumb menu and click "Manage versions..." + // Click on the asset name / badge dropdown trigger + await page.getByRole('button', { name: new RegExp(fileC.name) }).click() + // Hover or click on Versions sub-menu trigger + await page.getByRole('menuitem', { name: 'Versions', exact: true }).hover() + // Click "Manage versions..." + await page.getByRole('button', { name: /manage versions$/i }).click() + + // 4. Verify Manage versions dialog is visible with all 3 versions + const dialog = page.getByRole('dialog') + await expect(dialog).toBeVisible() + await expect(dialog.getByText('Manage versions')).toBeVisible() + await expect(dialog.getByText(fileA.name)).toBeVisible() + await expect(dialog.getByText(fileB.name)).toBeVisible() + await expect(dialog.getByText(fileC.name)).toBeVisible() + + // 5. Remove fileB from stack: hover its row and click Remove from stack + const rowB = dialog.locator('div.group', { hasText: fileB.name }) + await rowB.hover() + const moreButton = rowB.getByRole('button', { name: 'More options' }) + await moreButton.click() + await page.getByRole('menuitem', { name: /remove from stack/i }).click() + + // 6. Verify toast and that fileB is removed from dialog + await expect(page.getByText(/version removed from stack/i)).toBeVisible() + await expect(dialog.getByText(fileB.name)).not.toBeVisible() + await expect(dialog.getByText(fileA.name)).toBeVisible() + await expect(dialog.getByText(fileC.name)).toBeVisible() + + // DB: stack now has 2 versions (fileA and fileC), and fileB is standalone in root folder + await expect + .poll(async () => { + const s = await prisma.asset.findUnique({ where: { id: stack.id } }) + return s?.fileCount + }) + .toBe(2) + + const updatedFileB = await prisma.asset.findUnique({ where: { id: fileB.id } }) + expect(updatedFileB?.parentId).toBe(rootFolderId) +}) + +test('owner removes version from 2-version stack dissolving the stack into standalone files', async ({ + project, + prisma, +}) => { + const { page, projectId, rootFolderId } = project + + const fileA = await seedFile(prisma, projectId, rootFolderId, `e2e-dis-a-${Date.now()}`) + const fileB = await seedFile(prisma, projectId, rootFolderId, `e2e-dis-b-${Date.now()}`) + + await page.goto(`/projects/${projectId}`) + await dragCard(page, fileCard(page, fileB.name), fileCard(page, fileA.name)) + await expect(page.getByText('v2', { exact: true })).toBeVisible() + + const stack = await prisma.asset.findFirstOrThrow({ + where: { projectId, parentId: rootFolderId, type: 'version_stack' }, + }) + + // Open file view + await page.goto(`/projects/${projectId}/files/${stack.id}`) + + // Open breadcrumb menu and click "Manage versions..." + await page.getByRole('button', { name: new RegExp(fileB.name) }).click() + await page.getByRole('menuitem', { name: 'Versions', exact: true }).hover() + await page.getByRole('button', { name: /manage versions$/i }).click() + + const dialog = page.getByRole('dialog') + await expect(dialog).toBeVisible() + + // Remove fileB -> stack dissolves -> only fileA remains + const rowB = dialog.locator('div.group', { hasText: fileB.name }) + await rowB.hover() + const moreButton = rowB.getByRole('button', { name: 'More options' }) + await moreButton.click() + await page.getByRole('menuitem', { name: /remove from stack/i }).click() + + // Dialog should close automatically when stack dissolves + await expect(dialog).not.toBeVisible() + + // DB: stack asset is deleted + await expect + .poll(async () => { + const s = await prisma.asset.findUnique({ where: { id: stack.id } }) + return s === null + }) + .toBe(true) + + // Both fileA and fileB are now standalone files in rootFolder + const updatedFileA = await prisma.asset.findUnique({ where: { id: fileA.id } }) + const updatedFileB = await prisma.asset.findUnique({ where: { id: fileB.id } }) + expect(updatedFileA?.parentId).toBe(rootFolderId) + expect(updatedFileB?.parentId).toBe(rootFolderId) +}) + +test('dissolving a shared version stack renders the remaining standalone file name on the share page', async ({ + project, + prisma, +}) => { + const { page, projectId, rootFolderId } = project + + const fileA = await seedFile(prisma, projectId, rootFolderId, `e2e-shd-a-${Date.now()}`) + const fileB = await seedFile(prisma, projectId, rootFolderId, `e2e-shd-b-${Date.now()}`) + + await page.goto(`/projects/${projectId}`) + await dragCard(page, fileCard(page, fileB.name), fileCard(page, fileA.name)) + await expect(page.getByText('v2', { exact: true })).toBeVisible() + + const stack = await prisma.asset.findFirstOrThrow({ + where: { projectId, parentId: rootFolderId, type: 'version_stack' }, + }) + + // Share the version stack + await fileCard(page, fileB.name).click({ button: 'right' }) + await page.getByRole('menuitem', { name: 'Create Share Link' }).click() + const toast = page.locator('[data-sonner-toast]').filter({ hasText: 'Share link created' }) + await expect(toast).toBeVisible() + + const share = await prisma.shareLink.findFirstOrThrow({ + where: { projectId }, + orderBy: { createdAt: 'desc' }, + }) + + // Open file viewer for the stack + await page.goto(`/projects/${projectId}/files/${stack.id}`) + + // Open breadcrumb menu and click "Manage versions" + await page.getByRole('button', { name: new RegExp(fileB.name) }).click() + await page.getByRole('menuitem', { name: 'Versions', exact: true }).hover() + await page.getByRole('button', { name: /manage versions$/i }).click() + + const dialog = page.getByRole('dialog') + await expect(dialog).toBeVisible() + + // Remove fileB -> stack dissolves -> only fileA remains + const rowB = dialog.locator('div.group', { hasText: fileB.name }) + await rowB.hover() + const moreButton = rowB.getByRole('button', { name: 'More options' }) + await moreButton.click() + await page.getByRole('menuitem', { name: /remove from stack/i }).click() + + await expect(dialog).not.toBeVisible() + + // Navigate to public share page: verify fileA is displayed with its non-empty name + await page.goto(`/share/${share.id}`) + await expect(fileCard(page, fileA.name)).toBeVisible() + await expect(fileCard(page, fileB.name)).not.toBeVisible() +}) + +test('moving a shared file into a shared version stack leaves only 1 stack card on the share page', async ({ + project, + prisma, +}) => { + const { page, projectId, rootFolderId } = project + + const fileA = await seedFile(prisma, projectId, rootFolderId, `e2e-mvsh-a-${Date.now()}`) + const fileB = await seedFile(prisma, projectId, rootFolderId, `e2e-mvsh-b-${Date.now()}`) + const fileC = await seedFile(prisma, projectId, rootFolderId, `e2e-mvsh-c-${Date.now()}`) + + await page.goto(`/projects/${projectId}`) + + // 1. Create a version stack from file B and file A (stack has v2, displays file B) + await dragCard(page, fileCard(page, fileB.name), fileCard(page, fileA.name)) + await expect(page.getByText('v2', { exact: true })).toBeVisible() + + const stack = await prisma.asset.findFirstOrThrow({ + where: { projectId, parentId: rootFolderId, type: 'version_stack' }, + }) + + // 2. Create a share link and add both stack AB and file C to it + const share = await apiCreateShare(project.context.request, projectId, `Test Share ${Date.now()}`) + await apiAddAssetsToShare(project.context.request, share.id, [stack.id, fileC.id]) + + // Verify initial share page has both stack and file C + await page.goto(`/share/${share.id}`) + await expect(fileCard(page, fileB.name)).toBeVisible() + await expect(fileCard(page, fileC.name)).toBeVisible() + + // 3. In project page, drop file C onto stack card (displays file B) + await page.goto(`/projects/${projectId}`) + await dragCard(page, fileCard(page, fileC.name), fileCard(page, fileB.name)) + await expect(page.getByText('v3', { exact: true })).toBeVisible() + + // 4. Return to public share page: now only 1 card exists (the stack showing file C with v3) + await page.goto(`/share/${share.id}`) + await expect(page.getByText('v3', { exact: true })).toBeVisible() + await expect(fileCard(page, fileC.name)).toBeVisible() + await expect(fileCard(page, fileB.name)).not.toBeVisible() + + // DB: share rootFolder fileCount is 1 and exactly 1 symlink exists + const symlinks = await prisma.asset.findMany({ + where: { parentId: share.rootFolderId, type: 'symlink' }, + }) + expect(symlinks).toHaveLength(1) + expect(symlinks[0].targetId).toBe(stack.id) + + const updatedShareRoot = await prisma.asset.findUnique({ where: { id: share.rootFolderId } }) + expect(updatedShareRoot?.fileCount).toBe(1) +}) diff --git a/packages/api/src/versionStack.test.ts b/packages/api/src/versionStack.test.ts index 39ffed2f..7a95fa18 100644 --- a/packages/api/src/versionStack.test.ts +++ b/packages/api/src/versionStack.test.ts @@ -32,12 +32,14 @@ vi.mock('./middleware/auth', () => ({ describe('versionStack api', () => { let mockCreateVersionStack: any // eslint-disable-line @typescript-eslint/no-explicit-any let mockChangeStackFileVersion: any // eslint-disable-line @typescript-eslint/no-explicit-any + let mockRemoveVersionFromStack: any // eslint-disable-line @typescript-eslint/no-explicit-any let mockGetAsset: any // eslint-disable-line @typescript-eslint/no-explicit-any let mockGetStackVersions: any // eslint-disable-line @typescript-eslint/no-explicit-any beforeEach(() => { mockCreateVersionStack = vi.spyOn(versionStackService, 'createVersionStack') mockChangeStackFileVersion = vi.spyOn(versionStackService, 'changeStackFileVersion') + mockRemoveVersionFromStack = vi.spyOn(versionStackService, 'removeVersionFromStack') mockGetAsset = vi.spyOn(assetService, 'getAsset') mockGetStackVersions = vi.spyOn(assetService, 'getStackVersions') vi.mocked(authzService.hasPermission).mockResolvedValue(undefined) @@ -146,4 +148,30 @@ describe('versionStack api', () => { expect(mockGetStackVersions).toHaveBeenCalledWith('stack1') }) }) + + describe('DELETE /version_stacks/:stackId/versions/:versionId', () => { + it('should remove version from stack and return 200', async () => { + mockRemoveVersionFromStack.mockResolvedValue() + + const app = new Hono().use('*', authMiddleware).route('/', versionStackRoute) + + const res = await app.request('/version_stacks/stack1/versions/v1', { + method: 'DELETE', + }) + + expect(res.status).toBe(200) + + expect(authzService.hasPermission).toHaveBeenCalledWith( + expect.objectContaining({ + type: ResourceType.Asset, + id: 'stack1', + permission: Permission.Edit, + }), + ) + expect(mockRemoveVersionFromStack).toHaveBeenCalledWith({ + stackId: 'stack1', + fileId: 'v1', + }) + }) + }) }) diff --git a/packages/api/src/versionStack.ts b/packages/api/src/versionStack.ts index 4ff0b3b4..f433945a 100644 --- a/packages/api/src/versionStack.ts +++ b/packages/api/src/versionStack.ts @@ -75,5 +75,24 @@ const route = app const versions = await assetService.getStackVersions(stackId) return c.json(versions) }) + .delete('/version_stacks/:stackId/versions/:versionId', async (c) => { + const stackId = c.req.param('stackId') + const versionId = c.req.param('versionId') + const user = c.get('user') + + await authzService.hasPermission({ + user, + permission: Permission.Edit, + type: ResourceType.Asset, + id: stackId, + }) + + await versionStackService.removeVersionFromStack({ + stackId, + fileId: versionId, + }) + + return new Response(null, { status: 200 }) + }) export default route diff --git a/packages/core/src/asset/asset.test.ts b/packages/core/src/asset/asset.test.ts index d2d38688..702d291e 100644 --- a/packages/core/src/asset/asset.test.ts +++ b/packages/core/src/asset/asset.test.ts @@ -3030,4 +3030,218 @@ describe('AssetService — natural sort by name', () => { ) }) }) + + describe('reparentAssets into version_stack with sharelink symlinks', () => { + it('deduplicates symlinks when both Stack A and File B are in the sharelink and File B is moved into Stack A', async () => { + const team = await prisma.team.create({ data: { name: 'Test Team ' + Date.now() } }) + const project = await prisma.project.create({ + data: { name: 'Test Project', teamId: team.id }, + }) + const user = await prisma.user.create({ + data: { name: 'Test User', email: `test-${Date.now()}@example.com` }, + }) + const rootFolder = await prisma.asset.create({ + data: { + name: 'Root', + type: AssetType.folder, + projectId: project.id, + status: AssetStatus.uploaded, + }, + }) + const shareRoot = await prisma.asset.create({ + data: { + name: 'ShareRoot', + type: AssetType.share_root, + projectId: project.id, + status: AssetStatus.uploaded, + fileCount: 2, + }, + }) + + const fileA1 = await prisma.asset.create({ + data: { + name: 'fileA1.txt', + type: AssetType.file, + parentId: rootFolder.id, + projectId: project.id, + status: AssetStatus.uploaded, + sizeByte: 100, + sortIndex: 'a0', + }, + }) + const fileA2 = await prisma.asset.create({ + data: { + name: 'fileA2.txt', + type: AssetType.file, + parentId: rootFolder.id, + projectId: project.id, + status: AssetStatus.uploaded, + sizeByte: 100, + sortIndex: 'a1', + }, + }) + const fileB = await prisma.asset.create({ + data: { + name: 'fileB.txt', + type: AssetType.file, + parentId: rootFolder.id, + projectId: project.id, + status: AssetStatus.uploaded, + sizeByte: 200, + sortIndex: 'a2', + }, + }) + + // Create Stack A from fileA1 and fileA2 + const stackA = await prisma.asset.create({ + data: { + name: '', + type: AssetType.version_stack, + parentId: rootFolder.id, + projectId: project.id, + status: AssetStatus.uploaded, + fileCount: 2, + sizeByte: 200, + }, + }) + await prisma.asset.update({ where: { id: fileA1.id }, data: { parentId: stackA.id } }) + await prisma.asset.update({ where: { id: fileA2.id }, data: { parentId: stackA.id } }) + + // Create symlinks in shareRoot for both Stack A and File B + const symlinkStackA = await prisma.asset.create({ + data: { + name: '', + type: AssetType.symlink, + parentId: shareRoot.id, + targetId: stackA.id, + projectId: project.id, + status: AssetStatus.uploaded, + }, + }) + const symlinkFileB = await prisma.asset.create({ + data: { + name: fileB.name, + type: AssetType.symlink, + parentId: shareRoot.id, + targetId: fileB.id, + projectId: project.id, + status: AssetStatus.uploaded, + }, + }) + + // Move File B into Stack A + await assetService.reparentAssets({ + newParentId: stackA.id, + assetIds: [fileB.id], + creatorId: user.id, + }) + + // Verify: File B's symlink was deleted, only Stack A's symlink remains + expect(await prisma.asset.findUnique({ where: { id: symlinkFileB.id } })).toBeNull() + const remainingSymlinks = await prisma.asset.findMany({ + where: { parentId: shareRoot.id, type: AssetType.symlink }, + }) + expect(remainingSymlinks).toHaveLength(1) + expect(remainingSymlinks[0].id).toBe(symlinkStackA.id) + expect(remainingSymlinks[0].targetId).toBe(stackA.id) + + // ShareRoot fileCount was decremented from 2 to 1 + const updatedShareRoot = await prisma.asset.findUnique({ where: { id: shareRoot.id } }) + expect(updatedShareRoot?.fileCount).toBe(1) + }) + + it('repoints symlink to Stack A when only File B is in sharelink and File B is moved into Stack A', async () => { + const team = await prisma.team.create({ data: { name: 'Test Team ' + Date.now() } }) + const project = await prisma.project.create({ + data: { name: 'Test Project', teamId: team.id }, + }) + const user = await prisma.user.create({ + data: { name: 'Test User', email: `test-${Date.now()}@example.com` }, + }) + const rootFolder = await prisma.asset.create({ + data: { + name: 'Root', + type: AssetType.folder, + projectId: project.id, + status: AssetStatus.uploaded, + }, + }) + const shareRoot = await prisma.asset.create({ + data: { + name: 'ShareRoot', + type: AssetType.share_root, + projectId: project.id, + status: AssetStatus.uploaded, + fileCount: 1, + }, + }) + + const fileA1 = await prisma.asset.create({ + data: { + name: 'fileA1.txt', + type: AssetType.file, + parentId: rootFolder.id, + projectId: project.id, + status: AssetStatus.uploaded, + sizeByte: 100, + sortIndex: 'a0', + }, + }) + const stackA = await prisma.asset.create({ + data: { + name: '', + type: AssetType.version_stack, + parentId: rootFolder.id, + projectId: project.id, + status: AssetStatus.uploaded, + fileCount: 1, + sizeByte: 100, + }, + }) + await prisma.asset.update({ where: { id: fileA1.id }, data: { parentId: stackA.id } }) + + const fileB = await prisma.asset.create({ + data: { + name: 'fileB.txt', + type: AssetType.file, + parentId: rootFolder.id, + projectId: project.id, + status: AssetStatus.uploaded, + sizeByte: 200, + sortIndex: 'a1', + }, + }) + + // Create symlink for File B only + const symlinkFileB = await prisma.asset.create({ + data: { + name: fileB.name, + type: AssetType.symlink, + parentId: shareRoot.id, + targetId: fileB.id, + projectId: project.id, + status: AssetStatus.uploaded, + }, + }) + + // Move File B into Stack A + await assetService.reparentAssets({ + newParentId: stackA.id, + assetIds: [fileB.id], + creatorId: user.id, + }) + + // Verify: symlinkFileB now points to stackA.id + const updatedSymlink = await prisma.asset.findUnique({ where: { id: symlinkFileB.id } }) + expect(updatedSymlink?.targetId).toBe(stackA.id) + + // Listing assets for shareRoot returns Stack A with latest version name + const result = await assetService.listChildren({ + assetId: shareRoot.id, + assetType: AssetType.file, + }) + expect(result.data).toHaveLength(1) + expect(result.data[0].name).toBe(fileB.name) // fileB is the latest version + }) + }) }) diff --git a/packages/core/src/asset/asset.ts b/packages/core/src/asset/asset.ts index 41842549..9f81bb15 100644 --- a/packages/core/src/asset/asset.ts +++ b/packages/core/src/asset/asset.ts @@ -22,6 +22,7 @@ import { HTTPException } from 'hono/http-exception' import { logger } from '@shumai/core/src/logger' import { PaginatedData, paginateQuery, PaginationParams } from '@shumai/core/src/pagination' import { s3Service } from '@shumai/core/src/s3/s3' +import { dedupeSymlinksToTarget } from './symlink' import { watermarkService } from '@shumai/core/src/watermark/watermark' import { generateKeyBetween } from 'jittered-fractional-indexing' import { getAvatarUrl } from '@shumai/core/src/user/avatar' @@ -160,6 +161,9 @@ export class AssetService { const count = await tx.asset.count({ where: { parentId: stack.id } }) if (count === 0) { + await tx.asset.deleteMany({ + where: { targetId: stack.id, type: AssetType.symlink }, + }) if (stack.parentId) { await tx.asset.update({ where: { id: stack.parentId }, @@ -174,9 +178,14 @@ export class AssetService { if (!lastChild) return if (!stack.parentId) throw new Error('Stack has no parent') + await tx.asset.updateMany({ + where: { targetId: stack.id, type: AssetType.symlink }, + data: { targetId: lastChild.id, name: lastChild.name }, + }) + await tx.asset.update({ where: { id: lastChild.id }, - data: { parentId: stack.parentId, sortIndex: null }, + data: { parentId: stack.parentId, sortIndex: stack.sortIndex }, }) await tx.asset.delete({ where: { id: stack.id } }) } @@ -273,6 +282,14 @@ export class AssetService { firstSortIndex = newSortIndex } + if (newParent.type === AssetType.version_stack) { + await dedupeSymlinksToTarget(tx, { + targetIds: req.assetIds, + newTargetId: newParent.id, + name: '', + }) + } + const oldParent = await tx.asset.findUnique({ where: { id: oldParentId }, }) @@ -579,6 +596,12 @@ export class AssetService { }, }) + // Update existing symlinks pointing to destFile or sourceAsset + await dedupeSymlinksToTarget(tx, { + targetIds: [destFile.id, sourceAsset.id], + newTargetId: stack.id, + }) + const oldParent = await tx.asset.findUnique({ where: { id: oldParentId } }) if (oldParent) { await this.dissolveStackIfEmpty(tx, oldParent) @@ -1629,6 +1652,7 @@ export class AssetService { id: v.id, name: v.name, previewUrl: preview?.thumbnailUrl || null, + createdAt: v.createdAt.toISOString(), creator: v.creator ? { id: v.creator.id, @@ -1744,9 +1768,12 @@ export class AssetService { result.push({ id: a.id, name: - a.type === AssetType.version_stack && (a.name === '' || !a.name) + a.type === AssetType.version_stack || + (a.type === AssetType.symlink && a.target?.type === AssetType.version_stack) ? latestVersion.name - : a.name, + : a.type === AssetType.symlink + ? a.name || latestVersion.name || a.target?.name || '' + : a.name, sizeByte: Number(latestVersion.sizeByte), fileCount: latestVersion.fileCount, type: a.type, @@ -1776,7 +1803,8 @@ export class AssetService { version: number name: string previewUrl: string | null - creator: { id: string; name: string | null } | null + createdAt: string + creator: { id: string; name: string | null; image?: string | null } | null }> > { const versions = await this.prismaClient.asset.findMany({ @@ -1797,6 +1825,7 @@ export class AssetService { version: versions.length - i, name: v.name, previewUrl: preview?.thumbnailUrl || null, + createdAt: v.createdAt.toISOString(), creator: v.creator ? { id: v.creator.id, diff --git a/packages/core/src/asset/symlink.test.ts b/packages/core/src/asset/symlink.test.ts new file mode 100644 index 00000000..22f4c766 --- /dev/null +++ b/packages/core/src/asset/symlink.test.ts @@ -0,0 +1,249 @@ +import { describe, it, expect } from 'vitest' +import { prisma } from '@shumai/db' +import { setupTestDbHooks } from '@shumai/db/test' +import { AssetType } from '@shumai/db' +import { dedupeSymlinksToTarget } from './symlink' + +async function setupShareFolder(projectId: string, fileCount: number) { + const shareRoot = await prisma.asset.create({ + data: { + name: 'share-root', + type: AssetType.share_root, + projectId, + status: 'uploaded', + fileCount, + }, + }) + return shareRoot +} + +describe('dedupeSymlinksToTarget', () => { + setupTestDbHooks() + + async function setupProject() { + const team = await prisma.team.create({ data: { name: 'Team ' + Date.now() } }) + const project = await prisma.project.create({ + data: { name: 'Project ' + Date.now(), teamId: team.id }, + }) + const root = await prisma.asset.create({ + data: { + name: 'root', + type: AssetType.folder, + projectId: project.id, + status: 'uploaded', + }, + }) + const fileA = await prisma.asset.create({ + data: { + name: 'a.txt', + type: AssetType.file, + parentId: root.id, + projectId: project.id, + status: 'uploaded', + sizeByte: 10, + }, + }) + const fileB = await prisma.asset.create({ + data: { + name: 'b.txt', + type: AssetType.file, + parentId: root.id, + projectId: project.id, + status: 'uploaded', + sizeByte: 20, + }, + }) + return { project, root, fileA, fileB } + } + + it('repoints one symlink per parent and deletes duplicates, decrementing fileCount once', async () => { + const { project, root, fileA, fileB } = await setupProject() + const shareRoot = await setupShareFolder(project.id, 2) + + const symA = await prisma.asset.create({ + data: { + name: fileA.name, + type: AssetType.symlink, + parentId: shareRoot.id, + targetId: fileA.id, + projectId: project.id, + status: 'uploaded', + }, + }) + const symB = await prisma.asset.create({ + data: { + name: fileB.name, + type: AssetType.symlink, + parentId: shareRoot.id, + targetId: fileB.id, + projectId: project.id, + status: 'uploaded', + }, + }) + + const stack = await prisma.asset.create({ + data: { + name: '', + type: AssetType.version_stack, + parentId: root.id, + projectId: project.id, + status: 'uploaded', + fileCount: 2, + sizeByte: 30, + }, + }) + + await prisma.$transaction((tx) => + dedupeSymlinksToTarget(tx, { targetIds: [fileA.id, fileB.id], newTargetId: stack.id }), + ) + + // First symlink repointed to the stack, second deleted + const repointed = await prisma.asset.findUnique({ where: { id: symA.id } }) + expect(repointed?.targetId).toBe(stack.id) + expect(await prisma.asset.findUnique({ where: { id: symB.id } })).toBeNull() + + // fileCount decremented exactly once (2 -> 1) + const updatedShareRoot = await prisma.asset.findUnique({ where: { id: shareRoot.id } }) + expect(updatedShareRoot?.fileCount).toBe(1) + }) + + it('deletes a file symlink when the parent already shows the stack', async () => { + const { project, root, fileA } = await setupProject() + const shareRoot = await setupShareFolder(project.id, 2) + + const stack = await prisma.asset.create({ + data: { + name: '', + type: AssetType.version_stack, + parentId: root.id, + projectId: project.id, + status: 'uploaded', + fileCount: 1, + sizeByte: 10, + }, + }) + // Share already contains a symlink to the stack + const stackSymlink = await prisma.asset.create({ + data: { + name: '', + type: AssetType.symlink, + parentId: shareRoot.id, + targetId: stack.id, + projectId: project.id, + status: 'uploaded', + }, + }) + // And a symlink to the file being moved into the stack + const fileSymlink = await prisma.asset.create({ + data: { + name: fileA.name, + type: AssetType.symlink, + parentId: shareRoot.id, + targetId: fileA.id, + projectId: project.id, + status: 'uploaded', + }, + }) + + await prisma.$transaction((tx) => + dedupeSymlinksToTarget(tx, { targetIds: [fileA.id], newTargetId: stack.id }), + ) + + // File symlink deleted, stack symlink untouched + expect(await prisma.asset.findUnique({ where: { id: fileSymlink.id } })).toBeNull() + const updatedStackSymlink = await prisma.asset.findUnique({ where: { id: stackSymlink.id } }) + expect(updatedStackSymlink?.targetId).toBe(stack.id) + + // fileCount decremented once (2 -> 1) + const updatedShareRoot = await prisma.asset.findUnique({ where: { id: shareRoot.id } }) + expect(updatedShareRoot?.fileCount).toBe(1) + }) + + it('repoints symlinks in different share folders without changing fileCounts', async () => { + const { project, root, fileA, fileB } = await setupProject() + const share1 = await setupShareFolder(project.id, 1) + const share2 = await setupShareFolder(project.id, 1) + + const sym1 = await prisma.asset.create({ + data: { + name: fileA.name, + type: AssetType.symlink, + parentId: share1.id, + targetId: fileA.id, + projectId: project.id, + status: 'uploaded', + }, + }) + const sym2 = await prisma.asset.create({ + data: { + name: fileB.name, + type: AssetType.symlink, + parentId: share2.id, + targetId: fileB.id, + projectId: project.id, + status: 'uploaded', + }, + }) + + const stack = await prisma.asset.create({ + data: { + name: '', + type: AssetType.version_stack, + parentId: root.id, + projectId: project.id, + status: 'uploaded', + fileCount: 2, + sizeByte: 30, + }, + }) + + await prisma.$transaction((tx) => + dedupeSymlinksToTarget(tx, { targetIds: [fileA.id, fileB.id], newTargetId: stack.id }), + ) + + expect((await prisma.asset.findUnique({ where: { id: sym1.id } }))?.targetId).toBe(stack.id) + expect((await prisma.asset.findUnique({ where: { id: sym2.id } }))?.targetId).toBe(stack.id) + expect((await prisma.asset.findUnique({ where: { id: share1.id } }))?.fileCount).toBe(1) + expect((await prisma.asset.findUnique({ where: { id: share2.id } }))?.fileCount).toBe(1) + }) + + it('sets the provided name on repointed symlinks', async () => { + const { project, root, fileA } = await setupProject() + const shareRoot = await setupShareFolder(project.id, 1) + + const sym = await prisma.asset.create({ + data: { + name: fileA.name, + type: AssetType.symlink, + parentId: shareRoot.id, + targetId: fileA.id, + projectId: project.id, + status: 'uploaded', + }, + }) + + const stack = await prisma.asset.create({ + data: { + name: '', + type: AssetType.version_stack, + parentId: root.id, + projectId: project.id, + status: 'uploaded', + fileCount: 1, + sizeByte: 10, + }, + }) + + await prisma.$transaction((tx) => + dedupeSymlinksToTarget(tx, { + targetIds: [fileA.id], + newTargetId: stack.id, + name: '', + }), + ) + + const updatedSym = await prisma.asset.findUnique({ where: { id: sym.id } }) + expect(updatedSym?.targetId).toBe(stack.id) + expect(updatedSym?.name).toBe('') + }) +}) diff --git a/packages/core/src/asset/symlink.ts b/packages/core/src/asset/symlink.ts new file mode 100644 index 00000000..cda0120b --- /dev/null +++ b/packages/core/src/asset/symlink.ts @@ -0,0 +1,58 @@ +import { Prisma } from '@shumai/db' +import { AssetType } from '@shumai/db' + +interface DedupeSymlinksParams { + /** Files being merged into a version stack — symlinks pointing at them are the candidates. */ + targetIds: string[] + /** The version stack the files are moving into. */ + newTargetId: string + /** Optional name to set on repointed symlinks ('' for stacks — display name comes from the latest version). */ + name?: string +} + +/** + * When files are merged into a version stack, symlinks in share folders that + * pointed at those files must either be repointed to the stack (one per parent) + * or deleted as duplicates. Per parent folder: if the parent already shows the + * stack (either before this call or after the first repoint), delete the + * incoming symlink and decrement the parent's fileCount; otherwise repoint the + * first symlink to the stack. + */ +export async function dedupeSymlinksToTarget( + tx: Prisma.TransactionClient, + { targetIds, newTargetId, name }: DedupeSymlinksParams, +): Promise { + const existingSymlinks = await tx.asset.findMany({ + where: { targetId: { in: targetIds }, type: AssetType.symlink }, + }) + if (existingSymlinks.length === 0) return + + // Parents that already display the stack (or will after the first repoint). + const stackSymlinkParents = new Set( + ( + await tx.asset.findMany({ + where: { targetId: newTargetId, type: AssetType.symlink }, + select: { parentId: true }, + }) + ) + .map((s) => s.parentId) + .filter((id): id is string => !!id), + ) + + for (const symlink of existingSymlinks) { + if (!symlink.parentId) continue + if (stackSymlinkParents.has(symlink.parentId)) { + await tx.asset.delete({ where: { id: symlink.id } }) + await tx.asset.update({ + where: { id: symlink.parentId }, + data: { fileCount: { decrement: 1 } }, + }) + } else { + stackSymlinkParents.add(symlink.parentId) + await tx.asset.update({ + where: { id: symlink.id }, + data: { targetId: newTargetId, ...(name !== undefined ? { name } : {}) }, + }) + } + } +} diff --git a/packages/core/src/versionStack/versionStack.test.ts b/packages/core/src/versionStack/versionStack.test.ts index 541ca6e6..547291ee 100644 --- a/packages/core/src/versionStack/versionStack.test.ts +++ b/packages/core/src/versionStack/versionStack.test.ts @@ -2,6 +2,7 @@ import { describe, it, expect, beforeEach } from 'vitest' import { prisma } from '@shumai/db' import { setupTestDbHooks } from '@shumai/db/test' import { VersionStackService } from './versionStack' +import { assetService } from '../asset/asset' import { AssetType } from '@shumai/db' describe('VersionStackService', () => { @@ -207,4 +208,299 @@ describe('VersionStackService', () => { expect(children.map((c) => c.id).includes(file3.id)).toBe(true) }) }) + + describe('removeVersionFromStack', () => { + it('removes a version from a 3-version stack and turns it into a standalone file adjacent to the stack', async () => { + const team = await prisma.team.create({ data: { name: 'Test Team' } }) + const proj = await prisma.project.create({ + data: { name: 'Test Project', teamId: team.id }, + }) + const user = await prisma.user.create({ + data: { name: 'Test User', email: `test-${Date.now()}@example.com` }, + }) + const root = await prisma.asset.create({ + data: { + name: 'root', + type: AssetType.folder, + status: 'uploaded', + projectId: proj.id, + creatorId: user.id, + }, + }) + const parent = await prisma.asset.create({ + data: { + name: 'Parent Folder', + type: AssetType.folder, + projectId: proj.id, + parentId: root.id, + creatorId: user.id, + status: 'uploaded', + fileCount: 3, + }, + }) + + const file1 = await prisma.asset.create({ + data: { + name: 'file1.txt', + type: AssetType.file, + parentId: parent.id, + projectId: proj.id, + creatorId: user.id, + status: 'uploaded', + sizeByte: 100, + sortIndex: 'a0', + }, + }) + const file2 = await prisma.asset.create({ + data: { + name: 'file2.txt', + type: AssetType.file, + parentId: parent.id, + projectId: proj.id, + creatorId: user.id, + status: 'uploaded', + sizeByte: 200, + }, + }) + const file3 = await prisma.asset.create({ + data: { + name: 'file3.txt', + type: AssetType.file, + parentId: parent.id, + projectId: proj.id, + creatorId: user.id, + status: 'uploaded', + sizeByte: 300, + }, + }) + + const stack = await service.createVersionStack({ + fileIds: [file1.id, file2.id, file3.id], + projectId: proj.id, + creatorId: user.id, + }) + + // Stack should have 3 versions + expect(stack.fileCount).toBe(3) + expect(Number(stack.sizeByte)).toBe(600) + + // Parent fileCount should be 1 (the stack) + const parentBefore = await prisma.asset.findUnique({ where: { id: parent.id } }) + expect(parentBefore?.fileCount).toBe(1) + + // Remove file2 from stack + await service.removeVersionFromStack({ + stackId: stack.id, + fileId: file2.id, + }) + + // File2 should now be in parent folder + const updatedFile2 = await prisma.asset.findUnique({ where: { id: file2.id } }) + expect(updatedFile2?.parentId).toBe(parent.id) + expect(updatedFile2?.sortIndex).toBeDefined() + expect(updatedFile2!.sortIndex! > stack.sortIndex!).toBe(true) + + // Parent fileCount should be 2 (stack + file2) + const updatedParent = await prisma.asset.findUnique({ where: { id: parent.id } }) + expect(updatedParent?.fileCount).toBe(2) + + // Stack should still exist with 2 versions (file1 and file3) + const updatedStack = await prisma.asset.findUnique({ where: { id: stack.id } }) + expect(updatedStack).toBeDefined() + expect(updatedStack?.fileCount).toBe(2) + expect(Number(updatedStack?.sizeByte)).toBe(400) + + const remainingChildren = await prisma.asset.findMany({ + where: { parentId: stack.id }, + }) + expect(remainingChildren).toHaveLength(2) + expect(remainingChildren.map((c) => c.id).sort()).toEqual([file1.id, file3.id].sort()) + }) + + it('dissolves the version stack when removing down to 1 remaining version', async () => { + const team = await prisma.team.create({ data: { name: 'Test Team' } }) + const proj = await prisma.project.create({ + data: { name: 'Test Project', teamId: team.id }, + }) + const user = await prisma.user.create({ + data: { name: 'Test User', email: `test-${Date.now()}@example.com` }, + }) + const root = await prisma.asset.create({ + data: { + name: 'root', + type: AssetType.folder, + status: 'uploaded', + projectId: proj.id, + creatorId: user.id, + }, + }) + const parent = await prisma.asset.create({ + data: { + name: 'Parent Folder', + type: AssetType.folder, + projectId: proj.id, + parentId: root.id, + creatorId: user.id, + status: 'uploaded', + fileCount: 2, + }, + }) + + const file1 = await prisma.asset.create({ + data: { + name: 'file1.txt', + type: AssetType.file, + parentId: parent.id, + projectId: proj.id, + creatorId: user.id, + status: 'uploaded', + sizeByte: 100, + sortIndex: 'a0', + }, + }) + const file2 = await prisma.asset.create({ + data: { + name: 'file2.txt', + type: AssetType.file, + parentId: parent.id, + projectId: proj.id, + creatorId: user.id, + status: 'uploaded', + sizeByte: 200, + }, + }) + + const stack = await service.createVersionStack({ + fileIds: [file1.id, file2.id], + projectId: proj.id, + creatorId: user.id, + }) + + // Remove file2 from stack + await service.removeVersionFromStack({ + stackId: stack.id, + fileId: file2.id, + }) + + // Stack asset should be deleted + const deletedStack = await prisma.asset.findUnique({ where: { id: stack.id } }) + expect(deletedStack).toBeNull() + + // File1 should now be in parent folder and inherited stack's sortIndex + const updatedFile1 = await prisma.asset.findUnique({ where: { id: file1.id } }) + expect(updatedFile1?.parentId).toBe(parent.id) + expect(updatedFile1?.sortIndex).toBe('a0') + + // File2 should also be in parent folder + const updatedFile2 = await prisma.asset.findUnique({ where: { id: file2.id } }) + expect(updatedFile2?.parentId).toBe(parent.id) + + // Parent fileCount should be 2 + const updatedParent = await prisma.asset.findUnique({ where: { id: parent.id } }) + expect(updatedParent?.fileCount).toBe(2) + }) + + it('updates share link symlinks when normal asset becomes version stack and when stack dissolves back to normal asset', async () => { + const team = await prisma.team.create({ data: { name: 'Test Team' } }) + const proj = await prisma.project.create({ + data: { name: 'Test Project', teamId: team.id }, + }) + const user = await prisma.user.create({ + data: { name: 'Test User', email: `test-${Date.now()}@example.com` }, + }) + const root = await prisma.asset.create({ + data: { + name: 'root', + type: AssetType.folder, + status: 'uploaded', + projectId: proj.id, + creatorId: user.id, + }, + }) + const shareRoot = await prisma.asset.create({ + data: { + name: 'share-root', + type: AssetType.share_root, + status: 'uploaded', + projectId: proj.id, + creatorId: user.id, + fileCount: 0, + }, + }) + const shareLink = await prisma.shareLink.create({ + data: { + name: 'My Share', + projectId: proj.id, + rootFolderId: shareRoot.id, + creatorId: user.id, + }, + }) + + const file1 = await prisma.asset.create({ + data: { + name: 'file1.txt', + type: AssetType.file, + parentId: root.id, + projectId: proj.id, + creatorId: user.id, + status: 'uploaded', + sizeByte: 100, + }, + }) + const file2 = await prisma.asset.create({ + data: { + name: 'file2.txt', + type: AssetType.file, + parentId: root.id, + projectId: proj.id, + creatorId: user.id, + status: 'uploaded', + sizeByte: 200, + }, + }) + + // Add file1 to share link (create symlink) + const symlink = await prisma.asset.create({ + data: { + name: file1.name, + type: AssetType.symlink, + parentId: shareLink.rootFolderId, + targetId: file1.id, + projectId: proj.id, + creatorId: user.id, + status: 'uploaded', + }, + }) + + // 1. Group file1 and file2 into a version stack + const stack = await service.createVersionStack({ + fileIds: [file1.id, file2.id], + projectId: proj.id, + creatorId: user.id, + }) + + // Symlink in share link should now point to stack.id + const symlinkAfterStack = await prisma.asset.findUnique({ where: { id: symlink.id } }) + expect(symlinkAfterStack?.targetId).toBe(stack.id) + + // 2. Remove file2 from stack -> stack dissolves -> only file1 remains + await service.removeVersionFromStack({ + stackId: stack.id, + fileId: file2.id, + }) + + // Symlink in share link should now point directly to file1.id and have file1's name + const symlinkAfterDissolve = await prisma.asset.findUnique({ where: { id: symlink.id } }) + expect(symlinkAfterDissolve?.targetId).toBe(file1.id) + expect(symlinkAfterDissolve?.name).toBe(file1.name) + + // Listing share link files returns file1 with correct name + const shareFiles = await assetService.listChildren({ + assetId: shareLink.rootFolderId, + assetType: AssetType.file, + }) + expect(shareFiles.data).toHaveLength(1) + expect(shareFiles.data[0].name).toBe(file1.name) + }) + }) }) diff --git a/packages/core/src/versionStack/versionStack.ts b/packages/core/src/versionStack/versionStack.ts index 9d9dfd6d..dac59a1d 100644 --- a/packages/core/src/versionStack/versionStack.ts +++ b/packages/core/src/versionStack/versionStack.ts @@ -1,7 +1,12 @@ import { generateKeyBetween } from 'jittered-fractional-indexing' import { prisma } from '@shumai/db' import { type Asset, AssetType } from '@shumai/db' -import { ChangeStackFileVersionParams, CreateVersionStackParams } from '@shumai/dtos' +import { + ChangeStackFileVersionParams, + CreateVersionStackParams, + RemoveStackVersionParams, +} from '@shumai/dtos' +import { dedupeSymlinksToTarget } from '../asset/symlink' function generateSortIndex(previous?: string | null): string { if (!previous) return generateKeyBetween(null, null) @@ -95,6 +100,9 @@ export class VersionStackService { }, }) + // Update existing symlinks pointing to any of the stacked files + await dedupeSymlinksToTarget(tx, { targetIds: fileIds, newTargetId: stack.id }) + return stack }) } @@ -127,7 +135,7 @@ export class VersionStackService { if (beforeId === '-1') { const lastFile = await tx.asset.findFirst({ - where: { parentId: stackId }, + where: { parentId: stackId, id: { not: fileId } }, orderBy: { sortIndex: 'desc' }, }) newSortIndex = generateKeyBetween(lastFile?.sortIndex || null, null) @@ -145,6 +153,7 @@ export class VersionStackService { const prevFile = await tx.asset.findFirst({ where: { parentId: stackId, + id: { not: fileId }, sortIndex: { lt: beforeFile.sortIndex!, }, @@ -168,6 +177,123 @@ export class VersionStackService { }) }) } + + async removeVersionFromStack(params: RemoveStackVersionParams): Promise { + const { stackId, fileId } = params + + await this.prismaClient.$transaction(async (tx) => { + const stack = await tx.asset.findUnique({ + where: { id: stackId }, + }) + if (!stack) { + throw new Error('stack not found') + } + if (stack.type !== AssetType.version_stack) { + throw new Error('asset is not a version stack') + } + if (!stack.parentId) { + throw new Error('stack has no parent') + } + + const fileToRemove = await tx.asset.findUnique({ + where: { id: fileId }, + }) + if (!fileToRemove) { + throw new Error('file not found') + } + if (fileToRemove.parentId !== stackId) { + throw new Error('file is not in the stack') + } + + // Find next sibling in parent folder after the stack to insert the removed file adjacent to the stack + const nextSibling = await tx.asset.findFirst({ + where: { + parentId: stack.parentId, + id: { not: stack.id }, + sortIndex: { + gt: stack.sortIndex || '', + }, + }, + orderBy: { sortIndex: 'asc' }, + }) + + let newSortIndex: string + try { + newSortIndex = generateKeyBetween(stack.sortIndex || null, nextSibling?.sortIndex || null) + } catch { + newSortIndex = generateKeyBetween(null, null) + } + + await tx.asset.update({ + where: { id: fileId }, + data: { + parentId: stack.parentId, + sortIndex: newSortIndex, + }, + }) + + // Increment parent folder fileCount for the newly standalone file + await tx.asset.update({ + where: { id: stack.parentId }, + data: { + fileCount: { increment: 1 }, + }, + }) + + // Remaining files in stack + const remainingFiles = await tx.asset.findMany({ + where: { parentId: stackId, isDeleted: false, id: { not: fileId } }, + orderBy: { sortIndex: 'asc' }, + }) + + if (remainingFiles.length > 1) { + let totalSize = 0 + for (const f of remainingFiles) { + totalSize += Number(f.sizeByte) + } + await tx.asset.update({ + where: { id: stack.id }, + data: { + fileCount: remainingFiles.length, + sizeByte: totalSize, + }, + }) + } else if (remainingFiles.length === 1) { + const lastChild = remainingFiles[0] + + // Update symlinks pointing to stack.id to point to the single remaining child + await tx.asset.updateMany({ + where: { targetId: stack.id, type: AssetType.symlink }, + data: { targetId: lastChild.id, name: lastChild.name }, + }) + + // Reparent the single remaining child to stack.parentId, keeping stack's sortIndex + await tx.asset.update({ + where: { id: lastChild.id }, + data: { + parentId: stack.parentId, + sortIndex: stack.sortIndex, + }, + }) + + // Delete the stack asset (parent folder file count is unchanged: -1 stack, +1 remaining child) + await tx.asset.delete({ + where: { id: stack.id }, + }) + } else { + await tx.asset.deleteMany({ + where: { targetId: stack.id, type: AssetType.symlink }, + }) + await tx.asset.delete({ + where: { id: stack.id }, + }) + await tx.asset.update({ + where: { id: stack.parentId }, + data: { fileCount: { decrement: 1 } }, + }) + } + }) + } } export const versionStackService = new VersionStackService() diff --git a/packages/dtos/src/asset.ts b/packages/dtos/src/asset.ts index 109dc5a8..40282ac8 100644 --- a/packages/dtos/src/asset.ts +++ b/packages/dtos/src/asset.ts @@ -120,10 +120,12 @@ export const assetInfoSchema = z.object({ id: z.string(), name: z.string().optional().nullable(), previewUrl: z.string().optional().nullable(), + createdAt: z.string().optional().nullable(), creator: z .object({ id: z.string(), name: z.string().nullable(), + image: z.string().optional().nullable(), }) .nullable() .optional(), diff --git a/packages/dtos/src/versionStack.ts b/packages/dtos/src/versionStack.ts index d80599e7..f6ca3aa1 100644 --- a/packages/dtos/src/versionStack.ts +++ b/packages/dtos/src/versionStack.ts @@ -22,3 +22,25 @@ export interface ChangeStackFileVersionParams { fileId: string beforeId: string } + +export interface RemoveStackVersionParams { + stackId: string + fileId: string +} + +export const stackVersionInfoSchema = z.object({ + id: z.string(), + version: z.number(), + name: z.string().optional().nullable(), + previewUrl: z.string().optional().nullable(), + createdAt: z.string().optional().nullable(), + creator: z + .object({ + id: z.string(), + name: z.string().nullable(), + image: z.string().optional().nullable(), + }) + .nullable() + .optional(), +}) +export type StackVersionInfo = z.infer diff --git a/packages/webui/components/breadcrumb-nav.tsx b/packages/webui/components/breadcrumb-nav.tsx index 11e22b25..2603dd55 100644 --- a/packages/webui/components/breadcrumb-nav.tsx +++ b/packages/webui/components/breadcrumb-nav.tsx @@ -40,6 +40,8 @@ import { LayoutGrid, List, } from 'lucide-react' +import { useState } from 'react' +import { ManageVersionsDialog } from './manage-versions-dialog' interface BreadcrumbNavProps { teamId: string @@ -120,6 +122,7 @@ export function BreadcrumbNav({ }: BreadcrumbNavProps) { const navigate = useNavigate() const { canEdit } = usePermissions(projectId) + const [isManageVersionsOpen, setIsManageVersionsOpen] = useState(false) const isChatbotDisabled = false @@ -236,7 +239,7 @@ export function BreadcrumbNav({ {currentAsset.name} ) : ( - + {currentAsset.name} {currentAsset.version !== undefined && ( @@ -379,10 +382,10 @@ export function BreadcrumbNav({
@@ -395,6 +398,40 @@ export function BreadcrumbNav({ )} ) : null} + + {fileId && versions && versions.length > 0 && ( + { + setIsManageVersionsOpen(false) + navigate({ + to: '/projects/$projectId/files/$fileId', + params: { projectId, fileId: remainingFileId }, + }) + }} + onVersionRemoved={(removedVersionId, remainingVersions) => { + const currentVersionId = currentAsset.version + ? versions.find((v) => v.version === currentAsset.version)?.id + : undefined + if (currentVersionId === removedVersionId) { + const topVersion = remainingVersions[0] + if (topVersion) { + navigate({ + to: '/projects/$projectId/files/$fileId', + params: { projectId, fileId }, + search: (prev: Record) => ({ + ...prev, + version: topVersion.id, + }), + }) + } + } + }} + /> + )}
diff --git a/packages/webui/components/manage-versions-dialog.tsx b/packages/webui/components/manage-versions-dialog.tsx new file mode 100644 index 00000000..cf4e1231 --- /dev/null +++ b/packages/webui/components/manage-versions-dialog.tsx @@ -0,0 +1,313 @@ +import { client } from '@/ui/api/client' +import { Button } from '@/ui/components/ui/button' +import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/ui/components/ui/dialog' +import { + DropdownMenu, + DropdownMenuContent, + DropdownMenuItem, + DropdownMenuTrigger, +} from '@/ui/components/ui/dropdown-menu' +import { ScrollArea } from '@/ui/components/ui/scroll-area' +import { cn } from '@/ui/lib/utils' +import { m } from '@/ui/paraglide/messages.js' +import { PointerActivationConstraints } from '@dnd-kit/dom' +import { DragDropProvider, KeyboardSensor, PointerSensor, type DragEndEvent } from '@dnd-kit/react' +import { isSortable, useSortable } from '@dnd-kit/react/sortable' +import type { StackVersionInfo } from '@shumai/dtos' +import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query' +import { format, parseISO } from 'date-fns' +import { FileIcon, GripVertical, MoreVertical, Trash2 } from 'lucide-react' +import { useEffect, useState } from 'react' +import { toast } from 'sonner' + +interface ManageVersionsDialogProps { + open: boolean + onOpenChange: (open: boolean) => void + stackId: string + canEdit?: boolean + onVersionRemoved?: (removedVersionId: string, remainingVersions: StackVersionInfo[]) => void + onStackDissolved?: (remainingFileId: string) => void +} + +interface SortableVersionRowProps { + version: StackVersionInfo + displayVersionNumber: number + index: number + canEdit: boolean + onRemove: (versionId: string) => void +} + +function formatVersionDate(dateString?: string | null): string | null { + if (!dateString) return null + try { + const date = parseISO(dateString) + if (isNaN(date.getTime())) return null + return format(date, 'MMM d, yyyy') + } catch { + return null + } +} + +function SortableVersionRow({ + version, + displayVersionNumber, + index, + canEdit, + onRemove, +}: SortableVersionRowProps) { + const [dropdownOpen, setDropdownOpen] = useState(false) + const { ref, handleRef } = useSortable({ + id: version.id, + index, + disabled: !canEdit, + }) + + const formattedDate = formatVersionDate(version.createdAt) + + return ( +
+ {/* 1. Version Label */} +
+ v{displayVersionNumber} +
+ + {/* 2. Drag Handler */} + {canEdit ? ( +
+ +
+ ) : ( +
+ )} + + {/* 3. Thumbnail Preview */} +
+ {version.previewUrl ? ( + {version.name + ) : ( + + )} +
+ + {/* 4. Name / Creator / Create Date (2 rows) */} +
+ {/* Row 1: Name */} + + {version.name || 'Untitled'} + + {/* Row 2: Creator & Create Date */} +
+ {version.creator?.name || m.unknown()} + {formattedDate && ( + <> + • + {formattedDate} + + )} +
+
+ + {/* 5. Three-dot button (only shows on card hover or dropdown open) */} + {canEdit && ( + + + + + + onRemove(version.id)} + className="text-destructive focus:text-destructive cursor-pointer" + > + + {m.remove_from_stack()} + + + + )} +
+ ) +} + +export function ManageVersionsDialog({ + open, + onOpenChange, + stackId, + canEdit = true, + onVersionRemoved, + onStackDissolved, +}: ManageVersionsDialogProps) { + const queryClient = useQueryClient() + const [localVersions, setLocalVersions] = useState([]) + + const { data: fetchedVersions, isLoading } = useQuery({ + queryKey: ['version_stacks', stackId, 'versions'], + queryFn: async () => { + const res = await client.api.version_stacks[':stackId'].versions.$get({ + param: { stackId }, + }) + if (!res.ok) throw new Error('Failed to fetch versions') + return (await res.json()) as StackVersionInfo[] + }, + enabled: open && !!stackId, + }) + + useEffect(() => { + if (fetchedVersions) { + setLocalVersions(fetchedVersions) + } + }, [fetchedVersions]) + + // Reorder mutation + const { mutate: reorderVersion } = useMutation({ + mutationFn: async ({ fileId, beforeId }: { fileId: string; beforeId: string }) => { + const res = await client.api.version_stacks[':stackId'].order.$post({ + param: { stackId }, + json: { fileId, beforeId }, + }) + if (!res.ok) throw new Error('Failed to reorder versions') + }, + onSuccess: () => { + queryClient.invalidateQueries({ queryKey: ['version_stacks'] }) + queryClient.invalidateQueries({ queryKey: ['files'] }) + queryClient.invalidateQueries({ queryKey: ['projects'] }) + toast.success(m.version_reordered_successfully()) + }, + onError: () => { + toast.error(m.failed_to_reorder_versions()) + if (fetchedVersions) { + setLocalVersions(fetchedVersions) + } + }, + }) + + // Remove version mutation + const { mutate: removeVersion, isPending: isRemoving } = useMutation({ + mutationFn: async (versionId: string) => { + const res = await client.api.version_stacks[':stackId'].versions[':versionId'].$delete({ + param: { stackId, versionId }, + }) + if (!res.ok) throw new Error('Failed to remove version from stack') + return versionId + }, + onSuccess: (removedVersionId) => { + toast.success(m.version_removed_successfully()) + const remaining = localVersions.filter((v) => v.id !== removedVersionId) + setLocalVersions(remaining) + + queryClient.invalidateQueries({ queryKey: ['version_stacks'] }) + queryClient.invalidateQueries({ queryKey: ['files'] }) + queryClient.invalidateQueries({ queryKey: ['projects'] }) + + if (remaining.length <= 1) { + const singleRemaining = remaining[0] + onOpenChange(false) + if (singleRemaining) { + onStackDissolved?.(singleRemaining.id) + } + } else { + onVersionRemoved?.(removedVersionId, remaining) + } + }, + onError: () => { + toast.error(m.failed_to_remove_version()) + }, + }) + + const handleDragEnd = (event: DragEndEvent) => { + if (event.canceled) return + const { source } = event.operation + if (!isSortable(source)) return + const { initialIndex, index } = source + if (initialIndex === index) return + + const updated = [...localVersions] + const [movedItem] = updated.splice(initialIndex, 1) + updated.splice(index, 0, movedItem) + setLocalVersions(updated) + + // Calculate beforeId for the API: + // When moved to index `index` in a list ordered from newest to oldest: + // If index is at the very bottom (index === updated.length - 1), beforeId = '-1' (places after all others). + // Otherwise, beforeId is the ID of the item currently at index + 1 (the next item below it in the list). + const beforeId = index === updated.length - 1 ? '-1' : updated[index + 1].id + + reorderVersion({ + fileId: movedItem.id, + beforeId, + }) + } + + const handleRemove = (versionId: string) => { + if (isRemoving) return + removeVersion(versionId) + } + + return ( + + + + {m.manage_versions_title()} + + + + {isLoading ? ( +
+ {m.loading?.() || 'Loading...'} +
+ ) : localVersions.length === 0 ? ( +
+ {m.no_versions_found()} +
+ ) : ( +
+ + {localVersions.map((version, index) => ( + + ))} + +
+ )} +
+
+
+ ) +} diff --git a/packages/webui/messages/en.json b/packages/webui/messages/en.json index 23b5696c..30c7e204 100644 --- a/packages/webui/messages/en.json +++ b/packages/webui/messages/en.json @@ -516,7 +516,14 @@ "auth_community_cta": "Join our community of developers and designers.", "versions": "Versions", - "manage_versions": "Manage versions...", + "manage_versions": "Manage versions", + "manage_versions_title": "Manage versions", + "remove_from_stack": "Remove from stack", + "version_removed_successfully": "Version removed from stack", + "failed_to_remove_version": "Failed to remove version", + "version_reordered_successfully": "Version order updated", + "failed_to_reorder_versions": "Failed to reorder versions", + "no_versions_found": "No versions found", "compare_versions": "Compare Versions", "exit_compare": "Exit compare", "switch_version": "Switch version", diff --git a/packages/webui/messages/zh.json b/packages/webui/messages/zh.json index 67b04ef8..28bd521a 100644 --- a/packages/webui/messages/zh.json +++ b/packages/webui/messages/zh.json @@ -516,7 +516,14 @@ "auth_community_cta": "加入我们的开发者和设计师社区。", "versions": "版本", - "manage_versions": "管理版本...", + "manage_versions": "管理版本", + "manage_versions_title": "管理版本", + "remove_from_stack": "从版本堆栈中移除", + "version_removed_successfully": "已从版本堆栈中移除版本", + "failed_to_remove_version": "移除版本失败", + "version_reordered_successfully": "版本顺序已更新", + "failed_to_reorder_versions": "版本重新排序失败", + "no_versions_found": "暂无版本", "compare_versions": "对比版本", "exit_compare": "退出对比", "switch_version": "切换版本", diff --git a/packages/webui/paraglide/messages/_index.d.ts b/packages/webui/paraglide/messages/_index.d.ts index ef7b6d84..63814400 100644 --- a/packages/webui/paraglide/messages/_index.d.ts +++ b/packages/webui/paraglide/messages/_index.d.ts @@ -494,6 +494,13 @@ export * from "./auth_feature_teams.js"; export * from "./auth_community_cta.js"; export * from "./versions.js"; export * from "./manage_versions.js"; +export * from "./manage_versions_title.js"; +export * from "./remove_from_stack.js"; +export * from "./version_removed_successfully.js"; +export * from "./failed_to_remove_version.js"; +export * from "./version_reordered_successfully.js"; +export * from "./failed_to_reorder_versions.js"; +export * from "./no_versions_found.js"; export * from "./compare_versions.js"; export * from "./exit_compare.js"; export * from "./switch_version.js"; diff --git a/packages/webui/paraglide/messages/_index.js b/packages/webui/paraglide/messages/_index.js index 14c0bd31..c977f550 100644 --- a/packages/webui/paraglide/messages/_index.js +++ b/packages/webui/paraglide/messages/_index.js @@ -496,6 +496,13 @@ export * from './auth_feature_teams.js' export * from './auth_community_cta.js' export * from './versions.js' export * from './manage_versions.js' +export * from './manage_versions_title.js' +export * from './remove_from_stack.js' +export * from './version_removed_successfully.js' +export * from './failed_to_remove_version.js' +export * from './version_reordered_successfully.js' +export * from './failed_to_reorder_versions.js' +export * from './no_versions_found.js' export * from './compare_versions.js' export * from './exit_compare.js' export * from './switch_version.js' diff --git a/packages/webui/paraglide/messages/failed_to_remove_version.d.ts b/packages/webui/paraglide/messages/failed_to_remove_version.d.ts new file mode 100644 index 00000000..b6e41445 --- /dev/null +++ b/packages/webui/paraglide/messages/failed_to_remove_version.d.ts @@ -0,0 +1,16 @@ +/** +* | output | +* | --- | +* | "Failed to remove version" | +* +* @param {Failed_To_Remove_VersionInputs} inputs +* @param {{ locale?: "en" | "zh" }} options +* @returns {LocalizedString} +*/ +export const failed_to_remove_version: ((inputs?: Failed_To_Remove_VersionInputs, options?: { + locale?: "en" | "zh"; +}) => LocalizedString) & import("../runtime.js").MessageMetadata; +export type LocalizedString = import("../runtime.js").LocalizedString; +export type Failed_To_Remove_VersionInputs = {}; diff --git a/packages/webui/paraglide/messages/failed_to_remove_version.js b/packages/webui/paraglide/messages/failed_to_remove_version.js new file mode 100644 index 00000000..b7e72c84 --- /dev/null +++ b/packages/webui/paraglide/messages/failed_to_remove_version.js @@ -0,0 +1,29 @@ +/* eslint-disable */ +import { getLocale, experimentalStaticLocale } from '../runtime.js'; + +/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */ + +/** @typedef {{}} Failed_To_Remove_VersionInputs */ + +const en_failed_to_remove_version = /** @type {(inputs: Failed_To_Remove_VersionInputs) => LocalizedString} */ () => { + return /** @type {LocalizedString} */ (`Failed to remove version`) +}; + +const zh_failed_to_remove_version = /** @type {(inputs: Failed_To_Remove_VersionInputs) => LocalizedString} */ () => { + return /** @type {LocalizedString} */ (`移除版本失败`) +}; + +/** +* | output | +* | --- | +* | "Failed to remove version" | +* +* @param {Failed_To_Remove_VersionInputs} inputs +* @param {{ locale?: "en" | "zh" }} options +* @returns {LocalizedString} +*/ +export const failed_to_remove_version = /** @type {((inputs?: Failed_To_Remove_VersionInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata} */ ((inputs = {}, options = {}) => { + const locale = experimentalStaticLocale ?? options.locale ?? getLocale() + if (locale === "en") return en_failed_to_remove_version(inputs) + return zh_failed_to_remove_version(inputs) +}); \ No newline at end of file diff --git a/packages/webui/paraglide/messages/failed_to_reorder_versions.d.ts b/packages/webui/paraglide/messages/failed_to_reorder_versions.d.ts new file mode 100644 index 00000000..8938fc7c --- /dev/null +++ b/packages/webui/paraglide/messages/failed_to_reorder_versions.d.ts @@ -0,0 +1,16 @@ +/** +* | output | +* | --- | +* | "Failed to reorder versions" | +* +* @param {Failed_To_Reorder_VersionsInputs} inputs +* @param {{ locale?: "en" | "zh" }} options +* @returns {LocalizedString} +*/ +export const failed_to_reorder_versions: ((inputs?: Failed_To_Reorder_VersionsInputs, options?: { + locale?: "en" | "zh"; +}) => LocalizedString) & import("../runtime.js").MessageMetadata; +export type LocalizedString = import("../runtime.js").LocalizedString; +export type Failed_To_Reorder_VersionsInputs = {}; diff --git a/packages/webui/paraglide/messages/failed_to_reorder_versions.js b/packages/webui/paraglide/messages/failed_to_reorder_versions.js new file mode 100644 index 00000000..508cd066 --- /dev/null +++ b/packages/webui/paraglide/messages/failed_to_reorder_versions.js @@ -0,0 +1,29 @@ +/* eslint-disable */ +import { getLocale, experimentalStaticLocale } from '../runtime.js'; + +/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */ + +/** @typedef {{}} Failed_To_Reorder_VersionsInputs */ + +const en_failed_to_reorder_versions = /** @type {(inputs: Failed_To_Reorder_VersionsInputs) => LocalizedString} */ () => { + return /** @type {LocalizedString} */ (`Failed to reorder versions`) +}; + +const zh_failed_to_reorder_versions = /** @type {(inputs: Failed_To_Reorder_VersionsInputs) => LocalizedString} */ () => { + return /** @type {LocalizedString} */ (`版本重新排序失败`) +}; + +/** +* | output | +* | --- | +* | "Failed to reorder versions" | +* +* @param {Failed_To_Reorder_VersionsInputs} inputs +* @param {{ locale?: "en" | "zh" }} options +* @returns {LocalizedString} +*/ +export const failed_to_reorder_versions = /** @type {((inputs?: Failed_To_Reorder_VersionsInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata} */ ((inputs = {}, options = {}) => { + const locale = experimentalStaticLocale ?? options.locale ?? getLocale() + if (locale === "en") return en_failed_to_reorder_versions(inputs) + return zh_failed_to_reorder_versions(inputs) +}); \ No newline at end of file diff --git a/packages/webui/paraglide/messages/manage_versions.d.ts b/packages/webui/paraglide/messages/manage_versions.d.ts index ffd4c9b6..e748fbc8 100644 --- a/packages/webui/paraglide/messages/manage_versions.d.ts +++ b/packages/webui/paraglide/messages/manage_versions.d.ts @@ -1,7 +1,7 @@ /** * | output | * | --- | -* | "Manage versions..." | +* | "Manage versions" | * * @param {Manage_VersionsInputs} inputs * @param {{ locale?: "en" | "zh" }} options diff --git a/packages/webui/paraglide/messages/manage_versions.js b/packages/webui/paraglide/messages/manage_versions.js index 71df009c..5fbd3818 100644 --- a/packages/webui/paraglide/messages/manage_versions.js +++ b/packages/webui/paraglide/messages/manage_versions.js @@ -6,17 +6,17 @@ import { getLocale, experimentalStaticLocale } from '../runtime.js'; /** @typedef {{}} Manage_VersionsInputs */ const en_manage_versions = /** @type {(inputs: Manage_VersionsInputs) => LocalizedString} */ () => { - return /** @type {LocalizedString} */ (`Manage versions...`) + return /** @type {LocalizedString} */ (`Manage versions`) }; const zh_manage_versions = /** @type {(inputs: Manage_VersionsInputs) => LocalizedString} */ () => { - return /** @type {LocalizedString} */ (`管理版本...`) + return /** @type {LocalizedString} */ (`管理版本`) }; /** * | output | * | --- | -* | "Manage versions..." | +* | "Manage versions" | * * @param {Manage_VersionsInputs} inputs * @param {{ locale?: "en" | "zh" }} options diff --git a/packages/webui/paraglide/messages/manage_versions_title.d.ts b/packages/webui/paraglide/messages/manage_versions_title.d.ts new file mode 100644 index 00000000..5095c2d2 --- /dev/null +++ b/packages/webui/paraglide/messages/manage_versions_title.d.ts @@ -0,0 +1,16 @@ +/** +* | output | +* | --- | +* | "Manage versions" | +* +* @param {Manage_Versions_TitleInputs} inputs +* @param {{ locale?: "en" | "zh" }} options +* @returns {LocalizedString} +*/ +export const manage_versions_title: ((inputs?: Manage_Versions_TitleInputs, options?: { + locale?: "en" | "zh"; +}) => LocalizedString) & import("../runtime.js").MessageMetadata; +export type LocalizedString = import("../runtime.js").LocalizedString; +export type Manage_Versions_TitleInputs = {}; diff --git a/packages/webui/paraglide/messages/manage_versions_title.js b/packages/webui/paraglide/messages/manage_versions_title.js new file mode 100644 index 00000000..d989c031 --- /dev/null +++ b/packages/webui/paraglide/messages/manage_versions_title.js @@ -0,0 +1,29 @@ +/* eslint-disable */ +import { getLocale, experimentalStaticLocale } from '../runtime.js'; + +/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */ + +/** @typedef {{}} Manage_Versions_TitleInputs */ + +const en_manage_versions_title = /** @type {(inputs: Manage_Versions_TitleInputs) => LocalizedString} */ () => { + return /** @type {LocalizedString} */ (`Manage versions`) +}; + +const zh_manage_versions_title = /** @type {(inputs: Manage_Versions_TitleInputs) => LocalizedString} */ () => { + return /** @type {LocalizedString} */ (`管理版本`) +}; + +/** +* | output | +* | --- | +* | "Manage versions" | +* +* @param {Manage_Versions_TitleInputs} inputs +* @param {{ locale?: "en" | "zh" }} options +* @returns {LocalizedString} +*/ +export const manage_versions_title = /** @type {((inputs?: Manage_Versions_TitleInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata} */ ((inputs = {}, options = {}) => { + const locale = experimentalStaticLocale ?? options.locale ?? getLocale() + if (locale === "en") return en_manage_versions_title(inputs) + return zh_manage_versions_title(inputs) +}); \ No newline at end of file diff --git a/packages/webui/paraglide/messages/no_versions_found.d.ts b/packages/webui/paraglide/messages/no_versions_found.d.ts new file mode 100644 index 00000000..61d9458d --- /dev/null +++ b/packages/webui/paraglide/messages/no_versions_found.d.ts @@ -0,0 +1,16 @@ +/** +* | output | +* | --- | +* | "No versions found" | +* +* @param {No_Versions_FoundInputs} inputs +* @param {{ locale?: "en" | "zh" }} options +* @returns {LocalizedString} +*/ +export const no_versions_found: ((inputs?: No_Versions_FoundInputs, options?: { + locale?: "en" | "zh"; +}) => LocalizedString) & import("../runtime.js").MessageMetadata; +export type LocalizedString = import("../runtime.js").LocalizedString; +export type No_Versions_FoundInputs = {}; diff --git a/packages/webui/paraglide/messages/no_versions_found.js b/packages/webui/paraglide/messages/no_versions_found.js new file mode 100644 index 00000000..1a39c1d4 --- /dev/null +++ b/packages/webui/paraglide/messages/no_versions_found.js @@ -0,0 +1,29 @@ +/* eslint-disable */ +import { getLocale, experimentalStaticLocale } from '../runtime.js'; + +/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */ + +/** @typedef {{}} No_Versions_FoundInputs */ + +const en_no_versions_found = /** @type {(inputs: No_Versions_FoundInputs) => LocalizedString} */ () => { + return /** @type {LocalizedString} */ (`No versions found`) +}; + +const zh_no_versions_found = /** @type {(inputs: No_Versions_FoundInputs) => LocalizedString} */ () => { + return /** @type {LocalizedString} */ (`暂无版本`) +}; + +/** +* | output | +* | --- | +* | "No versions found" | +* +* @param {No_Versions_FoundInputs} inputs +* @param {{ locale?: "en" | "zh" }} options +* @returns {LocalizedString} +*/ +export const no_versions_found = /** @type {((inputs?: No_Versions_FoundInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata} */ ((inputs = {}, options = {}) => { + const locale = experimentalStaticLocale ?? options.locale ?? getLocale() + if (locale === "en") return en_no_versions_found(inputs) + return zh_no_versions_found(inputs) +}); \ No newline at end of file diff --git a/packages/webui/paraglide/messages/remove_from_stack.d.ts b/packages/webui/paraglide/messages/remove_from_stack.d.ts new file mode 100644 index 00000000..76127fc2 --- /dev/null +++ b/packages/webui/paraglide/messages/remove_from_stack.d.ts @@ -0,0 +1,16 @@ +/** +* | output | +* | --- | +* | "Remove from stack" | +* +* @param {Remove_From_StackInputs} inputs +* @param {{ locale?: "en" | "zh" }} options +* @returns {LocalizedString} +*/ +export const remove_from_stack: ((inputs?: Remove_From_StackInputs, options?: { + locale?: "en" | "zh"; +}) => LocalizedString) & import("../runtime.js").MessageMetadata; +export type LocalizedString = import("../runtime.js").LocalizedString; +export type Remove_From_StackInputs = {}; diff --git a/packages/webui/paraglide/messages/remove_from_stack.js b/packages/webui/paraglide/messages/remove_from_stack.js new file mode 100644 index 00000000..0c4ffd05 --- /dev/null +++ b/packages/webui/paraglide/messages/remove_from_stack.js @@ -0,0 +1,29 @@ +/* eslint-disable */ +import { getLocale, experimentalStaticLocale } from '../runtime.js'; + +/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */ + +/** @typedef {{}} Remove_From_StackInputs */ + +const en_remove_from_stack = /** @type {(inputs: Remove_From_StackInputs) => LocalizedString} */ () => { + return /** @type {LocalizedString} */ (`Remove from stack`) +}; + +const zh_remove_from_stack = /** @type {(inputs: Remove_From_StackInputs) => LocalizedString} */ () => { + return /** @type {LocalizedString} */ (`从版本堆栈中移除`) +}; + +/** +* | output | +* | --- | +* | "Remove from stack" | +* +* @param {Remove_From_StackInputs} inputs +* @param {{ locale?: "en" | "zh" }} options +* @returns {LocalizedString} +*/ +export const remove_from_stack = /** @type {((inputs?: Remove_From_StackInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata} */ ((inputs = {}, options = {}) => { + const locale = experimentalStaticLocale ?? options.locale ?? getLocale() + if (locale === "en") return en_remove_from_stack(inputs) + return zh_remove_from_stack(inputs) +}); \ No newline at end of file diff --git a/packages/webui/paraglide/messages/version_removed_successfully.d.ts b/packages/webui/paraglide/messages/version_removed_successfully.d.ts new file mode 100644 index 00000000..b3a73305 --- /dev/null +++ b/packages/webui/paraglide/messages/version_removed_successfully.d.ts @@ -0,0 +1,16 @@ +/** +* | output | +* | --- | +* | "Version removed from stack" | +* +* @param {Version_Removed_SuccessfullyInputs} inputs +* @param {{ locale?: "en" | "zh" }} options +* @returns {LocalizedString} +*/ +export const version_removed_successfully: ((inputs?: Version_Removed_SuccessfullyInputs, options?: { + locale?: "en" | "zh"; +}) => LocalizedString) & import("../runtime.js").MessageMetadata; +export type LocalizedString = import("../runtime.js").LocalizedString; +export type Version_Removed_SuccessfullyInputs = {}; diff --git a/packages/webui/paraglide/messages/version_removed_successfully.js b/packages/webui/paraglide/messages/version_removed_successfully.js new file mode 100644 index 00000000..8a9bcceb --- /dev/null +++ b/packages/webui/paraglide/messages/version_removed_successfully.js @@ -0,0 +1,29 @@ +/* eslint-disable */ +import { getLocale, experimentalStaticLocale } from '../runtime.js'; + +/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */ + +/** @typedef {{}} Version_Removed_SuccessfullyInputs */ + +const en_version_removed_successfully = /** @type {(inputs: Version_Removed_SuccessfullyInputs) => LocalizedString} */ () => { + return /** @type {LocalizedString} */ (`Version removed from stack`) +}; + +const zh_version_removed_successfully = /** @type {(inputs: Version_Removed_SuccessfullyInputs) => LocalizedString} */ () => { + return /** @type {LocalizedString} */ (`已从版本堆栈中移除版本`) +}; + +/** +* | output | +* | --- | +* | "Version removed from stack" | +* +* @param {Version_Removed_SuccessfullyInputs} inputs +* @param {{ locale?: "en" | "zh" }} options +* @returns {LocalizedString} +*/ +export const version_removed_successfully = /** @type {((inputs?: Version_Removed_SuccessfullyInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata} */ ((inputs = {}, options = {}) => { + const locale = experimentalStaticLocale ?? options.locale ?? getLocale() + if (locale === "en") return en_version_removed_successfully(inputs) + return zh_version_removed_successfully(inputs) +}); \ No newline at end of file diff --git a/packages/webui/paraglide/messages/version_reordered_successfully.d.ts b/packages/webui/paraglide/messages/version_reordered_successfully.d.ts new file mode 100644 index 00000000..36440f64 --- /dev/null +++ b/packages/webui/paraglide/messages/version_reordered_successfully.d.ts @@ -0,0 +1,16 @@ +/** +* | output | +* | --- | +* | "Version order updated" | +* +* @param {Version_Reordered_SuccessfullyInputs} inputs +* @param {{ locale?: "en" | "zh" }} options +* @returns {LocalizedString} +*/ +export const version_reordered_successfully: ((inputs?: Version_Reordered_SuccessfullyInputs, options?: { + locale?: "en" | "zh"; +}) => LocalizedString) & import("../runtime.js").MessageMetadata; +export type LocalizedString = import("../runtime.js").LocalizedString; +export type Version_Reordered_SuccessfullyInputs = {}; diff --git a/packages/webui/paraglide/messages/version_reordered_successfully.js b/packages/webui/paraglide/messages/version_reordered_successfully.js new file mode 100644 index 00000000..561da563 --- /dev/null +++ b/packages/webui/paraglide/messages/version_reordered_successfully.js @@ -0,0 +1,29 @@ +/* eslint-disable */ +import { getLocale, experimentalStaticLocale } from '../runtime.js'; + +/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */ + +/** @typedef {{}} Version_Reordered_SuccessfullyInputs */ + +const en_version_reordered_successfully = /** @type {(inputs: Version_Reordered_SuccessfullyInputs) => LocalizedString} */ () => { + return /** @type {LocalizedString} */ (`Version order updated`) +}; + +const zh_version_reordered_successfully = /** @type {(inputs: Version_Reordered_SuccessfullyInputs) => LocalizedString} */ () => { + return /** @type {LocalizedString} */ (`版本顺序已更新`) +}; + +/** +* | output | +* | --- | +* | "Version order updated" | +* +* @param {Version_Reordered_SuccessfullyInputs} inputs +* @param {{ locale?: "en" | "zh" }} options +* @returns {LocalizedString} +*/ +export const version_reordered_successfully = /** @type {((inputs?: Version_Reordered_SuccessfullyInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata} */ ((inputs = {}, options = {}) => { + const locale = experimentalStaticLocale ?? options.locale ?? getLocale() + if (locale === "en") return en_version_reordered_successfully(inputs) + return zh_version_reordered_successfully(inputs) +}); \ No newline at end of file