import { CircleDot, FileCode2, FolderGit2, GitCommitHorizontal, GitPullRequest, Radio, Users, } from "lucide-react"; import type * as React from "react"; import { WorkspaceEmojiIcon } from "@/features/workspaces/ui/WorkspaceSwitcher"; import type { Project, ProjectActivitySummary, ProjectRepoSnapshot, } from "@/features/projects/hooks"; import { languageForPath, topLanguagesFromCounts, } from "@/features/projects/lib/projectLanguages"; import { resolveUserLabel, type UserProfileLookup, } from "@/features/profile/lib/identity"; import { normalizePubkey } from "@/shared/lib/pubkey"; import { Tooltip, TooltipContent, TooltipTrigger } from "@/shared/ui/tooltip"; import { UserAvatar } from "@/shared/ui/UserAvatar"; import { LanguageChips, OverviewRailSection } from "./ProjectOverviewPanel"; import { ProjectsContributionGraph } from "./ProjectsContributionGraph"; export type ProjectsOverviewSection = | "repositories" | "prs" | "local" | "issues"; type ProjectsOverviewPanelProps = { localRepositoryCount: number; onSelectSection: (section: ProjectsOverviewSection) => void; profiles?: UserProfileLookup; projects: Project[]; relayName: string; /** Repo snapshots keyed by project ID, for workspace-wide aggregates. */ snapshots?: Record; snapshotsLoading?: boolean; summaries?: Record; }; function projectPeople( project: Project, summary: ProjectActivitySummary | undefined, ) { return [ ...new Set( [ project.owner, ...project.contributors, ...(summary?.participantPubkeys ?? []), ].map(normalizePubkey), ), ]; } function overviewPeople( projects: Project[], summaries: Record | undefined, ) { return [ ...new Set( projects.flatMap((project) => projectPeople(project, summaries?.[project.repoAddress]), ), ), ]; } function overviewStats( projects: Project[], summaries: Record | undefined, ) { return projects.reduce( (stats, project) => { const summary = summaries?.[project.repoAddress]; return { issues: stats.issues + (summary?.issueCount ?? 0), prs: stats.prs + (summary?.prCount ?? 0), }; }, { issues: 0, prs: 0 }, ); } function overviewLanguages( snapshots: Record | undefined, ) { const counts: Record = {}; for (const snapshot of Object.values(snapshots ?? {})) { for (const file of snapshot.files) { const language = languageForPath(file.path); if (language) counts[language] = (counts[language] ?? 0) + 1; } } return topLanguagesFromCounts(counts); } function overviewRepoTotals( snapshots: Record | undefined, ) { const contributorEmails = new Set(); let files = 0; let latestCommit: ProjectRepoSnapshot["latestCommit"] = null; for (const snapshot of Object.values(snapshots ?? {})) { files += snapshot.files.length; for (const contributor of snapshot.contributors) { contributorEmails.add( contributor.email.toLowerCase() || contributor.name.toLowerCase(), ); } if ( snapshot.latestCommit && snapshot.latestCommit.timestamp > (latestCommit?.timestamp ?? 0) ) { latestCommit = snapshot.latestCommit; } } return { contributors: contributorEmails.size, files, latestCommit }; } function RepoTotalRow({ icon: Icon, label, value, mono, }: { icon?: React.ComponentType<{ className?: string }>; label: string; value: React.ReactNode; mono?: boolean; }) { return (
{Icon ? : null} {label}
{value}
); } function overviewActivityByDay( projects: Project[], summaries: Record | undefined, ) { const merged: Record = {}; for (const project of projects) { const byDay = summaries?.[project.repoAddress]?.activityByDay; if (!byDay) continue; for (const [day, count] of Object.entries(byDay)) { merged[day] = (merged[day] ?? 0) + count; } } return merged; } function StatPill({ count, icon: Icon, label, onClick, }: { count: number; icon: React.ComponentType<{ className?: string }>; label: string; onClick: () => void; }) { return ( ); } export function ProjectsOverviewPanel({ localRepositoryCount, onSelectSection, profiles, projects, relayName, snapshots, snapshotsLoading, summaries, }: ProjectsOverviewPanelProps) { const stats = overviewStats(projects, summaries); const people = overviewPeople(projects, summaries); const activityByDay = overviewActivityByDay(projects, summaries); const languages = overviewLanguages(snapshots); const repoTotals = overviewRepoTotals(snapshots); const scanning = Boolean(snapshotsLoading); return (

{relayName} Projects

Browse shared repositories, pull requests, and local project checkouts in this workspace.

onSelectSection("repositories")} /> onSelectSection("prs")} /> onSelectSection("local")} /> onSelectSection("issues")} />

Contribution activity

); }