Files
PaperClipAI/ui/src/lib/task-views.ts
T
f8cb4957dc fix(ui): default Tasks to All tasks with a neutral sort header (#19393)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work.
> - The Tasks page helps people inspect work across their company.
> - A new viewer currently starts in Mine and can miss other company
tasks.
> - The task table also shows an active sort header before the viewer
selects a sort.
> - This pull request starts new viewers in All tasks and keeps the
default sort header neutral.
> - People see company work in newest-update order and keep their saved
view choices.

## Linked Issues or Issue Description

**What existing behavior does this improve?**

The initial task view and the task table's default sort state.

**Subsystem affected**

ui/ — React board UI.

**Current behavior**

Tasks opens Mine when the viewer has no saved view. The table highlights
Last updated even when the viewer has not selected a column sort.

**Proposed behavior**

Tasks opens All tasks when no saved view exists. The table keeps
newest-updated tasks first without an active header or arrow. A column
selection or an explicit sort URL activates the selected header.

**Reason and benefit**

New viewers can inspect company work immediately. The header
distinguishes default ordering from an explicit sort choice.

**Breaking changes**

The first-visit view changes from Mine to All tasks. Saved views and
explicit view URLs keep priority. Existing Inbox and Needs attention
preferences retain their meaning. The change does not alter task access
or database contracts.

**Additional context**

Refs #19363. This change builds on the grouped task menu from that
merged pull request. It uses the existing menu and design tokens.

## What Changed

- Default the Coordinator and combined task surfaces to All tasks.
- Preserve saved personal views and migrate previous picker choices.
- Keep implicit Last updated descending order separate from active
header state.
- Test default ordering, explicit sorting, reset behavior, view
selection, and preference migration.
- Update the product and implementation docs.

## Verification

- Passed 118 focused tests across task routing, table sorting, views,
and collection preferences.
- Passed `pnpm check:token-gates`, `pnpm -r typecheck`, and `pnpm
build`.
- Full `pnpm test:run` is running. Its result will be updated here.
- Greptile passed the current head with 5/5 and no findings or open
review threads.
- Browser check: All tasks uses the grouped My work and Organization
menu. Last updated has no active highlight by default. Selecting the
header adds the sort URL and active direction. Removing the explicit
sort restores the neutral header.
- Manual check: Open Tasks with no saved task view. Confirm All tasks
opens. Select Mine, leave Tasks, and return. Confirm Mine remains
selected.

## Risks

- The new default shows more accessible company tasks on the first
visit. Saved view choices remain intact.
- Task tables share the sort-state change. Explicit sort links and
column clicks retain active styling. Default row order stays
newest-updated first.
- No schema, API, permission, or execution changes.

## Model Used

OpenAI Codex, GPT-6 family. This session does not expose the exact model
ID or context-window size. Used reasoning, code editing, terminal
commands, and browser verification.

## 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
- [ ] 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 <scott@scottsmbpm5max.lan>
Co-authored-by: Paperclip <noreply@paperclip.ing>
2026-11-05 18:44:59 -08:00

157 lines
5.6 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",
"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" },
],
},
{
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;
}