Files
PaperClipAI/ui/src/components/RecentTaskGroup.tsx
T
DottaandPaperclip 991f773d7f fix(ui): align recent task status icons and move fold controls right (#21859)
## Thinking Path

> - Paperclip helps people manage AI agents for work.
> - The sidebar shows recent tasks and their subtasks.
> - A left fold control moves parent tasks away from the status column.
> - Status icons must stay in one column so people can scan tasks.
> - This pull request moves the fold control to the right.
> - The child guide now starts below the parent status icon.

## Linked Issues or Issue Description

Follow-up to #21649. Related sidebar alignment work: #20926. Related
experimental Recents work: #12314. This change corrects the status
column in the shipped subtask group.

**What happened?**

Parent tasks with subtasks moved 20 pixels to the right. Their status
icons did not align with tasks that had no subtasks.

**Expected behavior**

All top-level task status icons align. The child guide is centered below
the parent status icon. The fold control is on the right.

**Steps to reproduce**

1. Open a sidebar with a recent parent task and a task that has no
subtasks.
2. Compare their status icons.
3. Expand the parent and compare the child guide with its status icon.

## What Changed

- Remove the left offset from parent task rows.
- Put the fold control in a separate right slot.
- Center the child guide below the parent status slot.
- Add browser checks for alignment, narrow rows, unread parents, both
themes, and separate Classic menu and fold controls.

## Verification

- The browser regression failed before the fix: the status icons
differed by 20 pixels.
- Final browser run: 44 checks passed. It covers 20 states in both
themes, folding, paging, unread state, light and dark alignment, and the
Classic action menu.
- The focused component and request-performance suites passed: 46 tests.
- Final source is based on master `29903bed59b1`. UI typecheck and the
focused browser-test typecheck passed. The published head is
`b8287aec1f55aa182b44622d72b20fe7ed7ce0e6`. Its tree matches the tested
local tree `958e8d901ed1fec9ae17c164271eda4d25edca45`.
- `pnpm verify --base origin/master` returned exit 2. It requires broad
CI because the browser suite changed. Focused checks pass. [CI
43803650911](https://github.com/paperclipai/paperclip/actions/runs/43803650911)
passes typecheck, build, all eight E2E shards, policy, Runner checks,
all nine serialized server suites, all twelve general server shards, and
[final
verification](https://github.com/paperclipai/paperclip/actions/runs/43803650911/job/133095032900).
All 62 check runs are clean: 57 success, 3 skipped, and 2 neutral. No
checks are pending or failed. The legacy Snyk status also passes.
- [Greptile
review](https://github.com/paperclipai/paperclip/pull/21859#issuecomment-6907272673)
is 5/5 on head `b8287aec1f55aa182b44622d72b20fe7ed7ce0e6`. The check
passed. There are no review threads or actionable findings. The separate
source review also reports 5/5.
- Screenshots use production components with HTTP and session fixtures
in Chromium on Linux. No deployed-instance or image-baseline comparison
is claimed.
- No database or API behavior changes.

## Risks

Low risk. The change adjusts layout in the shared task group. The fold
button remains separate from the task link and the Classic action menu.
Exact unread counts and request limits keep their current behavior.

## Model Used

OpenAI Codex, GPT-6. Exact deployment model ID was not supplied by the
runtime.

## Checklist

- [x] I have searched GitHub for duplicate or related PRs and linked
them above

- [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 (this is a sidebar layout bug fix)
- [x] I have linked public issues or described the issue in this PR
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub references)
- [x] My branch name describes the change and has no internal task ID
- [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 (no
command or subsystem behavior change)
- [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: Paperclip <noreply@paperclip.ing>
2026-11-16 09:22:27 -06:00

121 lines
7.5 KiB
TypeScript

import { useEffect, useId, useRef, useState, type ReactNode } from "react";
import { useInfiniteQuery, useQueryClient } from "@tanstack/react-query";
import { readRecentSubtasks } from "@/lib/recent-subtask-requests";
import { ChevronRight } from "lucide-react";
import { issuesApi } from "@/api/issues";
import { queryKeys } from "@/lib/queryKeys";
import { cn } from "@/lib/utils";
import type { RecentTaskEntry } from "@/lib/recent-tasks";
import { RecentTaskNavItem } from "./RecentTaskNavItem";
import { StatusIcon } from "./StatusIcon";
import { taskStatusIconProps } from "@/lib/task-status-presentation";
import { QueryErrorState, useQueryView } from "./QueryView";
export const RECENT_SUBTASK_PAGE_SIZE = 10;
/** Shared by the standard mixed Recents and Classic Recent Tasks. */
type RecentTaskGroupProps = {
task: RecentTaskEntry;
userId: string | null | undefined;
selectedChild?: RecentTaskEntry;
children: ReactNode;
className?: string;
rail?: boolean;
renderChild?: (task: RecentTaskEntry) => ReactNode;
/** Invalid cyclic ancestry remains reachable as plain task rows. */
flattened?: boolean;
};
export function RecentTaskGroup(props: RecentTaskGroupProps) {
if (!props.task.subtaskCount || props.rail || props.flattened) return <>{props.children}</>;
return <ExpandableRecentTaskGroup {...props} />;
}
function ExpandableRecentTaskGroup({ task, userId, selectedChild, children, className, rail = false, renderChild }: RecentTaskGroupProps) {
const [expanded, setExpanded] = useState(true);
const [showAllLoaded, setShowAllLoaded] = useState(false);
const anchor = useRef<HTMLDivElement>(null);
const [visible, setVisible] = useState(typeof IntersectionObserver === "undefined");
const contentId = useId();
const queryClient = useQueryClient();
const queryKey = [...queryKeys.issues.list(task.companyId), "recent-subtasks", userId ?? "__local_board__", task.id];
const count = task.subtaskCount ?? 0;
useEffect(() => { if (selectedChild) setExpanded(true); }, [selectedChild?.id]);
// Large recent histories must not start one child request per offscreen parent.
useEffect(() => {
if (!anchor.current || typeof IntersectionObserver === "undefined") return;
const observer = new IntersectionObserver(([entry]) => {
setVisible(Boolean(entry?.isIntersecting));
});
observer.observe(anchor.current);
return () => observer.disconnect();
}, [count, rail]);
const enabled = count > 0 && expanded && visible && !rail;
const query = useInfiniteQuery({
queryKey,
queryFn: ({ pageParam, signal }) => readRecentSubtasks(signal, () => issuesApi.listCompact(task.companyId, {
parentId: task.id, projection: "rows", limit: RECENT_SUBTASK_PAGE_SIZE,
sortField: "id", sortDir: "asc", afterId: pageParam, includeRoutineExecutions: true, includeReadState: true,
}, { signal, cache: "no-store", fresh: true })),
initialPageParam: undefined as string | undefined,
getNextPageParam: (lastPage) => lastPage.length === RECENT_SUBTASK_PAGE_SIZE ? lastPage.at(-1)?.id : undefined,
enabled,
staleTime: 30_000,
});
useEffect(() => {
if (!enabled) void queryClient.cancelQueries({ queryKey, exact: true });
// Scope and eligibility own cancellation; queryKey is rebuilt each render.
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [queryClient, task.companyId, task.id, userId, enabled]);
const preview = () => {
setShowAllLoaded(false);
// Cancel first so an in-flight next page cannot restore discarded pages.
void queryClient.cancelQueries({ queryKey, exact: true }).then(() => {
queryClient.setQueryData<typeof query.data>(queryKey, data => data ? {
pages: data.pages.slice(0, 1), pageParams: data.pageParams.slice(0, 1),
} : data);
});
};
const view = useQueryView(query);
// Always filter by scope/parent, including cache data after an account switch.
const pages = query.data?.pages ?? [];
const loaded = [...new Map(pages.flat().filter(child => child.companyId === task.companyId && child.parentId === task.id)
.map(child => [child.id, child])).values()];
let displayed = showAllLoaded ? loaded : loaded.slice(0, RECENT_SUBTASK_PAGE_SIZE);
const pinned = selectedChild && !displayed.some(child => child.id === selectedChild.id) ? selectedChild : undefined;
// A selected child beyond the first page replaces the last preview row.
if (pinned && !showAllLoaded) displayed = displayed.slice(0, RECENT_SUBTASK_PAGE_SIZE - 1);
const hiddenUnread = Math.max(0, (task.unreadSubtaskCount ?? 0) - displayed.filter(child => child.isUnreadForMe).length - (pinned?.isUnreadForMe ? 1 : 0));
const remaining = Math.max(0, count - displayed.length - (pinned ? 1 : 0));
const controlClass = "mx-2 rounded-md px-2 py-1 text-left text-xs text-muted-foreground hover:bg-sidebar-accent hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring";
const childRow = (child: RecentTaskEntry) => renderChild ? renderChild(child)
: <RecentTaskNavItem task={child} label={child.title} className={className} iconNode={<StatusIcon {...taskStatusIconProps(child)} />} />;
if (!count || rail) return <>{children}</>;
return <div ref={anchor} className="min-w-0">
<div className="flex min-w-0 items-center">
<div className="min-w-0 flex-1">{children}</div>
<button type="button" aria-label={`${expanded ? "Collapse" : "Expand"} subtasks of ${task.title}`} aria-expanded={expanded} aria-controls={expanded ? contentId : undefined}
onClick={() => { if (expanded) preview(); setExpanded(value => !value); }}
className="mr-2 flex size-6 shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-sidebar-accent focus-visible:ring-2 focus-visible:ring-ring">
<ChevronRight aria-hidden="true" className={cn("size-3.5 transition-transform motion-reduce:transition-none", expanded && "rotate-90")} />
</button>
</div>
{!expanded ? <button type="button" className={cn(controlClass, "ml-7")} onClick={() => setExpanded(true)}>
{count} subtasks{task.unreadSubtaskCount ? ` · ${task.unreadSubtaskCount} unread` : ""}
</button> : <div id={contentId} className="ml-6 min-w-0 border-l border-border pl-1" role="group" aria-label={`Subtasks of ${task.title}`}>
{(view.kind === "loading" || view.kind === "reconnecting") && <p role="status" className="px-3 py-1 text-xs text-muted-foreground">Loading subtasks…</p>}
{displayed.map(child => <div key={child.id}>{childRow({ ...child, recordedAt: 0 })}</div>)}
{pinned && childRow(pinned)}
{view.kind === "error" ? <QueryErrorState size="inline" action="load subtasks" error={view.error} retrying={view.isFetching}
className="px-3 py-1 text-xs" onRetry={() => { if (query.isFetchNextPageError) void query.fetchNextPage(); else view.retry(); }} />
: view.data && loaded.length === 0 ? <p className="px-3 py-1 text-xs text-muted-foreground">No subtasks available.</p> : null}
{remaining > 0 && loaded.length > 0 && (loaded.length > displayed.length || query.hasNextPage) && view.kind !== "error" && <button type="button" disabled={query.isFetching} className={controlClass}
onClick={() => { setShowAllLoaded(true); if (loaded.length <= displayed.length + (pinned ? 1 : 0) && query.hasNextPage) void query.fetchNextPage(); }}>
{query.isFetching ? "Loading…" : `Show more (${remaining})`}{hiddenUnread > 0 ? ` · ${hiddenUnread} unread` : ""}
</button>}
{showAllLoaded && displayed.length > RECENT_SUBTASK_PAGE_SIZE && <button type="button" className={controlClass} onClick={preview}>Show less</button>}
</div>}
</div>;
}