Files
buzz/desktop/src/features/projects/ui/ProjectIssuesPanel.tsx
thomaspblock 122a8b8988 Projects v3: unify sharing, discussions, and issue ownership (#5792)
## Summary

Projects v3 makes repository work shareable, discussion-aware, and
easier to scan in one coherent workspace. People can copy canonical
links, reopen the exact workspace tab, understand issue and pull-request
context at a glance, find related channel conversations, and assign or
unassign issues across Desktop and CLI.

- **Unified workspace** — top-level sections sit above repository
controls in one rounded workspace, with navigation positioned close to
the page heading. README and Files retain branch selection; every
section has a labeled icon header, and Issues and Pull Requests expose
creation from a consistent right-aligned action.
- **Repository management** — the repository selector is always
available, including single-repository projects. Its integrated add flow
lets project owners create a repository manually or select an existing
repository without a separate toolbar button.
- **Readable work-item lists** — issue and pull-request rows use
plain-language context instead of opaque metadata. Files, commits,
issues, pull requests, channels, and contributors share consistent row
density and right-aligned timestamps, while deterministic
fallback-avatar colors keep participants distinct on light backgrounds.
Inbox pull-request metadata wraps between complete phrases and truncates
long channel names instead of compressing copy into narrow columns.
- **Reliable entity links** — projects, repositories, issues, pull
requests, and commits have canonical `buzz://` links, preview cards, OS
deep-link routing, and tab-aware navigation. Reopening the same link
re-applies its destination instead of leaving the user on a locally
selected tab.
- **Related conversations** — repository and work-item views surface
channels discussing the current entity, including participants, channel
navigation, message context, and an explicit notice when discovery
reaches its 500-result cap.
- **Reversible issue ownership** — trusted assignment and unassignment
events work across Desktop, Tauri, `buzz-sdk`, and `buzz issues`.
Assignees appear in project views and the assigned inbox, while
authorized users can remove assignments directly from the assignee row.

Assignment state is derived chronologically from labeled Nostr notes.
Issue authors and repository owners may change any assignee; other users
may only assign or unassign themselves. Shared golden fixtures keep
entity-link grammar and validation aligned across TypeScript and Rust.

The branch also updates `webbrowser` to the patched release for
RUSTSEC-2026-0257.

### Related issue

N/A.

### Testing

- [x] `just ci` — formatting, lint, typechecking, unit tests, and builds
passed
- [x] Full pre-push suite — organization, branch-skew, Desktop checks,
typechecking, and tests passed on the latest push
- [x] `cargo test -p buzz-cli` and focused `buzz-sdk` assignment tests
passed
- [x] Focused Tauri recipient-note and 500-result search-limit tests
passed
- [x] Desktop entity-link and issue-assignment unit tests passed
- [x] Playwright smoke coverage passed for assignment, repeated
entity-link navigation, repository create/select flows, section headers
and actions, timestamp alignment, timeline icons, sentence-style
issue/PR metadata, header spacing, avatar contrast, and Inbox metadata
at stacked and side-rail breakpoints
- [ ] Manual staging pass: link round-trips, Channels tab, assignment
flows, and inbox routing

### Screenshots

Pull requests explain who opened the request, where it lives, and which
branch it comes from; fallback avatars remain visually distinct.

![Pull request list with conversational
metadata](https://raw.githubusercontent.com/block/buzz/2a536de86f7e6f79b349d7bc147b2923ff2b817d/pr-5624--05-pr-list-metadata.png)

Issues use the same sentence-style hierarchy while keeping status and
recency easy to scan.

![Issue list with conversational
metadata](https://raw.githubusercontent.com/block/buzz/2a536de86f7e6f79b349d7bc147b2923ff2b817d/pr-5624--06-issue-list-metadata.png)

The wide Inbox detail keeps author, timestamp, and origin context
readable beside its metadata rail.

![Pull request Inbox detail with readable
metadata](https://raw.githubusercontent.com/block/buzz/e65b433e14b97c45365ed7b68ea402ec01d26615/pr-5624--02-pull-request-detail-wide.png)

[View the complete six-state Projects v3 screenshot
set](https://github.com/block/buzz/pull/5624#issuecomment-5268039672)
and [the compact/wide Inbox
comparison](https://github.com/block/buzz/pull/5624#issuecomment-5268614585).


---

> Supersedes #5624, whose head commit accumulated permanently-queued
required check suites (block-dco-check et al.) that GitHub never
dispatched. History flattened into a single signed-off commit on latest
main; tree verified byte-identical (`git merge-tree`) to merging the
original branch into main.

---------

Signed-off-by: Thomas Petersen <thomasp@squareup.com>
Co-authored-by: Wintermute <3f1797424fd9ad6653a83665c660517777cd7f8c228c0d5907f49e01537f3ca5@buzz.block.builderlab.xyz>
2026-08-14 16:48:41 -04:00

430 lines
13 KiB
TypeScript

import { CircleCheck, CircleDot, CircleX, MessageSquare } from "lucide-react";
import * as React from "react";
import { toast } from "sonner";
import { useIsManagedAgent } from "@/features/agent-memory/hooks";
import { ForumComposer } from "@/features/forum/ui/ForumComposer";
import {
type ProjectIssue,
type Repository as Project,
useCreateProjectIssueCommentMutation,
useProjectIssuesQuery,
} from "@/features/projects/hooks";
import {
resolveUserLabel,
type UserProfileLookup,
} from "@/features/profile/lib/identity";
import { entityDiscussionQuery } from "@/features/projects/lib/discussionChannels";
import { issueShareLink } from "@/features/projects/lib/projectShareLinks";
import { relativeTime } from "@/features/projects/lib/projectsViewHelpers";
import { useIdentityQuery } from "@/shared/api/hooks";
import type { ChannelMember } from "@/shared/api/types";
import { cn } from "@/shared/lib/cn";
import { normalizePubkey } from "@/shared/lib/pubkey";
import { IssueAssigneeFacepile, IssueAssigneesRow } from "./IssueAssigneesRow";
import {
ProjectFeedRow,
ProjectFeedRowCluster,
ProjectFeedRowMonoCell,
} from "./ProjectFeedRow";
import { DiscussedInChannels } from "./DiscussionChannels";
import { ProjectIssueCommentTimeline } from "./ProjectIssueCommentTimeline";
import { ProjectOriginReference } from "./ProjectOriginReference";
import { OverviewRailSection } from "./ProjectOverviewPanel";
import { ProfileIdentityButton } from "./ProjectProfileIdentity";
import { ProjectRichContent } from "./ProjectRichContent";
import { ShareLinkButton } from "./ShareLinkButton";
export function issueStatusClassName(status: ProjectIssue["status"]) {
if (status === "Done") return "text-purple-400";
if (status === "Closed") return "text-destructive";
return "text-green-500";
}
function issueStatusVisual(status: ProjectIssue["status"]) {
if (status === "Done") {
return { className: "text-purple-400", icon: CircleCheck };
}
if (status === "Closed") {
return { className: "text-destructive", icon: CircleX };
}
return { className: "text-green-500", icon: CircleDot };
}
function issueMembers(
project: Project,
issue: ProjectIssue,
profiles?: UserProfileLookup,
): ChannelMember[] {
return [
...new Set([
project.owner,
issue.author,
...project.contributors,
...issue.recipients,
]),
].map((pubkey) => {
const profile = profiles?.[normalizePubkey(pubkey)];
return {
pubkey,
role: "member" as const,
isAgent: profile?.isAgent === true,
joinedAt: new Date(0).toISOString(),
displayName:
profile?.displayName?.trim() || profile?.nip05Handle?.trim() || null,
};
});
}
function IssueRow({
issue,
onOpen,
profiles,
}: {
issue: ProjectIssue;
onOpen: () => void;
profiles?: UserProfileLookup;
}) {
const authorProfile = profiles?.[normalizePubkey(issue.author)];
const authorLabel = resolveUserLabel({ profiles, pubkey: issue.author });
const status = issueStatusVisual(issue.status);
return (
<ProjectFeedRow
meta={
<>
<ProfileIdentityButton
avatarClassName="shrink-0"
avatarSize="xs"
avatarUrl={authorProfile?.avatarUrl ?? null}
isAgent={authorProfile?.isAgent === true}
label={authorLabel}
pubkey={issue.author}
showLabel={false}
/>
<span className="truncate text-foreground/80">
<span className="font-medium">{authorLabel}</span> created this
issue
</span>
<span>·</span>
<span>{issue.status}</span>
{issue.labels.map((label) => (
<span
className="rounded-full border border-border/60 px-1.5 py-0.5 text-2xs"
key={label}
>
{label}
</span>
))}
</>
}
eventId={issue.id}
onOpen={onOpen}
statusIcon={
<status.icon className={`h-3.5 w-3.5 shrink-0 ${status.className}`} />
}
testId="project-issue-row"
title={issue.title}
trailing={
<>
<IssueAssigneeFacepile
assignees={issue.assignees}
profiles={profiles}
/>
{issue.comments.length > 0 ? (
<button
aria-label={`View ${issue.comments.length} comments`}
className="flex items-center gap-1 rounded-md text-xs text-muted-foreground hover:text-foreground focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring"
onClick={onOpen}
type="button"
>
<MessageSquare className="h-3.5 w-3.5" />
{issue.comments.length}
</button>
) : null}
<ProjectFeedRowCluster>
<ProjectFeedRowMonoCell
label={`#${issue.id.slice(0, 8)}`}
onClick={onOpen}
title="View issue"
/>
</ProjectFeedRowCluster>
<span
className="hidden w-20 shrink-0 text-right text-xs text-muted-foreground sm:block"
data-testid="project-issue-row-date"
title={new Date(issue.createdAt * 1_000).toLocaleString()}
>
{relativeTime(issue.createdAt)}
</span>
</>
}
/>
);
}
/** Full issue conversation and comment composer. */
export function ProjectIssueDetail({
issue,
profiles,
project,
stackMetaRail = false,
}: {
issue: ProjectIssue;
profiles?: UserProfileLookup;
project: Project;
stackMetaRail?: boolean;
}) {
const commentMutation = useCreateProjectIssueCommentMutation(project);
const authorLabel = resolveUserLabel({ profiles, pubkey: issue.author });
const members = React.useMemo(
() => issueMembers(project, issue, profiles),
[issue, profiles, project],
);
const handleCommentSubmit = React.useCallback(
async (
content: string,
mentionPubkeys: string[],
mediaTags?: string[][],
) => {
try {
await commentMutation.mutateAsync({
content,
issue,
mediaTags,
mentionPubkeys,
});
toast.success("Comment posted.");
} catch (error) {
toast.error(
error instanceof Error ? error.message : "Failed to post comment.",
);
throw error;
}
},
[commentMutation, issue],
);
return (
<div
className={cn(
"grid",
!stackMetaRail && "xl:grid-cols-[minmax(0,1fr)_18rem]",
)}
>
<div className="min-w-0">
<header className="space-y-3 p-4">
<div className="min-w-0">
<p className="flex flex-wrap items-center gap-1.5 text-xs font-medium text-muted-foreground">
<CircleDot className="h-3.5 w-3.5" />
Issue from {authorLabel}
<ProjectOriginReference
agentName={issue.originAgentName}
channelId={issue.channelId}
/>
</p>
<h3 className="mt-1 line-clamp-2 text-base font-semibold text-foreground">
{issue.title}{" "}
<span className="font-normal text-muted-foreground">
#{issue.id.slice(0, 8)}
</span>
<ShareLinkButton
className="ml-1 inline-flex h-6 w-6 align-text-bottom"
label="Copy issue link"
link={issueShareLink(issue)}
testId="project-issue-copy-link"
/>
</h3>
</div>
{issue.content ? (
<ProjectRichContent content={issue.content} tags={issue.tags} />
) : null}
</header>
<section className="space-y-3 p-4">
<DiscussedInChannels
entityLabel="this issue"
query={entityDiscussionQuery(issue.id)}
testId="issue-discussed-in"
/>
<ProjectIssueCommentTimeline
comments={issue.comments}
key={issue.id}
profiles={profiles}
/>
<div data-testid="project-issue-comment-composer">
<ForumComposer
className="border border-border/60 bg-background/45"
disabled={commentMutation.isPending}
isSending={commentMutation.isPending}
members={members}
onSubmit={handleCommentSubmit}
placeholder="Add a comment…"
profiles={profiles}
/>
</div>
</section>
</div>
<IssueMetaRail
issue={issue}
profiles={profiles}
project={project}
stacked={stackMetaRail}
/>
</div>
);
}
/** Right-hand meta column for the issue detail view: status, assignees,
* author, labels, and dates — keeps the conversation column focused. */
function IssueMetaRail({
issue,
profiles,
project,
stacked = false,
}: {
issue: ProjectIssue;
profiles?: UserProfileLookup;
project: Project;
stacked?: boolean;
}) {
const identityQuery = useIdentityQuery();
const authorProfile = profiles?.[normalizePubkey(issue.author)];
const authorLabel = resolveUserLabel({ profiles, pubkey: issue.author });
const status = issueStatusVisual(issue.status);
const viewerPubkey = identityQuery.data?.pubkey;
const viewer = viewerPubkey ? normalizePubkey(viewerPubkey) : null;
const isAuthor = viewer === normalizePubkey(issue.author);
const isOwner = viewer === normalizePubkey(project.owner);
const isManagedAgentOwner = useIsManagedAgent(project.owner) === true;
// Same trust rule as parsing (assigneesForIssue): the issue author or
// repo owner (directly or via a managed agent) can assign anyone;
// everyone else who is signed in may still self-assign.
const canAssignOthers =
Boolean(viewer) && (isAuthor || isOwner || isManagedAgentOwner);
return (
<aside
className={cn(
"space-y-6 border-border/60 p-4",
stacked ? "border-t" : "border-t xl:border-l xl:border-t-0",
)}
>
<OverviewRailSection title="Status">
<span
className={`inline-flex items-center gap-1.5 rounded-md border border-border/60 px-2.5 py-1 text-xs font-medium ${status.className}`}
>
<status.icon className="h-3.5 w-3.5" />
{issue.status}
</span>
</OverviewRailSection>
{issue.assignees.length > 0 || viewer ? (
<OverviewRailSection title="Assignees">
<IssueAssigneesRow
canAssignOthers={canAssignOthers}
issue={issue}
profiles={profiles}
project={project}
signAsManagedOwner={isManagedAgentOwner && !isOwner}
viewerPubkey={viewer}
/>
</OverviewRailSection>
) : null}
<OverviewRailSection title="Author">
<ProfileIdentityButton
align="center"
avatarSize="xs"
avatarUrl={authorProfile?.avatarUrl ?? null}
isAgent={authorProfile?.isAgent === true}
label={authorLabel}
pubkey={issue.author}
/>
</OverviewRailSection>
{issue.labels.length > 0 ? (
<OverviewRailSection title="Labels">
<div className="flex flex-wrap gap-1.5">
{issue.labels.map((label) => (
<span
className="rounded-full border border-border/60 px-1.5 py-0.5 text-2xs text-muted-foreground"
key={label}
>
{label}
</span>
))}
</div>
</OverviewRailSection>
) : null}
<OverviewRailSection title="Activity">
<dl className="space-y-1.5 text-xs text-muted-foreground">
<div className="flex items-center justify-between gap-3">
<dt>Created</dt>
<dd className="font-medium text-foreground">
{relativeTime(issue.createdAt)}
</dd>
</div>
<div className="flex items-center justify-between gap-3">
<dt>Updated</dt>
<dd className="font-medium text-foreground">
{relativeTime(issue.updatedAt)}
</dd>
</div>
</dl>
</OverviewRailSection>
</aside>
);
}
export function ProjectIssuesPanel({
onSelectedIssueIdChange,
profiles,
project,
selectedIssueId,
}: {
onSelectedIssueIdChange: (id: string | null) => void;
profiles?: UserProfileLookup;
project: Project;
selectedIssueId: string | null;
}) {
const issuesQuery = useProjectIssuesQuery(project);
const issues = issuesQuery.data ?? [];
const selectedIssue =
issues.find((issue) => issue.id === selectedIssueId) ?? null;
if (issuesQuery.isLoading) {
return <p className="p-4 text-sm text-muted-foreground">Loading issues…</p>;
}
if (issues.length === 0) {
return (
<p className="p-4 text-sm text-muted-foreground">
{issuesQuery.error
? "Could not load issues for this repository."
: "No issues yet."}
</p>
);
}
if (selectedIssue) {
return (
<ProjectIssueDetail
issue={selectedIssue}
profiles={profiles}
project={project}
/>
);
}
return (
<div className="divide-y divide-border/50">
{issues.map((issue) => (
<IssueRow
issue={issue}
key={issue.id}
onOpen={() => onSelectedIssueIdChange(issue.id)}
profiles={profiles}
/>
))}
</div>
);
}