mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-03 20:09:33 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - People use Tasks to see shared work and manage the work that needs their attention. > - The old inbox already let each person archive a task and undo that action. > - The combined Tasks surface needs the same controls in Unread and in task table rows. > - The existing inbox archive rules determine when new activity brings a task back. > - This pull request adds an Archived view so people can find and restore their archived tasks. ## Linked Issues or Issue Description **What existing behavior does this improve?** Personal task archiving in Tasks. Related work includes the combined Inbox and Tasks surface (#15100), the Coordinator workspace (#17983), moving Mine into Tasks (#19363), and the existing inbox archive rules (#9931). **Subsystem affected** Cross-cutting. The UI and task list API reuse the existing inbox archive state. **Current behavior** Mine has an archive action. Unread and the task table have no equivalent action. The Tasks menu has no dedicated view for restoring archived tasks. **Proposed behavior** Add Archive and Undo to the task views. Let people restore tasks from Archived. Keep archived tasks available in All tasks. **Reason and benefit** People can clear their personal lists and still find the original task. **Breaking changes** The task list API adds an optional archive filter and viewer archive field. Existing callers use the same response and filters unless they opt in. ## What Changed - Reuse the current inbox archive and restore actions, activity rules, and authorization. - Add Archive and Restore to task table rows, Archive and Undo to Unread, and a personal Archived view. - Give each archived task its own Undo control, including when people archive tasks quickly. - Add tests for the archive list, account isolation, new activity, row actions, and Undo. - Document the archive flow and API filter. Refresh the generated SDK source input registry. ## Verification - Passed 287 focused tests in 12 Vitest files. These cover the task views, row actions, archive cache, and PostgreSQL routes. - Passed local server and UI typechecks. The source input registry check also passed. - Reproduced a missing Undo action when archiving two tasks in a row. After the fix, the 158 task and inbox tests and the 2 toast tests passed. - On macOS with Chrome, archived a task from Mine and restored it using Undo. Archived another task from All tasks, reloaded Archived, restored it, and verified its Todo status and return to Mine. - A human tester also verified Archive, Undo, and Restore in the local browser. - On commit `c5526fd9b1`, GitHub's [verification](https://github.com/paperclipai/paperclip/actions/runs/44630156078/job/135950130662) and [browser tests](https://github.com/paperclipai/paperclip/actions/runs/44630156078/job/135946228919) passed. A targeted retry passed after the first attempt hit a watchdog self-test failure and two cancelled jobs. - [Greptile scored 5/5](https://github.com/paperclipai/paperclip/pull/22358#issuecomment-7024083610) on the same commit. Both review threads are resolved. ## Risks - An incorrect visibility rule could hide a task from a personal list. The archived filter uses the same activity predicate as Mine. The PostgreSQL test covers isolation between people and resurfacing after a reply. - The archive state is already stored per person and company. No database migration is required. ## Model Used - OpenAI Codex, GPT-6, with shell, code editing, and browser verification tools. The serving model ID and context size were unavailable in this session. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [x] All Paperclip CI gates are green - [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge --------- Co-authored-by: Scott Tong <1504818+scotttong@users.noreply.github.com> Co-authored-by: Paperclip <noreply@paperclip.ing>
96 lines
3.5 KiB
TypeScript
96 lines
3.5 KiB
TypeScript
import { useRef, useState } from "react";
|
|
import { useQueryClient } from "@tanstack/react-query";
|
|
import type { Issue } from "@paperclipai/shared";
|
|
import { describeError } from "@/api/errors";
|
|
import { issuesApi } from "@/api/issues";
|
|
import type { IssueRowArchiveAction } from "@/components/IssueRow";
|
|
import { useOptionalToastActions } from "@/context/ToastContext";
|
|
import { useAccountBoundMutation } from "@/hooks/useAccountBoundMutation";
|
|
import { bindAccount } from "@/lib/account-scope";
|
|
import {
|
|
beginLocalInboxArchive,
|
|
clearLocalInboxArchive,
|
|
confirmLocalInboxArchive,
|
|
invalidateTaskArchiveQueries,
|
|
} from "@/lib/inboxArchiveCache";
|
|
|
|
type ArchiveChange = { companyId: string; issueId: string; reference: string; archive: boolean; owner: string };
|
|
|
|
function changeKey({ companyId, issueId, owner }: ArchiveChange) {
|
|
return JSON.stringify([companyId, issueId, owner]);
|
|
}
|
|
|
|
export function useTaskArchiveAction(companyId: string | null, userId: string | null) {
|
|
const client = useQueryClient();
|
|
const toast = useOptionalToastActions();
|
|
const inFlight = useRef(new Set<string>());
|
|
const [pending, setPending] = useState<ReadonlySet<string>>(inFlight.current);
|
|
|
|
const change = useAccountBoundMutation({
|
|
mutationFn: ({ issueId, archive }: ArchiveChange) => archive
|
|
? issuesApi.archiveFromInbox(issueId)
|
|
: issuesApi.unarchiveFromInbox(issueId),
|
|
onMutate: ({ companyId, issueId, archive }) => archive
|
|
? { release: beginLocalInboxArchive(companyId, issueId), account: bindAccount(client) }
|
|
: undefined,
|
|
onSuccess: (_result, { companyId, issueId, archive }) => {
|
|
if (archive) confirmLocalInboxArchive(companyId, issueId);
|
|
else clearLocalInboxArchive(companyId, issueId);
|
|
},
|
|
onError: (error, { archive }, context) => {
|
|
context?.release();
|
|
toast?.pushToast({
|
|
title: archive ? "Archive failed" : "Restore failed",
|
|
body: describeError(error).body,
|
|
tone: "error",
|
|
});
|
|
},
|
|
onFinished: (_input, context) => {
|
|
if (context && !context.account.isCurrentScope()) context.release();
|
|
},
|
|
onSettled: (_result, _error, { companyId }) => invalidateTaskArchiveQueries(client, companyId),
|
|
});
|
|
|
|
async function submit(input: ArchiveChange) {
|
|
const key = changeKey(input);
|
|
if (inFlight.current.has(key)) return;
|
|
const account = bindAccount(client);
|
|
inFlight.current.add(key);
|
|
setPending(new Set(inFlight.current));
|
|
try {
|
|
await change.mutateAsync(input);
|
|
if (input.archive && account.isCurrentAccount()) {
|
|
toast?.pushToast({
|
|
id: `archive:${input.companyId}:${input.issueId}`,
|
|
dedupe: false,
|
|
title: "Task archived",
|
|
body: input.reference,
|
|
tone: "success",
|
|
ttlMs: 8000,
|
|
action: {
|
|
label: "Undo",
|
|
onClick: () => {
|
|
if (account.isCurrentAccount()) void submit({ ...input, archive: false });
|
|
},
|
|
},
|
|
});
|
|
}
|
|
} catch {
|
|
return;
|
|
} finally {
|
|
inFlight.current.delete(key);
|
|
setPending(new Set(inFlight.current));
|
|
}
|
|
}
|
|
|
|
return (issue: Issue): IssueRowArchiveAction | undefined => {
|
|
if (!companyId || !userId || issue.companyId !== companyId || issue.isArchivedForMe === undefined) return;
|
|
const input = { companyId, issueId: issue.id, reference: issue.identifier ?? issue.id, archive: !issue.isArchivedForMe, owner: userId };
|
|
return {
|
|
archived: issue.isArchivedForMe,
|
|
disabled: pending.has(changeKey(input)),
|
|
onClick: () => void submit(input),
|
|
};
|
|
};
|
|
}
|