mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-03 11:47:42 +01:00
## Thinking Path
> - Paperclip is the open source app people use to manage AI agents for
work
> - The Tasks page lists tasks and provides a Filters panel for status,
assignee, project, and other fields
> - The panel has no time filter, so users cannot limit the list to
tasks updated in a recent time window or date range
> - Users need a quick way to find recent work (such as the last 3 days)
or inspect a custom date range across both desktop and mobile views
> - This pull request supersedes #21822 on current `master` and adds an
"Updated" section to all Tasks filter panels (Any time, Last 24 hours,
Last 3 days, Last 7 days, Last 30 days, and Custom range), keeps the
filter in the URL, aligns "Last updated" display and sort with the
filter timestamp, and adds an optional `updatedBefore` server list bound
> - The benefit is that users can filter tasks by update time window and
share filtered links cleanly across all Tasks views
## Linked Issues or Issue Description
Refs #21822 (rebased onto current `master` with merge conflicts and
post-pruning test updates resolved).
**What existing behavior does this improve?**
The Tasks list filters (`CoordinatorTasks`, Classic `IssuesList`, and
`LegacyIssuesList`) and the company issue list API (`GET
/api/companies/:companyId/issues`). The Filters panel had status,
responsible, project, creator, and label filters, but no time filter.
**Subsystem affected**
UI (Tasks list filters, sorting, and URL sync) and Server (`GET
/api/companies/:companyId/issues`).
**Current behavior**
Users cannot limit the Tasks list to tasks updated within a recent time
window or custom date range. They must scan rows manually to find recent
activity.
**Proposed behavior**
Add an "Updated" section to the Tasks filter panels with options: Any
time (default), Last 24 hours, Last 3 days, Last 7 days, Last 30 days,
and Custom range (start and end local calendar day). Filter on the same
timestamp shown on each row (`lastActivityAt ?? lastExternalCommentAt ??
updatedAt`), count it as 1 active filter, reset it on Clear, persist it
in the page URL (`updated`, `updatedFrom`, `updatedTo`), and send an
optional `updatedBefore` upper bound to the server for custom ranges.
**Reason and benefit**
Users can narrow large task lists to recent work or a specific date
window in one click, including on phones, and share filtered URLs that
open with the same filter applied.
**Breaking changes**
None. The filter defaults to Any time, and `updatedBefore` is an
optional query parameter.
## What Changed
- `server/src/routes/issues.ts`, `server/src/services/issues.ts`,
`docs/api/issues.md`: add the optional `updatedBefore` query parameter
(`issues.updatedAt < updatedBefore`) with `400` validation matching
`updatedSince`, apply both `updatedSince` and `updatedBefore` in
`blockedInboxIssueConditions` so `attention=blocked` enforces the same
bounds, and document both parameters.
- `ui/src/api/issues.ts`: add optional `updatedBefore` to
`IssueListFilters` and `issueListSearchParams`.
- `ui/src/lib/issue-filters.ts`,
`ui/src/hooks/useIssueUpdatedFilterNow.ts`: add `updatedWithin`,
`updatedFrom`, and `updatedTo` to `IssueFilterState`, plus
`issueUpdatedWithinOptions`, `issueUpdatedWithinPatch`,
`issueUpdatedTime`, `issueUpdatedTimeRange`,
`nextIssueUpdatedFilterExpiryMs`, `issueUpdatedServerBefore`,
`readIssueUpdatedParams`, and `writeIssueUpdatedParams`. Reject
impossible calendar dates (such as `2026-02-31`), swap reversed custom
ranges, count Updated as 1 active filter, filter in `applyIssueFilters`
on the row time, and schedule a single deadline timer when a relative
window (`24h`/`3d`/`7d`/`30d`) is active so tasks age out automatically
across task and inbox lists.
- `ui/src/components/IssueUpdatedRangeInputs.tsx`,
`ui/src/components/IssueFilterPanel.tsx`,
`ui/src/components/IssueFiltersPopover.tsx`: add the "Updated" section
and native date inputs (`text-base md:text-xs` to prevent mobile Safari
focus zoom) across refreshed, streamlined, and legacy filter panels.
- `ui/src/components/IssueColumns.tsx`,
`ui/src/components/TaskList.tsx`, `ui/src/lib/issue-sort.ts`,
`DESIGN.md`: align `TaskList` "Last updated" display and sort with
`issueUpdatedTime`, compute each task's sort key once before sorting
(`O(N)` context reads), and update `DESIGN.md` to document the shared
timestamp rule.
- `ui/src/components/IssuesList.tsx`,
`ui/src/components/LegacyIssuesList.tsx`, `ui/src/pages/Issues.tsx`,
`ui/src/pages/CoordinatorTasks.tsx`: sync `updated`, `updatedFrom`, and
`updatedTo` with the page URL, queue multiple URL filter writes in the
same event so Clear resets filters together, pass `updatedBefore` for
custom ranges while preserving `archiveQueryScope` as the final
`issuesQuery.queryKey` segment for `placeholderData`, and forward
`updatedBefore` to `CoordinatorTasks` and `Issues` `searchFilters`.
- `server/src/__tests__/issue-list-updatedsince-filter-routes.test.ts`,
`ui/src/lib/issue-filters.test.ts`, `ui/src/lib/issue-sort.test.ts`,
`ui/src/lib/inbox.test.ts`,
`ui/src/components/IssueFiltersPopover.updated.test.tsx`: add
embedded-Postgres route tests for `updatedBefore` (strict bound,
combined range, `400` validation), unit tests for time windows/custom
ranges/local time zone/invalid dates/URL params/sort key caching, and
component tests across `legacy`, `streamlined`, and `refreshed` panels.
## Verification
- `pnpm --filter @paperclipai/server exec vitest run
src/__tests__/issue-list-updatedsince-filter-routes.test.ts`: **1 file,
6/6 tests pass** (embedded Postgres, including `attention=blocked` with
`updatedBefore` and `updatedSince`).
- `pnpm --filter @paperclipai/server typecheck`: **pass** (0 errors
across all server layers).
- `pnpm --filter @paperclipai/ui exec vitest run
src/lib/issue-filters.test.ts src/lib/issue-sort.test.ts
src/lib/inbox.test.ts
src/components/IssueFiltersPopover.updated.test.tsx
src/pages/Issues.test.tsx`: **5 files, 94/94 tests pass** (including
fake-timer relative window expiration and a 500-task bounded
timestamp-read render-cost test).
- `pnpm --filter @paperclipai/ui typecheck`: **pass** (0 errors,
Storybook catalog clean).
- `node scripts/check-token-gates.mjs`: **pass** (all 4 token gates
clean).
- `node scripts/check-test-budget.mjs --files
server/src/__tests__/issue-list-updatedsince-filter-routes.test.ts
ui/src/lib/issue-filters.test.ts ui/src/lib/issue-sort.test.ts
ui/src/lib/inbox.test.ts
ui/src/components/IssueFiltersPopover.updated.test.tsx`: **pass** (110
nightly suites validated, 5 test files checked).
- `pnpm verify --base 2d06567795
--explain`: exited `2` because `DESIGN.md` is a global CI input; focused
server and UI verification ran locally and full PR CI supplies repo-wide
coverage.
## Risks
- Low risk. The Updated filter is off by default (`Any time`), and
`updatedBefore` is optional.
- `IssueFiltersPopover` is shared by Inbox and agent work panels; those
views use `applyIssueFilters`, so the Updated section works consistently
there as well.
- The refreshed `TaskList` "Last updated" column now displays and sorts
by latest activity (`lastActivityAt ?? lastExternalCommentAt ??
updatedAt`), matching the Classic row and the Updated filter.
- Relative windows filter loaded pages in the browser (like other Tasks
filters); because the server sorts by update time descending, recent
tasks load first.
> For core feature work, check [`ROADMAP.md`](ROADMAP.md) first and
discuss it in `#dev` before opening the PR. Feature PRs that overlap
with planned core work may need to be redirected — check the roadmap
first. See `CONTRIBUTING.md`.
## Model Used
- Google Gemini (`gemini-3-pro` / Antigravity agentic coding environment
with tool use, shell execution, and embedded Postgres testing), building
on original work from #21822 authored with Anthropic Claude Opus 5.5
(`claude-opus-5-5`).
## 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: lucktastic <13757243+lucktastic@users.noreply.github.com>
Co-authored-by: Paperclip <noreply@paperclip.ing>
204 lines
12 KiB
TypeScript
204 lines
12 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, issueUpdatedTime } 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, updated: issueUpdatedTime(issue) };
|
|
});
|
|
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(issueUpdatedTime(issue)),
|
|
}}
|
|
/>
|
|
{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>
|
|
);
|
|
}
|