Files
PaperClipAI/ui/src/lib/task-views.ts
T
19a7381398 feat: restore personal archiving in task views (#22358)
## 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>
2026-11-19 16:22:07 -08:00

159 lines
5.7 KiB
TypeScript

import type { InboxTab } from "./inbox";
/**
* The single view registry behind the merged Tasks surface (PAP-670).
*
* Inbox stopped being its own nav row and its five tabs became views inside
* Tasks, alongside the status presets that used to live only inside the task
* list's filter popover. Every view is addressed as `/issues?view=<key>`.
*
* Each view declares which surface renders it:
* - `inbox` — the attention-ordered inbox list (unread state, archive,
* date groups, mixed approval/failed-run/join-request rows).
* - `issues` — the task collection list (board/list modes, filters, columns).
*
* Views are *not* reimplemented on the other surface: pointing a view at the
* component that already owns those behaviours is what keeps them intact.
*/
export const TASK_VIEW_KEYS = [
"mine",
"unread",
"blocked",
"recent",
"everything",
"archived",
"needs_attention",
"all",
"active",
"backlog",
"done",
] as const;
export type TaskViewKey = (typeof TASK_VIEW_KEYS)[number];
export type TaskViewSurface = "inbox" | "issues";
export interface TaskView {
key: TaskViewKey;
label: string;
surface: TaskViewSurface;
/** Which inbox tab renders this view (`inbox` surface only). */
inboxTab?: InboxTab;
/** Status filter applied on entry (`issues` surface only). */
statuses?: string[];
/** One-line description shown in the Views menu. */
hint: string;
coordinatorOnly?: boolean;
}
export interface TaskViewGroup {
label: string;
views: TaskView[];
}
export const TASK_VIEW_GROUPS: TaskViewGroup[] = [
{
label: "My work",
views: [
{ key: "mine", label: "Mine", surface: "inbox", inboxTab: "mine", hint: "Assigned to you or waiting on you" },
{ key: "unread", label: "Unread", surface: "inbox", inboxTab: "unread", hint: "Tasks you touched with new activity" },
{ key: "blocked", label: "Blocked", surface: "inbox", inboxTab: "blocked", hint: "Blocked tasks, grouped by blocker" },
{ key: "recent", label: "Recent", surface: "inbox", inboxTab: "recent", hint: "Everything you touched lately" },
{ key: "everything", label: "Everything", surface: "inbox", inboxTab: "all", hint: "Tasks, approvals, failed runs and join requests" },
{ key: "archived", label: "Archived", surface: "issues", statuses: [], hint: "Tasks archived for you" },
],
},
{
label: "Organization",
views: [
{ key: "needs_attention", label: "Needs attention", surface: "issues", statuses: [], hint: "Tasks with pending decisions", coordinatorOnly: true },
{ key: "all", label: "All tasks", surface: "issues", statuses: [], hint: "Every task in the organization" },
{ key: "active", label: "Active", surface: "issues", statuses: ["todo", "in_progress", "monitoring", "in_review", "blocked"], hint: "Open tasks, running or not" },
{ key: "backlog", label: "Backlog", surface: "issues", statuses: ["backlog"], hint: "Not started yet" },
{ key: "done", label: "Done", surface: "issues", statuses: ["done", "cancelled"], hint: "Completed and cancelled" },
],
},
];
const VIEWS_BY_KEY = new Map<TaskViewKey, TaskView>(
TASK_VIEW_GROUPS.flatMap((group) => group.views.map((view) => [view.key, view] as const)),
);
export const DEFAULT_TASK_VIEW: TaskViewKey = "all";
export const TASK_VIEW_PARAM = "view";
export const TASK_LAST_VIEW_KEY = "paperclip:tasks:last-view";
export function isTaskViewKey(value: unknown): value is TaskViewKey {
return typeof value === "string" && VIEWS_BY_KEY.has(value as TaskViewKey);
}
export function taskView(key: TaskViewKey): TaskView {
return VIEWS_BY_KEY.get(key)!;
}
/** Resolves a `?view=` value, falling back to `null` so callers can pick a default. */
export function normalizeTaskViewKey(value: string | null | undefined): TaskViewKey | null {
return isTaskViewKey(value) ? value : null;
}
export function taskViewPath(key: TaskViewKey): string {
return `/issues?${TASK_VIEW_PARAM}=${key}`;
}
/** Inbox tab → view key, for redirecting the retired `/inbox/*` URLs. */
const VIEW_BY_INBOX_TAB: Record<InboxTab, TaskViewKey> = {
mine: "mine",
unread: "unread",
blocked: "blocked",
recent: "recent",
all: "everything",
};
export function taskViewForInboxTab(tab: string | null | undefined): TaskViewKey {
return (tab && tab in VIEW_BY_INBOX_TAB)
? VIEW_BY_INBOX_TAB[tab as InboxTab]
: DEFAULT_TASK_VIEW;
}
export function loadLastTaskView(): TaskViewKey {
try {
return normalizeTaskViewKey(window.localStorage.getItem(TASK_LAST_VIEW_KEY)) ?? DEFAULT_TASK_VIEW;
} catch {
return DEFAULT_TASK_VIEW;
}
}
export function saveLastTaskView(key: TaskViewKey): void {
try {
window.localStorage.setItem(TASK_LAST_VIEW_KEY, key);
} catch {
/* Navigation still works without storage; the default view just returns. */
}
}
/**
* Query params that only the organization task list understands. A deep link
* carrying one of these (the dashboard's "assigned to me", a workspace
* drill-in, a search hand-off) must not land on a My-work view, so it resolves
* to `All tasks` instead of the user's last-used view.
*/
export const ORGANIZATION_SCOPED_PARAMS = [
"assignee",
"workspace",
"participantAgentId",
"originKind",
"q",
] as const;
/** Resolves which view a `/issues` visit opens. */
export function resolveInitialTaskView(
requested: string | null,
hasOrganizationScopedParam: boolean,
lastUsed: TaskViewKey,
): TaskViewKey {
const explicit = normalizeTaskViewKey(requested);
// Inbox views can't apply organization filters, so a link carrying one
// opens All tasks rather than silently dropping the filter.
if (hasOrganizationScopedParam && (!explicit || taskView(explicit).surface === "inbox")) return "all";
return explicit ?? lastUsed;
}