mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-25 16:14:26 +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>
204 lines
11 KiB
TypeScript
204 lines
11 KiB
TypeScript
import { Fragment, useId, useState, type ReactNode } from "react";
|
|
import type { Issue } from "@paperclipai/shared";
|
|
import { ChevronDown, ChevronRight, GitBranch } from "lucide-react";
|
|
import { buildIssueTree } from "../lib/issue-tree";
|
|
import { issueFilterLabel } from "../lib/issue-filters";
|
|
import { paperclipHumanAvatarUrl } from "../lib/issue-chat-human-author";
|
|
import { defaultTaskListColumns, defaultTaskListSort, isTaskListColumnSort, taskListOrderToIssueSort, type TaskListColumnId, type TaskListSort, type TaskListOrder } from "../lib/task-list";
|
|
import { sortIssues } from "../lib/issue-sort";
|
|
import { timeAgo } from "../lib/timeAgo";
|
|
import { IssueRow, type IssueRowArchiveAction, type IssueRowDensity } from "./IssueRow";
|
|
import { IssueGroupHeader } from "./IssueGroupHeader";
|
|
import { TaskListColumnHeader, TaskListColumnSettings, TaskListViewport } from "./TaskListColumns";
|
|
import { TaskRowGroup } from "./TaskRowGroup";
|
|
import { Badge } from "./ui/badge";
|
|
import { Button } from "./ui/button";
|
|
import { useTaskRowBudget } from "../hooks/useTaskRowBudget";
|
|
import { AgentAvatar, type AvatarAgent } from "./AgentAvatar";
|
|
import { deriveInitials } from "./Identity";
|
|
import { Avatar, AvatarFallback, AvatarImage } from "./ui/avatar";
|
|
import { useTaskListColumnPreferences } from "../hooks/useTaskListColumnPreferences";
|
|
import { usePreloadTaskChats } from "../hooks/usePreloadTaskChats";
|
|
import { CHAT_BOOTSTRAP_PRELOAD_LIMIT } from "../lib/issue-chat-bootstrap";
|
|
import type { TaskCollectionPreferenceLocation } from "../lib/task-collection-preferences";
|
|
|
|
export type TaskListItem = {
|
|
issue: Issue;
|
|
unread?: boolean;
|
|
createdBy?: string | null;
|
|
assignee?: string | null;
|
|
assigneeAgent?: AvatarAgent | null;
|
|
assigneeUserAvatarUrl?: string | null;
|
|
};
|
|
|
|
export type TaskListGrouping = "none" | "status" | "project";
|
|
|
|
/** Keep matching subtasks in their hierarchy without pulling in unrelated siblings. */
|
|
export function includeTaskListAncestors(items: readonly TaskListItem[], matches: readonly TaskListItem[]): TaskListItem[] {
|
|
const byId = new Map(items.map(item => [item.issue.id, item]));
|
|
const included = new Set<string>();
|
|
for (const match of matches) {
|
|
let item: TaskListItem | undefined = match;
|
|
while (item && !included.has(item.issue.id)) {
|
|
included.add(item.issue.id);
|
|
item = item.issue.parentId ? byId.get(item.issue.parentId) : undefined;
|
|
}
|
|
}
|
|
return items.filter(item => included.has(item.issue.id));
|
|
}
|
|
|
|
/**
|
|
* The route refs of the first `limit` rendered rows. Rows that are not
|
|
* rendered are skipped; no row after the last one returned is read.
|
|
*/
|
|
export function topRenderedTaskRefs(rows: Iterable<Pick<Issue, "id" | "identifier">>, rendered: ReadonlySet<string>, limit: number) {
|
|
const refs: string[] = [];
|
|
if (limit <= 0) return refs;
|
|
for (const issue of rows) {
|
|
if (!rendered.has(issue.id)) continue;
|
|
refs.push(issue.identifier ?? issue.id);
|
|
if (refs.length >= limit) break;
|
|
}
|
|
return refs;
|
|
}
|
|
|
|
/** Preloads the chats of a list's top rows. A component, so lists without it need no query client. */
|
|
function TaskChatPreload({ companyId, refs }: { companyId: string; refs: readonly string[] }) {
|
|
usePreloadTaskChats(companyId, refs, true);
|
|
return null;
|
|
}
|
|
|
|
/** Opt-in collection built from the reviewed row, hierarchy and column primitives. */
|
|
export function TaskList({ items, allItems = items, initialColumns = defaultTaskListColumns, density = "comfortable", collapsedIds, onCollapsedIdsChange, groupBy = "none", emptyState, issueLinkState, collectionKey, preferenceLocation, sort: controlledSort, onSortChange, preloadCompanyId, getArchiveAction }: {
|
|
items: readonly TaskListItem[];
|
|
allItems?: readonly TaskListItem[];
|
|
initialColumns?: readonly TaskListColumnId[];
|
|
density?: IssueRowDensity;
|
|
collapsedIds?: ReadonlySet<string>;
|
|
onCollapsedIdsChange?: (ids: ReadonlySet<string>) => void;
|
|
groupBy?: TaskListGrouping;
|
|
emptyState?: ReactNode;
|
|
issueLinkState?: unknown;
|
|
/** Company/person/view/filter identity; membership changes do not reset it. */
|
|
collectionKey?: string;
|
|
preferenceLocation?: TaskCollectionPreferenceLocation;
|
|
sort?: TaskListOrder;
|
|
onSortChange?: (sort: TaskListSort | undefined) => void;
|
|
/** Preload the chat of the top rows for this company. Only a page's main task list sets this. */
|
|
preloadCompanyId?: string | null;
|
|
getArchiveAction?: (issue: Issue) => IssueRowArchiveAction | undefined;
|
|
}) {
|
|
const localKey = useId();
|
|
const { columns, order: columnOrder, setColumns, setOrder: setColumnOrder } = useTaskListColumnPreferences(preferenceLocation, initialColumns);
|
|
const [localSort, setLocalSort] = useState<TaskListSort>();
|
|
const sort = controlledSort ?? (onSortChange ? undefined : localSort);
|
|
const setSort = (next: TaskListSort | undefined) => {
|
|
setLocalSort(next);
|
|
onSortChange?.(next);
|
|
};
|
|
const [localCollapsed, setLocalCollapsed] = useState<ReadonlySet<string>>(new Set());
|
|
const collapsed = collapsedIds ?? localCollapsed;
|
|
const setCollapsed = onCollapsedIdsChange ?? setLocalCollapsed;
|
|
const byId = new Map(allItems.map(item => [item.issue.id, item]));
|
|
const visibleById = new Map(items.map(item => [item.issue.id, item]));
|
|
const ordered = sortIssues(items.map(item => item.issue), taskListOrderToIssueSort(sort ?? defaultTaskListSort), issue => {
|
|
const item = byId.get(issue.id)!;
|
|
const parent = issue.parentId ? byId.get(issue.parentId)?.issue : null;
|
|
return { createdBy: item.createdBy, assignee: item.assignee, parentTask: parent ? `${parent.identifier} ${parent.title}` : null };
|
|
});
|
|
const { roots, childMap } = buildIssueTree(ordered);
|
|
const rowIds: string[] = [];
|
|
const collectRows = (issue: Issue) => {
|
|
rowIds.push(issue.id);
|
|
if (!collapsed.has(issue.id)) for (const child of childMap.get(issue.id) ?? []) collectRows(child);
|
|
};
|
|
roots.forEach(collectRows);
|
|
const { limit, hasMore, sentinel, loadMore } = useTaskRowBudget(rowIds, JSON.stringify([collectionKey ?? localKey, sort ?? defaultTaskListSort, groupBy]));
|
|
const renderedIds = new Set(rowIds.slice(0, limit));
|
|
const updateColumns = (next: readonly TaskListColumnId[]) => {
|
|
setColumns(next);
|
|
if (sort && isTaskListColumnSort(sort) && !next.includes(sort.column)) setSort(undefined);
|
|
};
|
|
const renderBranch = (issue: Issue, depth: number): ReactNode => {
|
|
if (!renderedIds.has(issue.id)) return null;
|
|
const item = visibleById.get(issue.id)!;
|
|
const children = childMap.get(issue.id) ?? [];
|
|
const expanded = !collapsed.has(issue.id);
|
|
const parent = issue.parentId ? byId.get(issue.parentId)?.issue : null;
|
|
const branch = issue.currentExecutionWorkspace?.branchName;
|
|
const assigneeName = item.assignee ?? (issue.assigneeAgentId ? "Unknown agent" : issue.assigneeUserId ? "User" : "Unassigned");
|
|
const assigneeUserAvatarUrl = paperclipHumanAvatarUrl(item.assigneeUserAvatarUrl);
|
|
return (
|
|
<Fragment key={issue.id}>
|
|
<IssueRow
|
|
issue={issue} presentation="task" appearance="refreshed" density={density} issueLinkState={issueLinkState}
|
|
archiveAction={getArchiveAction?.(issue)}
|
|
unreadState={item.unread ? "visible" : "hidden"}
|
|
treeGuides={depth} chevronInGuide={depth > 0 && children.length > 0}
|
|
leadingControl={children.length ? (
|
|
<Button variant="ghost" size="icon-xs" className="task-row-disclosure" aria-label={`${expanded ? "Collapse" : "Expand"} ${issue.title}`} aria-expanded={expanded} onClick={() => {
|
|
const next = new Set(collapsed);
|
|
if (next.has(issue.id)) next.delete(issue.id); else next.add(issue.id);
|
|
setCollapsed(next);
|
|
}}>{expanded ? <ChevronDown aria-hidden /> : <ChevronRight aria-hidden />}</Button>
|
|
) : undefined}
|
|
columnValues={{
|
|
createdBy: item.createdBy,
|
|
assignee: assigneeName,
|
|
assigneeAvatar: issue.assigneeAgentId ? (
|
|
<AgentAvatar agent={item.assigneeAgent ?? { id: issue.assigneeAgentId, name: assigneeName }} size={20} />
|
|
) : issue.assigneeUserId ? (
|
|
<Avatar size="xs" aria-hidden="true">
|
|
{assigneeUserAvatarUrl ? <AvatarImage src={assigneeUserAvatarUrl} alt="" /> : null}
|
|
<AvatarFallback>{deriveInitials(assigneeName)}</AvatarFallback>
|
|
</Avatar>
|
|
) : null,
|
|
project: issue.project?.name,
|
|
parentTask: parent ? <span><span className="font-mono">{parent.identifier}</span> {parent.title}</span> : undefined,
|
|
tags: issue.labels?.length ? <span className="inline-flex items-center gap-1">{issue.labels.map(label => <Badge key={label.id} variant="secondary" className="shrink-0 px-1.5 py-0">{label.name}</Badge>)}</span> : undefined,
|
|
worktree: branch ? <span className="inline-flex items-center gap-1.5"><GitBranch className="size-3 shrink-0" aria-hidden />{branch}</span> : undefined,
|
|
lastUpdated: timeAgo(issue.updatedAt),
|
|
}}
|
|
/>
|
|
{expanded ? children.map(child => renderBranch(child, depth + 1)) : null}
|
|
</Fragment>
|
|
);
|
|
};
|
|
const groups = new Map<string, Issue[]>();
|
|
for (const root of roots) {
|
|
const label = groupBy === "status" ? issueFilterLabel(root.status) : groupBy === "project" ? root.project?.name ?? "No project" : "";
|
|
groups.set(label, [...(groups.get(label) ?? []), root]);
|
|
}
|
|
// The top rendered rows, in display order. The walk is lazy: it stops after
|
|
// the preload limit, whatever the size of the list.
|
|
function* displayedRows(): Generator<Issue> {
|
|
function* branch(issue: Issue): Generator<Issue> {
|
|
yield issue;
|
|
if (!collapsed.has(issue.id)) for (const child of childMap.get(issue.id) ?? []) yield* branch(child);
|
|
}
|
|
for (const groupRoots of groups.values()) for (const root of groupRoots) yield* branch(root);
|
|
}
|
|
const preloadRefs = preloadCompanyId ? topRenderedTaskRefs(displayedRows(), renderedIds, CHAT_BOOTSTRAP_PRELOAD_LIMIT) : [];
|
|
return (
|
|
<TaskListViewport visibleColumns={columns} columnOrder={columnOrder} controls={<TaskListColumnSettings visibleColumns={columns} onVisibleColumnsChange={updateColumns} onColumnOrderChange={setColumnOrder} onResetDefaults={() => setSort(undefined)} />}>
|
|
<TaskListColumnHeader sort={sort && isTaskListColumnSort(sort) ? sort : undefined} onSortChange={setSort} onColumnOrderChange={setColumnOrder} />
|
|
{items.length === 0 ? emptyState : (
|
|
<div aria-label={`${density} task list`}>
|
|
{[...groups].map(([label, groupRoots]) => groupRoots.some(issue => renderedIds.has(issue.id)) ? (
|
|
<Fragment key={label}>
|
|
{label ? <IssueGroupHeader label={label} className="task-list-group-heading" trailing={<span className="text-xs text-muted-foreground">{groupRoots.length}</span>} /> : null}
|
|
{groupRoots.filter(issue => renderedIds.has(issue.id)).map(issue => <TaskRowGroup key={issue.id} role="rowgroup" aria-label={`${issue.title} task group`}
|
|
data-density={density} className={childMap.get(issue.id)?.length ? undefined : "task-row-deferred"}>{renderBranch(issue, 0)}</TaskRowGroup>)}
|
|
</Fragment>
|
|
) : null)}
|
|
</div>
|
|
)}
|
|
{hasMore ? <div ref={sentinel} className="flex items-center gap-3 py-2 text-sm text-muted-foreground">
|
|
<span>Rendering {Math.min(limit, rowIds.length)} of {rowIds.length} tasks</span>
|
|
<Button variant="outline" size="sm" onClick={loadMore}>Show more tasks</Button>
|
|
</div> : null}
|
|
{preloadCompanyId && preloadRefs.length ? <TaskChatPreload companyId={preloadCompanyId} refs={preloadRefs} /> : null}
|
|
</TaskListViewport>
|
|
);
|
|
}
|