Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

✨ feat(acceptance): file a delivery under a project from its row menu (#18537)

Arvin Xud0426c970a84
diff --git a/apps/server/src/routers/lambda/acceptance.ts b/apps/server/src/routers/lambda/acceptance.ts
index 64499e69da9..684ad67edaf 100644
--- a/apps/server/src/routers/lambda/acceptance.ts
+++ b/apps/server/src/routers/lambda/acceptance.ts
@@ -16,6 +16,7 @@ import {
wsCompatProcedure,
} from '@/business/server/trpc-middlewares/workspaceAuth';
import { AgentOperationModel } from '@/database/models/agentOperation';
+import { ProjectModel } from '@/database/models/project';
import { TaskModel } from '@/database/models/task';
import { VerifyReviewPredictionModel } from '@/database/models/verifyReviewPrediction';
import { VerifyRunModel } from '@/database/models/verifyRun';
@@ -825,6 +826,36 @@ export const acceptanceRouter = router({
});
}),
+ /**
+ * File the acceptance under a project (or take it out of one) from the list.
+ * Only the grouping pointer moves: the delivery, its rounds and its subject
+ * are untouched, so this is reversible and never rewrites history.
+ *
+ * The bar is READABLE, not manageable: a delivery may be filed under any
+ * project the caller can see — the same set the list already groups by — so
+ * a workspace member is not blocked from filing under a teammate's project.
+ */
+ setProject: acceptanceWriteProcedure
+ .input(z.object({ id: z.string(), projectId: z.string().nullable() }))
+ .mutation(async ({ ctx, input }) => {
+ const acceptance = await resolveAcceptance(ctx, input.id);
+ assertWorkspaceRowManageable(ctx, acceptance.userId, 'acceptance');
+
+ if (input.projectId) {
+ const project = await new ProjectModel(
+ ctx.serverDB,
+ ctx.userId,
+ ctx.workspaceId ?? undefined,
+ ).findById(input.projectId);
+ if (!project) throw new TRPCError({ code: 'NOT_FOUND', message: 'Project not found' });
+ }
+
+ await ctx.acceptanceService.acceptanceModel.update(acceptance.id, {
+ projectId: input.projectId,
+ });
+ return { success: true };
+ }),
+
/**
* Manually move the acceptance's user-facing lifecycle state from the list —
* an owner override (mark accepted / closed / rejected, or reopen for another look).
diff --git a/locales/en-US/verify.json b/locales/en-US/verify.json
index 381e70b93b2..3d2ba750c95 100644
--- a/locales/en-US/verify.json
+++ b/locales/en-US/verify.json
@@ -275,6 +275,17 @@
"acceptance.workspace.groups.viewProject": "View project",
"acceptance.workspace.listEmpty": "Ingest a verification report with the CLI and its acceptance will show up here.",
"acceptance.workspace.listEmptyTitle": "No acceptances yet",
+ "acceptance.workspace.project.add": "Add to project",
+ "acceptance.workspace.project.addSuccess": "Added to the project",
+ "acceptance.workspace.project.create": "New project with this delivery",
+ "acceptance.workspace.project.empty": "No projects yet",
+ "acceptance.workspace.project.error": "Failed to update the project",
+ "acceptance.workspace.project.loadError": "Couldn’t load your projects",
+ "acceptance.workspace.project.loading": "Loading projects…",
+ "acceptance.workspace.project.move": "Move to project",
+ "acceptance.workspace.project.moveSuccess": "Moved to the project",
+ "acceptance.workspace.project.remove": "Remove from project",
+ "acceptance.workspace.project.removeSuccess": "Removed from the project",
"acceptance.workspace.renameEmpty": "The title cannot be empty",
"acceptance.workspace.renameError": "Failed to rename",
"acceptance.workspace.renameSuccess": "Renamed",
diff --git a/locales/zh-CN/verify.json b/locales/zh-CN/verify.json
index 683a4c0af83..3e49fc75dc9 100644
--- a/locales/zh-CN/verify.json
+++ b/locales/zh-CN/verify.json
@@ -275,6 +275,17 @@
"acceptance.workspace.groups.viewProject": "查看项目",
"acceptance.workspace.listEmpty": "用 CLI ingest 一份验证报告后,对应的验收会出现在这里。",
"acceptance.workspace.listEmptyTitle": "还没有验收记录",
+ "acceptance.workspace.project.add": "添加到项目",
+ "acceptance.workspace.project.addSuccess": "已添加到项目",
+ "acceptance.workspace.project.create": "新建项目并添加",
+ "acceptance.workspace.project.empty": "还没有项目",
+ "acceptance.workspace.project.error": "更新项目失败",
+ "acceptance.workspace.project.loadError": "项目列表加载失败",
+ "acceptance.workspace.project.loading": "正在加载项目…",
+ "acceptance.workspace.project.move": "移动到项目",
+ "acceptance.workspace.project.moveSuccess": "已移动到该项目",
+ "acceptance.workspace.project.remove": "移出项目",
+ "acceptance.workspace.project.removeSuccess": "已移出项目",
"acceptance.workspace.renameEmpty": "标题不能为空",
"acceptance.workspace.renameError": "重命名失败",
"acceptance.workspace.renameSuccess": "已重命名",
diff --git a/packages/database/src/models/__tests__/acceptance.test.ts b/packages/database/src/models/__tests__/acceptance.test.ts
index ab6c4788c6b..e20b06076ba 100644
--- a/packages/database/src/models/__tests__/acceptance.test.ts
+++ b/packages/database/src/models/__tests__/acceptance.test.ts
@@ -84,6 +84,26 @@ describe('AcceptanceModel', () => {
expect((await model.findById(grouped.id))?.projectId).toBeNull();
});
+ it('files an acceptance under a project and takes it back out', async () => {
+ const projectModel = new ProjectModel(serverDB, userId);
+ const project = await projectModel.create({ identifier: 'MOVE', name: 'Move target' });
+ const model = new AcceptanceModel(serverDB, userId);
+ const acceptance = await model.ensureForSubject('topic', topicId);
+
+ await model.update(acceptance.id, { projectId: project.id });
+ expect((await model.findById(acceptance.id))?.projectId).toBe(project.id);
+
+ // Ungrouping is the same write with a null — the aggregate itself stays put.
+ await model.update(acceptance.id, { projectId: null });
+ expect((await model.findById(acceptance.id))?.projectId).toBeNull();
+
+ // Another user's model cannot re-file it: ownership scopes the update.
+ await new AcceptanceModel(serverDB, otherUserId).update(acceptance.id, {
+ projectId: project.id,
+ });
+ expect((await model.findById(acceptance.id))?.projectId).toBeNull();
+ });
+
it('keeps the first standalone display title and backfills one when initially absent', async () => {
const model = new AcceptanceModel(serverDB, userId);
const subjectId = 'standalone-external-delivery';
diff --git a/packages/database/src/models/acceptance.ts b/packages/database/src/models/acceptance.ts
index 292f6b51332..e85c556cc7a 100644
--- a/packages/database/src/models/acceptance.ts
+++ b/packages/database/src/models/acceptance.ts
@@ -168,7 +168,10 @@ export class AcceptanceModel {
update = async (
id: string,
value: Partial<
- Pick<NewAcceptance, 'config' | 'metadata' | 'requirement' | 'visibility' | 'visualRender'>
+ Pick<
+ NewAcceptance,
+ 'config' | 'metadata' | 'projectId' | 'requirement' | 'visibility' | 'visualRender'
+ >
>,
): Promise<AcceptanceItem | undefined> => {
const [row] = await this.db
diff --git a/packages/locales/src/default/verify.ts b/packages/locales/src/default/verify.ts
index d5c3905fa9f..aeaa5616d8b 100644
--- a/packages/locales/src/default/verify.ts
+++ b/packages/locales/src/default/verify.ts
@@ -310,6 +310,17 @@ export default {
'acceptance.workspace.listEmpty':
'Ingest a verification report with the CLI and its acceptance will show up here.',
'acceptance.workspace.listEmptyTitle': 'No acceptances yet',
+ 'acceptance.workspace.project.add': 'Add to project',
+ 'acceptance.workspace.project.addSuccess': 'Added to the project',
+ 'acceptance.workspace.project.create': 'New project with this delivery',
+ 'acceptance.workspace.project.empty': 'No projects yet',
+ 'acceptance.workspace.project.error': 'Failed to update the project',
+ 'acceptance.workspace.project.loadError': 'Couldn’t load your projects',
+ 'acceptance.workspace.project.loading': 'Loading projects…',
+ 'acceptance.workspace.project.move': 'Move to project',
+ 'acceptance.workspace.project.moveSuccess': 'Moved to the project',
+ 'acceptance.workspace.project.remove': 'Remove from project',
+ 'acceptance.workspace.project.removeSuccess': 'Removed from the project',
'acceptance.workspace.renameEmpty': 'The title cannot be empty',
'acceptance.workspace.renameError': 'Failed to rename',
'acceptance.workspace.renameSuccess': 'Renamed',
diff --git a/src/features/HomeSidebar/Body/Project/index.tsx b/src/features/HomeSidebar/Body/Project/index.tsx
index b688013c7bf..cf8c28dc08c 100644
--- a/src/features/HomeSidebar/Body/Project/index.tsx
+++ b/src/features/HomeSidebar/Body/Project/index.tsx
@@ -58,7 +58,7 @@ const Project = memo<ProjectProps>(({ itemKey }) => {
<NavItem
icon={PlusIcon}
title={t('sidebar.emptyAction')}
- onClick={openCreateProjectModal}
+ onClick={() => openCreateProjectModal()}
/>
) : (
projects.map((project) => <ProjectItem key={project.id} project={project} />)
diff --git a/src/features/Projects/CreateProjectModal.tsx b/src/features/Projects/CreateProjectModal.tsx
index bfd4c94b700..a12f82bc283 100644
--- a/src/features/Projects/CreateProjectModal.tsx
+++ b/src/features/Projects/CreateProjectModal.tsx
@@ -4,7 +4,7 @@ import { memo, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useWorkspaceAwareNavigate } from '@/features/Workspace/useWorkspaceAwareNavigate';
-import { useProjectStore } from '@/store/project';
+import { type ProjectListItem, useProjectStore } from '@/store/project';
import {
getCreateProjectInput,
@@ -13,6 +13,15 @@ import {
isProjectSlugValid,
} from './createProjectForm';
+interface CreateProjectOptions {
+ /**
+ * Handle the created project instead of opening it. Callers that create a
+ * project as a step of another action (filing a delivery under a new one)
+ * must not have the user navigated away from what they were doing.
+ */
+ onCreated?: (project: ProjectListItem) => void;
+}
+
interface CreateProjectFormState {
identifier: string;
identifierEdited: boolean;
@@ -28,7 +37,7 @@ const CreateProjectTitle = memo(() => {
return t('create.title');
});
-const CreateProjectContent = memo(() => {
+const CreateProjectContent = memo<CreateProjectOptions>(({ onCreated }) => {
const { t } = useTranslation(['project', 'common']);
const { close } = useModalContext();
const navigate = useWorkspaceAwareNavigate();
@@ -67,7 +76,8 @@ const CreateProjectContent = memo(() => {
try {
const project = await createProject(createInput);
close();
- navigate(`/project/${project.slug ?? project.id}`);
+ if (onCreated) onCreated(project);
+ else navigate(`/project/${project.slug ?? project.id}`);
} catch (error) {
console.error('Failed to create project', error);
toast.error(t('operationFailed', { ns: 'common' }));
@@ -144,9 +154,9 @@ const CreateProjectContent = memo(() => {
);
});
-export const openCreateProjectModal = () =>
+export const openCreateProjectModal = (options: CreateProjectOptions = {}) =>
createModal({
- content: <CreateProjectContent />,
+ content: <CreateProjectContent {...options} />,
footer: null,
styles: { content: { padding: 0 } },
title: <CreateProjectTitle />,
diff --git a/src/features/Projects/List/index.tsx b/src/features/Projects/List/index.tsx
index 935599a2fb9..ff877a67156 100644
--- a/src/features/Projects/List/index.tsx
+++ b/src/features/Projects/List/index.tsx
@@ -232,7 +232,7 @@ const ProjectListPage = memo(() => {
value={keyword}
onChange={(event) => setKeyword(event.target.value)}
/>
- <Button icon={PlusIcon} onClick={openCreateProjectModal}>
+ <Button icon={PlusIcon} onClick={() => openCreateProjectModal()}>
{t('create.action')}
</Button>
</Flexbox>
diff --git a/src/features/Verify/Acceptance/Workspace/AcceptanceListPanel.tsx b/src/features/Verify/Acceptance/Workspace/AcceptanceListPanel.tsx
index af8250f886e..cdb17ff3552 100644
--- a/src/features/Verify/Acceptance/Workspace/AcceptanceListPanel.tsx
+++ b/src/features/Verify/Acceptance/Workspace/AcceptanceListPanel.tsx
@@ -47,7 +47,12 @@ import {
normalizeAcceptanceListFilter,
} from './acceptanceListFilter';
import AcceptanceRow from './AcceptanceRow';
-import { groupAcceptanceList, hasProjectAcceptanceGroups } from './groupAcceptanceList';
+import {
+ expandedAcceptanceGroupKeys,
+ groupAcceptanceList,
+ hasProjectAcceptanceGroups,
+ nextCollapsedGroupKeys,
+} from './groupAcceptanceList';
const PANEL_MIN = 260;
const PANEL_MAX = 420;
@@ -250,6 +255,9 @@ const AcceptanceListPanel = memo<AcceptanceListPanelProps>(
ACCEPTANCE_LIST_FILTER_STORAGE_KEY,
DEFAULT_ACCEPTANCE_LIST_FILTER,
);
+ // Collapsed (not expanded) is the tracked set: a group that appears after
+ // mount — the project a delivery was just filed into — must come in open.
+ const [collapsedGroups, setCollapsedGroups] = useState<string[]>([]);
const filter = normalizeAcceptanceListFilter(storedFilter);
const filtered = filterAcceptanceList(data ?? [], filter, query);
const groups = groupAcceptanceList(filtered);
@@ -400,7 +408,15 @@ const AcceptanceListPanel = memo<AcceptanceListPanelProps>(
) : (
<div className={styles.list}>
{showGroups ? (
- <Accordion defaultExpandedKeys={groups.map(({ key }) => key)} gap={4}>
+ <Accordion
+ expandedKeys={expandedAcceptanceGroupKeys(groups, collapsedGroups)}
+ gap={4}
+ onExpandedChange={(keys) =>
+ setCollapsedGroups((previous) =>
+ nextCollapsedGroupKeys(previous, groups, keys.map(String)),
+ )
+ }
+ >
{groups.map((group) => (
<AccordionItem
action={renderProjectActions?.(group.projectName ? group.key : undefined)}
diff --git a/src/features/Verify/Acceptance/Workspace/AcceptanceProjectActions.tsx b/src/features/Verify/Acceptance/Workspace/AcceptanceProjectActions.tsx
index a8b65b1ea85..b01b10f591a 100644
--- a/src/features/Verify/Acceptance/Workspace/AcceptanceProjectActions.tsx
+++ b/src/features/Verify/Acceptance/Workspace/AcceptanceProjectActions.tsx
@@ -35,7 +35,7 @@ const AcceptanceProjectActions = memo<AcceptanceProjectActionsProps>(({ projectI
icon: <Icon icon={Plus} />,
key: action,
label: t('acceptance.workspace.groups.createProject'),
- onClick: openCreateProjectModal,
+ onClick: () => openCreateProjectModal(),
};
});
diff --git a/src/features/Verify/Acceptance/Workspace/AcceptanceRow.tsx b/src/features/Verify/Acceptance/Workspace/AcceptanceRow.tsx
index d2fff20fb25..b2e41fe5ecc 100644
--- a/src/features/Verify/Acceptance/Workspace/AcceptanceRow.tsx
+++ b/src/features/Verify/Acceptance/Workspace/AcceptanceRow.tsx
@@ -31,6 +31,7 @@ import type { AcceptanceListItem } from '@/services/verify';
import { verifyService } from '@/services/verify';
import { getAcceptanceStatusActions } from '../statusActions';
+import { useAcceptanceProjectMenuItem } from './useAcceptanceProjectMenuItem';
const styles = createStaticStyles(({ css }) => ({
editRow: css`
@@ -187,6 +188,33 @@ const AcceptanceRow = memo<{
}
};
+ const assignProject = async (projectId: string | null) => {
+ setMutating(true);
+ try {
+ await verifyService.setAcceptanceProject(item.id, projectId);
+ await refresh();
+ toast.success(
+ projectId
+ ? t(
+ item.project?.id
+ ? 'acceptance.workspace.project.moveSuccess'
+ : 'acceptance.workspace.project.addSuccess',
+ )
+ : t('acceptance.workspace.project.removeSuccess'),
+ );
+ } catch (error) {
+ console.error('[acceptance:project]', error);
+ toast.error(t('acceptance.workspace.project.error'));
+ } finally {
+ setMutating(false);
+ }
+ };
+
+ const projectItem = useAcceptanceProjectMenuItem({
+ currentProjectId: item.project?.id,
+ onSelect: (projectId) => void assignProject(projectId),
+ });
+
const removeAcceptance = () => {
confirmModal({
cancelText: t('actions.cancel'),
@@ -243,6 +271,7 @@ const AcceptanceRow = memo<{
label: t('acceptance.workspace.actions.rename'),
onClick: startRename,
},
+ projectItem,
...(statusItems.length > 0
? [
{
diff --git a/src/features/Verify/Acceptance/Workspace/acceptanceProjectOptions.test.ts b/src/features/Verify/Acceptance/Workspace/acceptanceProjectOptions.test.ts
new file mode 100644
index 00000000000..6e9ea0aebc0
--- /dev/null
+++ b/src/features/Verify/Acceptance/Workspace/acceptanceProjectOptions.test.ts
@@ -0,0 +1,41 @@
+import { describe, expect, it } from 'vitest';
+
+import { buildAcceptanceProjectMenuState } from './acceptanceProjectOptions';
+
+const projects = [
+ { id: 'p1', name: 'Recycle bin' },
+ { id: 'p2', name: 'Acceptance' },
+];
+
+describe('buildAcceptanceProjectMenuState', () => {
+ it('reports a failed fetch as an error, never as "no projects"', () => {
+ expect(buildAcceptanceProjectMenuState({ error: new Error('offline'), projects: [] })).toEqual({
+ type: 'error',
+ });
+ });
+
+ it('waits while the projects have not arrived yet', () => {
+ expect(buildAcceptanceProjectMenuState({})).toEqual({ type: 'loading' });
+ });
+
+ it('distinguishes an empty project list from a pending one', () => {
+ expect(buildAcceptanceProjectMenuState({ projects: [] })).toEqual({ type: 'empty' });
+ });
+
+ it('marks the project the acceptance is already filed under', () => {
+ expect(buildAcceptanceProjectMenuState({ currentProjectId: 'p2', projects })).toEqual({
+ options: [
+ { id: 'p1', name: 'Recycle bin', selected: false },
+ { id: 'p2', name: 'Acceptance', selected: true },
+ ],
+ type: 'options',
+ });
+ });
+
+ it('selects nothing for an ungrouped acceptance', () => {
+ const state = buildAcceptanceProjectMenuState({ currentProjectId: null, projects });
+
+ expect(state.type).toBe('options');
+ expect(state.type === 'options' && state.options.every(({ selected }) => !selected)).toBe(true);
+ });
+});
diff --git a/src/features/Verify/Acceptance/Workspace/acceptanceProjectOptions.ts b/src/features/Verify/Acceptance/Workspace/acceptanceProjectOptions.ts
new file mode 100644
index 00000000000..b4ca0ad098f
--- /dev/null
+++ b/src/features/Verify/Acceptance/Workspace/acceptanceProjectOptions.ts
@@ -0,0 +1,47 @@
+import type { ProjectListItem } from '@/store/project';
+
+export interface AcceptanceProjectOption {
+ id: string;
+ name: string;
+ /** The project the acceptance is currently filed under. */
+ selected: boolean;
+}
+
+/**
+ * What the "file under a project" submenu shows for the state its project
+ * fetch is in. Kept as data (not JSX) so the branch order — error before
+ * loading, loading before empty — is testable without rendering a menu.
+ *
+ * Every state still offers "create a project", so the empty one is a starting
+ * point rather than a dead end.
+ */
+export type AcceptanceProjectMenuState =
+ | { type: 'error' }
+ | { type: 'loading' }
+ | { type: 'empty' }
+ | { options: AcceptanceProjectOption[]; type: 'options' };
+
+export const buildAcceptanceProjectMenuState = ({
+ currentProjectId,
+ error,
+ projects,
+}: {
+ currentProjectId?: string | null;
+ error?: unknown;
+ projects?: Pick<ProjectListItem, 'id' | 'name'>[];
+}): AcceptanceProjectMenuState => {
+ // A failed fetch must never read as "you have no projects" — that would
+ // invite the user to create a duplicate of one they already own.
+ if (error) return { type: 'error' };
+ if (!projects) return { type: 'loading' };
+ if (projects.length === 0) return { type: 'empty' };
+
+ return {
+ options: projects.map(({ id, name }) => ({
+ id,
+ name,
+ selected: id === currentProjectId,
+ })),
+ type: 'options',
+ };
+};
diff --git a/src/features/Verify/Acceptance/Workspace/groupAcceptanceList.test.ts b/src/features/Verify/Acceptance/Workspace/groupAcceptanceList.test.ts
index 2ebe6333f39..4c9d5eac3c1 100644
--- a/src/features/Verify/Acceptance/Workspace/groupAcceptanceList.test.ts
+++ b/src/features/Verify/Acceptance/Workspace/groupAcceptanceList.test.ts
@@ -2,7 +2,12 @@ import { describe, expect, it } from 'vitest';
import type { AcceptanceListItem } from '@/services/verify';
-import { groupAcceptanceList, hasProjectAcceptanceGroups } from './groupAcceptanceList';
+import {
+ expandedAcceptanceGroupKeys,
+ groupAcceptanceList,
+ hasProjectAcceptanceGroups,
+ nextCollapsedGroupKeys,
+} from './groupAcceptanceList';
const item = (id: string, project: { id: string; name: string } | null): AcceptanceListItem =>
({ id, project }) as AcceptanceListItem;
@@ -32,4 +37,45 @@ describe('groupAcceptanceList', () => {
),
).toBe(true);
});
+
+ it('keeps a group that appears after mount expanded, and remembers manual collapses', () => {
+ const groups = groupAcceptanceList([
+ item('one', { id: 'p1', name: 'Alpha' }),
+ item('two', { id: 'p2', name: 'Beta' }),
+ ]);
+
+ expect(expandedAcceptanceGroupKeys(groups, [])).toEqual(['p1', 'p2']);
+ expect(expandedAcceptanceGroupKeys(groups, ['p1'])).toEqual(['p2']);
+
+ // A delivery filed into a brand-new project adds a group the user has never
+ // seen: it must come in expanded, or the row they just moved vanishes.
+ const withNewGroup = groupAcceptanceList([
+ item('one', { id: 'p1', name: 'Alpha' }),
+ item('two', { id: 'p2', name: 'Beta' }),
+ item('three', { id: 'p3', name: 'Gamma' }),
+ ]);
+
+ expect(expandedAcceptanceGroupKeys(withNewGroup, ['p1'])).toEqual(['p2', 'p3']);
+ });
+
+ it('keeps a collapsed group that the active filter hides out of view', () => {
+ const all = groupAcceptanceList([
+ item('one', { id: 'p1', name: 'Alpha' }),
+ item('two', { id: 'p2', name: 'Beta' }),
+ ]);
+ // The user collapses Alpha while both groups are listed.
+ const collapsed = nextCollapsedGroupKeys([], all, ['p2']);
+ expect(collapsed).toEqual(['p1']);
+
+ // A search now hides Alpha entirely; toggling Beta must not forget Alpha.
+ const filtered = groupAcceptanceList([item('two', { id: 'p2', name: 'Beta' })]);
+ const afterToggle = nextCollapsedGroupKeys(collapsed, filtered, []);
+ expect(afterToggle).toEqual(['p1', 'p2']);
+
+ // Clearing the search brings Alpha back — still collapsed, as the user left it.
+ expect(expandedAcceptanceGroupKeys(all, afterToggle)).toEqual([]);
+ expect(
+ expandedAcceptanceGroupKeys(all, nextCollapsedGroupKeys(afterToggle, filtered, ['p2'])),
+ ).toEqual(['p2']);
+ });
});
diff --git a/src/features/Verify/Acceptance/Workspace/groupAcceptanceList.ts b/src/features/Verify/Acceptance/Workspace/groupAcceptanceList.ts
index 573bef9ef2e..1785b9a42bb 100644
--- a/src/features/Verify/Acceptance/Workspace/groupAcceptanceList.ts
+++ b/src/features/Verify/Acceptance/Workspace/groupAcceptanceList.ts
@@ -35,3 +35,36 @@ export const groupAcceptanceList = (items: AcceptanceListItem[]): AcceptanceList
export const hasProjectAcceptanceGroups = (groups: AcceptanceListGroup[]) =>
groups.some(({ projectName }) => projectName !== null);
+
+/**
+ * Which groups the accordion shows open. Expressed as "everything except what
+ * the user collapsed" on purpose: a group that appears AFTER mount — the one
+ * the user just filed a delivery into — must be open, or the row they moved
+ * silently disappears behind a collapsed header.
+ */
+export const expandedAcceptanceGroupKeys = (
+ groups: AcceptanceListGroup[],
+ collapsedKeys: string[],
+) => groups.map(({ key }) => key).filter((key) => !collapsedKeys.includes(key));
+
+/**
+ * Fold an accordion change back into the collapsed set.
+ *
+ * Only the groups the list is currently showing can be reported by the
+ * accordion, so a group hidden behind the active filter/search keeps whatever
+ * the user last chose for it. Rebuilding the set from the visible groups alone
+ * would silently re-open it the moment the filter is cleared.
+ */
+export const nextCollapsedGroupKeys = (
+ previousCollapsed: string[],
+ groups: AcceptanceListGroup[],
+ expandedKeys: string[],
+) => {
+ const visible = new Set(groups.map(({ key }) => key));
+ const expanded = new Set(expandedKeys);
+
+ return [
+ ...previousCollapsed.filter((key) => !visible.has(key)),
+ ...groups.map(({ key }) => key).filter((key) => !expanded.has(key)),
+ ];
+};
diff --git a/src/features/Verify/Acceptance/Workspace/useAcceptanceProjectMenuItem.tsx b/src/features/Verify/Acceptance/Workspace/useAcceptanceProjectMenuItem.tsx
new file mode 100644
index 00000000000..d9d3cbbbdff
--- /dev/null
+++ b/src/features/Verify/Acceptance/Workspace/useAcceptanceProjectMenuItem.tsx
@@ -0,0 +1,122 @@
+'use client';
+
+import type { DropdownItem } from '@lobehub/ui/base-ui';
+import Icon from '@lobehub/ui/es/Icon/index';
+import { Check, FolderInput, FolderMinus, FolderPlus } from 'lucide-react';
+import { useState } from 'react';
+import { useTranslation } from 'react-i18next';
+
+import { openCreateProjectModal } from '@/features/Projects/CreateProjectModal';
+import { mutate, useClientDataSWR } from '@/libs/swr';
+import { projectService } from '@/services/project';
+
+import { buildAcceptanceProjectMenuState } from './acceptanceProjectOptions';
+
+/**
+ * Read and invalidation go through the same pair on purpose: `useClientDataSWR`
+ * and the scoped `mutate` both run the key through `augmentKey`, so workspace
+ * scoping stays symmetric. Plain `swr`'s global mutate cannot reach this cache
+ * at all (the app installs a custom provider), and hand-scoping the key here
+ * would double-augment it.
+ */
+const PROJECT_OPTIONS_KEY = ['acceptance:projectOptions'];
+
+interface AcceptanceProjectMenuItemParams {
+ /** The project the acceptance is filed under, if any. */
+ currentProjectId?: string | null;
+ /** `null` takes the acceptance out of its project. */
+ onSelect: (projectId: string | null) => void;
+}
+
+/**
+ * The "file this delivery under a project" submenu on an acceptance row.
+ *
+ * The projects are fetched the first time the submenu opens, not on row mount:
+ * a list of 50 rows must not fire a project read nobody asked for.
+ *
+ * Creating a project is offered from inside the submenu — it is the only way
+ * out of the empty state, and the newly created project immediately receives
+ * this delivery instead of navigating the user away from their list.
+ *
+ * The caller owns the write (and its toast); this hook only decides what the
+ * menu offers.
+ */
+export const useAcceptanceProjectMenuItem = ({
+ currentProjectId,
+ onSelect,
+}: AcceptanceProjectMenuItemParams): DropdownItem => {
+ const { t } = useTranslation('verify');
+ const [requested, setRequested] = useState(false);
+
+ const { data, error } = useClientDataSWR(
+ requested ? PROJECT_OPTIONS_KEY : null,
+ () => projectService.listAll(),
+ { revalidateOnFocus: false },
+ );
+
+ const state = buildAcceptanceProjectMenuState({
+ currentProjectId,
+ error,
+ projects: data?.data,
+ });
+
+ const placeholder = (key: string, label: string): DropdownItem[] => [
+ { disabled: true, key, label },
+ ];
+
+ const listItems: DropdownItem[] =
+ state.type === 'error'
+ ? placeholder('error', t('acceptance.workspace.project.loadError'))
+ : state.type === 'loading'
+ ? placeholder('loading', t('acceptance.workspace.project.loading'))
+ : state.type === 'empty'
+ ? placeholder('empty', t('acceptance.workspace.project.empty'))
+ : state.options.map(({ id, name, selected }) => ({
+ icon: <Icon icon={Check} style={{ opacity: selected ? 1 : 0 }} />,
+ key: id,
+ label: name,
+ onClick: () => {
+ if (selected) return;
+ onSelect(id);
+ },
+ }));
+
+ const createItem: DropdownItem = {
+ icon: <Icon icon={FolderPlus} />,
+ key: 'create',
+ label: t('acceptance.workspace.project.create'),
+ onClick: () =>
+ openCreateProjectModal({
+ onCreated: (project) => {
+ // This row's submenu is already subscribed, so nothing refetches it
+ // on the next open — the new project has to be pushed into the cache.
+ void mutate(PROJECT_OPTIONS_KEY);
+ onSelect(project.id);
+ },
+ }),
+ };
+
+ const removeItem: DropdownItem = {
+ icon: <Icon icon={FolderMinus} />,
+ key: 'remove',
+ label: t('acceptance.workspace.project.remove'),
+ onClick: () => onSelect(null),
+ };
+
+ return {
+ children: [
+ ...listItems,
+ { type: 'divider' },
+ createItem,
+ ...(currentProjectId ? [removeItem] : []),
+ ],
+ icon: <Icon icon={FolderInput} />,
+ key: 'project',
+ label: currentProjectId
+ ? t('acceptance.workspace.project.move')
+ : t('acceptance.workspace.project.add'),
+ onOpenChange: (open) => {
+ if (open) setRequested(true);
+ },
+ };
+};
diff --git a/src/services/verify.ts b/src/services/verify.ts
index 70d9e739201..cf74422ada4 100644
--- a/src/services/verify.ts
+++ b/src/services/verify.ts
@@ -262,6 +262,13 @@ export class VerifyService {
renameAcceptance = (id: string, title: string) =>
lambdaClient.acceptance.rename.mutate({ id, title });
+ /**
+ * File the acceptance under a project (`null` takes it out of one). Only the
+ * grouping moves — the delivery and its rounds stay exactly where they are.
+ */
+ setAcceptanceProject = (id: string, projectId: string | null) =>
+ lambdaClient.acceptance.setProject.mutate({ id, projectId });
+
/** Owner override of the acceptance's decision state from the list. */
updateAcceptanceStatus = (id: string, status: 'accepted' | 'closed' | 'delivered' | 'rejected') =>
lambdaClient.acceptance.updateStatus.mutate({ id, status });