mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-21 16:27:18 +02:00
Polish inbox nested issue UI
Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
1 parent
42a299fb9d
commit
fdcf96a46c
7 files changed
+166
-50
No files matched your search
@@ -1487,6 +1487,49 @@ describe("IssueChatThread", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("invokes the cancel callback for pending question interactions", async () => {
|
||||
const root = createRoot(container);
|
||||
const onCancelInteraction = vi.fn(async () => undefined);
|
||||
|
||||
await act(async () => {
|
||||
root.render(
|
||||
<MemoryRouter>
|
||||
<IssueChatThread
|
||||
comments={[]}
|
||||
interactions={[createQuestionInteraction()]}
|
||||
linkedRuns={[]}
|
||||
timelineEvents={[]}
|
||||
liveRuns={[]}
|
||||
onAdd={async () => {}}
|
||||
onCancelInteraction={onCancelInteraction}
|
||||
showComposer={false}
|
||||
enableLiveTranscriptPolling={false}
|
||||
/>
|
||||
</MemoryRouter>,
|
||||
);
|
||||
});
|
||||
|
||||
const cancelButton = Array.from(container.querySelectorAll("button")).find((button) =>
|
||||
button.textContent?.includes("Cancel question"),
|
||||
);
|
||||
expect(cancelButton).toBeTruthy();
|
||||
|
||||
await act(async () => {
|
||||
cancelButton?.dispatchEvent(new MouseEvent("click", { bubbles: true }));
|
||||
});
|
||||
|
||||
expect(onCancelInteraction).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
id: "interaction-question-1",
|
||||
kind: "ask_user_questions",
|
||||
}),
|
||||
);
|
||||
|
||||
act(() => {
|
||||
root.unmount();
|
||||
});
|
||||
});
|
||||
|
||||
it("folds expired request confirmations into an activity row by default", async () => {
|
||||
const root = createRoot(container);
|
||||
|
||||
|
||||
@@ -807,8 +807,8 @@ function AskUserQuestionsCard({
|
||||
) : (
|
||||
"Cancel question"
|
||||
)}
|
||||
</Button>
|
||||
) : null}
|
||||
</Button>
|
||||
) : null}
|
||||
<Button
|
||||
size="sm"
|
||||
disabled={!onSubmitInteractionAnswers || !canSubmit || working || cancelling}
|
||||
|
||||
@@ -1114,8 +1114,8 @@ describe("IssuesList", () => {
|
||||
title: `Issue ${index + 1}`,
|
||||
}),
|
||||
);
|
||||
const onLoadMoreIssues = vi.fn();
|
||||
setDocumentScrollMetrics({ innerHeight: 2000, scrollY: 0, scrollHeight: 1000 });
|
||||
const onLoadMoreIssues = vi.fn();
|
||||
setDocumentScrollMetrics({ innerHeight: 2000, scrollY: 0, scrollHeight: 1000 });
|
||||
|
||||
const { root } = renderWithQueryClient(
|
||||
<IssuesList
|
||||
|
||||
@@ -153,7 +153,7 @@ export function SwipeToArchive({
|
||||
data-inbox-row-surface
|
||||
className={cn(
|
||||
"relative will-change-transform",
|
||||
selected ? "bg-zinc-100 dark:bg-zinc-800" : "bg-card",
|
||||
selected ? "bg-zinc-100 dark:bg-zinc-800" : "bg-background",
|
||||
)}
|
||||
style={{
|
||||
transform: `translate3d(${offsetX}px, 0, 0)`,
|
||||
|
||||
@@ -634,6 +634,45 @@ describe("inbox helpers", () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it("keeps nested grandchild issues visible in keyboard navigation", () => {
|
||||
const parentIssue = makeIssue("parent", true);
|
||||
parentIssue.lastActivityAt = new Date("2026-03-11T01:00:00.000Z");
|
||||
const childIssue = makeIssue("child", true);
|
||||
childIssue.parentId = parentIssue.id;
|
||||
childIssue.lastActivityAt = new Date("2026-03-11T02:00:00.000Z");
|
||||
const grandchildIssue = makeIssue("grandchild", false);
|
||||
grandchildIssue.parentId = childIssue.id;
|
||||
grandchildIssue.lastActivityAt = new Date("2026-03-11T05:00:00.000Z");
|
||||
|
||||
const [section] = buildGroupedInboxSections(
|
||||
getInboxWorkItems({ issues: [parentIssue, childIssue, grandchildIssue], approvals: [] }),
|
||||
"none",
|
||||
{},
|
||||
{ nestingEnabled: true },
|
||||
);
|
||||
|
||||
expect(section?.displayItems.map((item) => item.kind === "issue" ? item.issue.id : "other")).toEqual([
|
||||
parentIssue.id,
|
||||
]);
|
||||
expect(section?.displayItems[0]?.timestamp).toBe(new Date("2026-03-11T05:00:00.000Z").getTime());
|
||||
|
||||
expect(
|
||||
buildInboxKeyboardNavEntries([section!], new Set(), new Set()).map((entry) => entry.type === "top"
|
||||
? entry.item.kind === "issue" ? entry.item.issue.id : "other"
|
||||
: entry.type === "child"
|
||||
? entry.issueId
|
||||
: entry.groupKey),
|
||||
).toEqual([parentIssue.id, childIssue.id, grandchildIssue.id]);
|
||||
|
||||
expect(
|
||||
buildInboxKeyboardNavEntries([section!], new Set(), new Set([childIssue.id])).map((entry) => entry.type === "top"
|
||||
? entry.item.kind === "issue" ? entry.item.issue.id : "other"
|
||||
: entry.type === "child"
|
||||
? entry.issueId
|
||||
: entry.groupKey),
|
||||
).toEqual([parentIssue.id, childIssue.id]);
|
||||
});
|
||||
|
||||
it("emits a group nav entry for labeled groups and omits children when the group is collapsed", () => {
|
||||
const visibleIssue = makeIssue("visible", true);
|
||||
const hiddenIssue = makeIssue("hidden", true);
|
||||
|
||||
+35
-14
@@ -906,9 +906,26 @@ export function buildInboxNesting(items: InboxWorkItem[]): {
|
||||
}
|
||||
}
|
||||
|
||||
// Sort each child list by most recent activity
|
||||
const subtreeActivityTimestamp = (issue: Issue, seen: ReadonlySet<string> = new Set()): number => {
|
||||
const ownTimestamp = issueLastActivityTimestamp(issue);
|
||||
if (seen.has(issue.id)) return ownTimestamp;
|
||||
const nextSeen = new Set(seen);
|
||||
nextSeen.add(issue.id);
|
||||
const children = childrenByIssueId.get(issue.id) ?? [];
|
||||
if (children.length === 0) return ownTimestamp;
|
||||
return Math.max(
|
||||
ownTimestamp,
|
||||
...children.map((child) => subtreeActivityTimestamp(child, nextSeen)),
|
||||
);
|
||||
};
|
||||
|
||||
// Sort each child list by most recent descendant activity, not just direct issue activity.
|
||||
for (const children of childrenByIssueId.values()) {
|
||||
children.sort(sortIssuesByMostRecentActivity);
|
||||
children.sort((a, b) => {
|
||||
const activityDiff = subtreeActivityTimestamp(b) - subtreeActivityTimestamp(a);
|
||||
if (activityDiff !== 0) return activityDiff;
|
||||
return sortIssuesByMostRecentActivity(a, b);
|
||||
});
|
||||
}
|
||||
|
||||
// Build root issue items with group-adjusted timestamps
|
||||
@@ -917,7 +934,7 @@ export function buildInboxNesting(items: InboxWorkItem[]): {
|
||||
.map((item) => {
|
||||
const children = childrenByIssueId.get(item.issue.id);
|
||||
if (!children?.length) return item;
|
||||
const maxChildTs = Math.max(...children.map(issueLastActivityTimestamp));
|
||||
const maxChildTs = Math.max(...children.map((child) => subtreeActivityTimestamp(child)));
|
||||
return { ...item, timestamp: Math.max(item.timestamp, maxChildTs) };
|
||||
});
|
||||
|
||||
@@ -985,6 +1002,20 @@ export function buildInboxKeyboardNavEntries(
|
||||
}
|
||||
if (isCollapsed) continue;
|
||||
|
||||
const addIssueChildren = (issueId: string) => {
|
||||
const children = group.childrenByIssueId.get(issueId);
|
||||
if (!children?.length || collapsedInboxParents.has(issueId)) return;
|
||||
|
||||
for (const child of children) {
|
||||
entries.push({
|
||||
type: "child",
|
||||
issueId: child.id,
|
||||
issue: child,
|
||||
});
|
||||
addIssueChildren(child.id);
|
||||
}
|
||||
};
|
||||
|
||||
for (const item of group.displayItems) {
|
||||
entries.push({
|
||||
type: "top",
|
||||
@@ -993,17 +1024,7 @@ export function buildInboxKeyboardNavEntries(
|
||||
});
|
||||
|
||||
if (item.kind !== "issue") continue;
|
||||
|
||||
const children = group.childrenByIssueId.get(item.issue.id);
|
||||
if (!children?.length || collapsedInboxParents.has(item.issue.id)) continue;
|
||||
|
||||
for (const child of children) {
|
||||
entries.push({
|
||||
type: "child",
|
||||
issueId: child.id,
|
||||
issue: child,
|
||||
});
|
||||
}
|
||||
addIssueChildren(item.issue.id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+44
-31
@@ -2122,7 +2122,7 @@ export function Inbox() {
|
||||
<>
|
||||
{showSeparatorBefore("work_items") && <Separator />}
|
||||
<div>
|
||||
<div ref={listRef} className="overflow-hidden rounded-xl bg-card">
|
||||
<div ref={listRef} className="overflow-hidden rounded-xl">
|
||||
{(() => {
|
||||
const renderInboxIssue = ({
|
||||
issue,
|
||||
@@ -2436,6 +2436,48 @@ export function Inbox() {
|
||||
const hasChildren = childIssues.length > 0;
|
||||
const isExpanded = hasChildren && !collapsedInboxParents.has(issue.id);
|
||||
const canArchiveIssue = canArchiveFromTab && group.searchSection === "none";
|
||||
const renderChildIssueRows = (children: Issue[], depth: number): ReactNode[] =>
|
||||
children.flatMap((child) => {
|
||||
const childNavIdx = childFlatIndex.get(child.id) ?? -1;
|
||||
const isChildSelected = selectedIndex === childNavIdx;
|
||||
const grandchildIssues = group.childrenByIssueId.get(child.id) ?? [];
|
||||
const childHasChildren = grandchildIssues.length > 0;
|
||||
const childIsExpanded = childHasChildren && !collapsedInboxParents.has(child.id);
|
||||
const childRow = renderInboxIssue({
|
||||
issue: child,
|
||||
depth,
|
||||
selected: isChildSelected,
|
||||
hasChildren: childHasChildren,
|
||||
isExpanded: childIsExpanded,
|
||||
childCount: grandchildIssues.length,
|
||||
collapseParentId: child.id,
|
||||
allowArchive: canArchiveIssue,
|
||||
});
|
||||
const isChildArchiving = archivingIssueIds.has(child.id);
|
||||
const row = (
|
||||
<div
|
||||
key={`sel-issue:${child.id}`}
|
||||
data-inbox-item
|
||||
className="relative"
|
||||
onClick={() => setSelectedIndex(childNavIdx)}
|
||||
>
|
||||
{canArchiveIssue ? (
|
||||
<SwipeToArchive
|
||||
key={`issue:${child.id}`}
|
||||
selected={isChildSelected}
|
||||
disabled={isChildArchiving || archiveIssueMutation.isPending}
|
||||
onArchive={() => archiveIssueMutation.mutate(child.id)}
|
||||
>
|
||||
{childRow}
|
||||
</SwipeToArchive>
|
||||
) : childRow}
|
||||
</div>
|
||||
);
|
||||
|
||||
return childIsExpanded
|
||||
? [row, ...renderChildIssueRows(grandchildIssues, depth + 1)]
|
||||
: [row];
|
||||
});
|
||||
const parentRow = renderInboxIssue({
|
||||
issue,
|
||||
depth: 0,
|
||||
@@ -2459,36 +2501,7 @@ export function Inbox() {
|
||||
) : parentRow));
|
||||
|
||||
if (isExpanded) {
|
||||
for (const child of childIssues) {
|
||||
const childNavIdx = childFlatIndex.get(child.id) ?? -1;
|
||||
const isChildSelected = selectedIndex === childNavIdx;
|
||||
const childRow = renderInboxIssue({
|
||||
issue: child,
|
||||
depth: 1,
|
||||
selected: isChildSelected,
|
||||
allowArchive: canArchiveIssue,
|
||||
});
|
||||
const isChildArchiving = archivingIssueIds.has(child.id);
|
||||
elements.push(
|
||||
<div
|
||||
key={`sel-issue:${child.id}`}
|
||||
data-inbox-item
|
||||
className="relative"
|
||||
onClick={() => setSelectedIndex(childNavIdx)}
|
||||
>
|
||||
{canArchiveIssue ? (
|
||||
<SwipeToArchive
|
||||
key={`issue:${child.id}`}
|
||||
selected={isChildSelected}
|
||||
disabled={isChildArchiving || archiveIssueMutation.isPending}
|
||||
onArchive={() => archiveIssueMutation.mutate(child.id)}
|
||||
>
|
||||
{childRow}
|
||||
</SwipeToArchive>
|
||||
) : childRow}
|
||||
</div>,
|
||||
);
|
||||
}
|
||||
elements.push(...renderChildIssueRows(childIssues, 1));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user