mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-25 16:14:26 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - Operators use projects to organize and review related tasks. > - The Coordinator sidebar provides quick access to pinned items. > - Project pins were available from Recents after a project visit. > - This PR makes each project pinnable directly from More → Projects. > - Pinned project rows expand in place so operators can open a recent task from the sidebar. ## Linked Issues or Issue Description **What existing behavior does this improve?** Project navigation in the Coordinator workspace. **Subsystem affected** The board UI, specifically the Projects list and the left sidebar. **Current behavior** Users who review work by project must visit a project before they can pin it from Recents. Project rows use a separate expand control. Hidden sidebar controls also reserve space that can truncate project and task names. **Proposed behavior** Give each Coordinator project row a pin action. Let users click the sidebar project row to open or close its recent tasks, and give labels the full available width while row controls are hidden. **Reason and benefit** Users can set up several project shortcuts from one page and reach the tasks they review regularly from the sidebar. ## What Changed - Add pin and unpin actions to Coordinator Projects rows using the existing per-user browser preference. - Make pinned and recent project rows expand and collapse their tasks. Show closed and open folder icons for the two states. - Match nested task spacing to adjacent navigation items and give nested tasks a small indent. - Reserve sidebar label space for controls when they are visible. Keep the project icon and text centered in the Projects list. - Scope project star and join or leave controls to Classic mode. ## Verification - Run `pnpm --filter @paperclipai/ui typecheck`. - Run the focused workspace preference, project query, and pinned navigation Vitest files. - Run `tests/e2e/project-pinning.spec.ts` in Chromium to verify pinning, persistence, label width, expansion, and task navigation. - In Chromium, open More → Projects and pin a project. Reload and confirm the shortcut persists. Expand it using the mouse or keyboard, open a nested task, reorder pins, and unpin from either the list or the sidebar. - Check label widths at rest and with hover, keyboard focus, and touch controls. Check that Classic mode shows the star and membership controls. - GitHub Actions passed on `e96959bffe`, including build, typecheck, and all eight browser shards. Two server shards passed on retry. [CI run](https://github.com/paperclipai/paperclip/actions/runs/45466386598) - Greptile gave the same commit 5/5 with no open review threads. [Review](https://github.com/paperclipai/paperclip/pull/22805#issuecomment-7141648518) ## Risks - Clicking a project row in the Coordinator sidebar now opens its task list in place. Users can still open the full project from the Projects page. - This UI change reuses the existing browser preference and project task query. It requires no database migration. ## Model Used OpenAI Codex with GPT-6.2-Sol. Used local code execution, Chromium, and GitHub CLI. ## 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 - [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: Scott Tong <scott@scotts-mbp-m5-max.local> Co-authored-by: Paperclip <noreply@paperclip.ing>
275 lines
12 KiB
TypeScript
275 lines
12 KiB
TypeScript
import { useEffect, useMemo, useState } from "react";
|
|
import { useQuery } from "@tanstack/react-query";
|
|
import type { Project } from "@paperclipai/shared";
|
|
import { useCompany } from "../context/CompanyContext";
|
|
import { useDialogActions } from "../context/DialogContext";
|
|
import { useBreadcrumbs } from "../context/BreadcrumbContext";
|
|
import { EntityRow } from "../components/EntityRow";
|
|
import { NavigationPinButton } from "../components/NavigationPinButton";
|
|
import { useCoordinatorWorkspaceEnabled } from "../hooks/useCoordinatorWorkspaceEnabled";
|
|
import { projectPinKey, usePinnedNavigation } from "../hooks/usePinnedNavigation";
|
|
import { ProjectTile } from "../components/ProjectTile";
|
|
import { StatusBadge } from "../components/StatusBadge";
|
|
import { MembershipAction } from "../components/MembershipAction";
|
|
import { StarToggle } from "../components/StarToggle";
|
|
import { ArtifactEmptyGraphic } from "@/components/artifacts/v1/ArtifactEmptyGraphic";
|
|
import { EmptyState } from "../components/EmptyState";
|
|
import { PageSkeleton } from "../components/PageSkeleton";
|
|
import { QueryErrorState, useQueryView } from "../components/QueryView";
|
|
import { formatDate, formatNumber, formatProjectBudget, projectUrl } from "../lib/utils";
|
|
import {
|
|
isStarred,
|
|
resourceMembershipState,
|
|
useResourceMembershipMutation,
|
|
useResourceMemberships,
|
|
} from "../hooks/useResourceMemberships";
|
|
import { ProjectsToolbar, type ProjectSortField, type ProjectSortDir } from "@/components/ProjectsToolbar";
|
|
import { Hexagon } from "lucide-react";
|
|
import { Lock } from "lucide-react";
|
|
import { Card } from "@/components/ui/card";
|
|
import { companyProjectsQuery } from "@/lib/company-projects-query";
|
|
|
|
function compareProjectNames(left: Project, right: Project) {
|
|
const nameDiff = left.name.localeCompare(right.name, undefined, { sensitivity: "base" });
|
|
return nameDiff !== 0 ? nameDiff : left.id.localeCompare(right.id);
|
|
}
|
|
|
|
function projectTime(value: Date | string | null | undefined): number | null {
|
|
if (!value) return null;
|
|
const time = new Date(value).getTime();
|
|
return Number.isFinite(time) ? time : null;
|
|
}
|
|
|
|
function compareOptionalTime(
|
|
left: Date | string | null | undefined,
|
|
right: Date | string | null | undefined,
|
|
sortDir: ProjectSortDir,
|
|
) {
|
|
const leftTime = projectTime(left);
|
|
const rightTime = projectTime(right);
|
|
if (leftTime === null && rightTime === null) return 0;
|
|
if (leftTime === null) return 1;
|
|
if (rightTime === null) return -1;
|
|
return sortDir === "asc" ? leftTime - rightTime : rightTime - leftTime;
|
|
}
|
|
|
|
function sortProjects(projects: Project[], sortField: ProjectSortField, sortDir: ProjectSortDir) {
|
|
return [...projects].sort((left, right) => {
|
|
let comparison = 0;
|
|
if (sortField === "name") {
|
|
comparison = compareProjectNames(left, right);
|
|
return sortDir === "asc" ? comparison : -comparison;
|
|
}
|
|
|
|
if (sortField === "updated") comparison = compareOptionalTime(left.updatedAt, right.updatedAt, sortDir);
|
|
else if (sortField === "created") comparison = compareOptionalTime(left.createdAt, right.createdAt, sortDir);
|
|
else comparison = compareOptionalTime(left.targetDate, right.targetDate, sortDir);
|
|
|
|
if (comparison === 0) comparison = compareProjectNames(left, right);
|
|
return comparison;
|
|
});
|
|
}
|
|
|
|
export function Projects() {
|
|
const { selectedCompanyId } = useCompany();
|
|
const workspace = useCoordinatorWorkspaceEnabled();
|
|
const pins = usePinnedNavigation(workspace.enabled && workspace.loaded ? workspace.userId : null);
|
|
const { openNewProject } = useDialogActions();
|
|
const { setBreadcrumbs } = useBreadcrumbs();
|
|
const [query, setQuery] = useState("");
|
|
const [sortField, setSortField] = useState<ProjectSortField>("name");
|
|
const [sortDir, setSortDir] = useState<ProjectSortDir>("asc");
|
|
|
|
useEffect(() => {
|
|
setBreadcrumbs([{ label: "Projects" }]);
|
|
}, [setBreadcrumbs]);
|
|
|
|
const projectsQuery = useQuery({
|
|
...companyProjectsQuery(selectedCompanyId!),
|
|
enabled: !!selectedCompanyId,
|
|
});
|
|
const { data: allProjects, isLoading } = projectsQuery;
|
|
const projectsView = useQueryView(projectsQuery);
|
|
const membershipsQuery = useResourceMemberships(selectedCompanyId);
|
|
const membershipMutation = useResourceMembershipMutation(selectedCompanyId);
|
|
const projects = useMemo(
|
|
() => allProjects ?? [],
|
|
[allProjects],
|
|
);
|
|
const sortedProjects = useMemo(
|
|
() => {
|
|
const words = query.trim().toLocaleLowerCase().split(/\s+/).filter(Boolean);
|
|
const matching = projects.filter(project => {
|
|
const text = `${project.name} ${project.description ?? ""}`.toLocaleLowerCase();
|
|
return words.every(word => text.includes(word));
|
|
});
|
|
return sortProjects(matching, sortField, sortDir);
|
|
},
|
|
[projects, query, sortDir, sortField],
|
|
);
|
|
const groupedProjects = useMemo(() => {
|
|
const groups = {
|
|
mine: [] as typeof sortedProjects,
|
|
other: [] as typeof sortedProjects,
|
|
};
|
|
|
|
for (const project of sortedProjects) {
|
|
const state = resourceMembershipState(membershipsQuery.data, "project", project.id);
|
|
if (state === "left") groups.other.push(project);
|
|
else groups.mine.push(project);
|
|
}
|
|
|
|
return groups;
|
|
}, [membershipsQuery.data, sortedProjects]);
|
|
|
|
if (!selectedCompanyId) {
|
|
return <EmptyState icon={Hexagon} message="Select an organization to view projects." />;
|
|
}
|
|
|
|
// Keep a loaded list on screen through a failed refetch; only a real
|
|
// failure, or an outage before the first load, replaces the page.
|
|
if (isLoading || projectsView.kind === "reconnecting") {
|
|
return <PageSkeleton variant="list" />;
|
|
}
|
|
if (projectsView.kind === "error") {
|
|
return (
|
|
<QueryErrorState
|
|
size="page"
|
|
error={projectsView.error}
|
|
action="load projects"
|
|
onRetry={projectsView.retry}
|
|
retrying={projectsView.isFetching}
|
|
/>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<div className="space-y-4">
|
|
<ProjectsToolbar query={query} onQueryChange={setQuery} sortField={sortField} sortDir={sortDir}
|
|
onSortChange={(field, direction) => { setSortField(field); setSortDir(direction); }} onNewProject={openNewProject} />
|
|
|
|
{pins.error && <p role="alert" className="text-sm text-destructive">{pins.error}</p>}
|
|
|
|
{!isLoading && projects.length === 0 && (
|
|
<EmptyState
|
|
icon={Hexagon}
|
|
graphic={<ArtifactEmptyGraphic stack />}
|
|
message="No projects yet."
|
|
action="Create project"
|
|
hideActionIcon
|
|
onAction={openNewProject}
|
|
/>
|
|
)}
|
|
|
|
{projects.length > 0 && sortedProjects.length === 0 && <p className="text-sm text-muted-foreground">No projects match your search.</p>}
|
|
|
|
{sortedProjects.length > 0 && (
|
|
<div className="space-y-6">
|
|
{([
|
|
["My Projects", groupedProjects.mine],
|
|
["Other Projects", groupedProjects.other],
|
|
] as const).map(([label, sectionProjects]) => {
|
|
if (sectionProjects.length === 0) return null;
|
|
|
|
return (
|
|
<section key={label} className="space-y-2">
|
|
<div className="flex items-center justify-between">
|
|
<h2 className="text-sm font-medium">{label}</h2>
|
|
<span className="text-xs text-muted-foreground">
|
|
{sectionProjects.length} project{sectionProjects.length === 1 ? "" : "s"}
|
|
</span>
|
|
</div>
|
|
<Card className="block py-0 overflow-hidden divide-y divide-border">
|
|
{sectionProjects.map((project) => {
|
|
const state = resourceMembershipState(membershipsQuery.data, "project", project.id);
|
|
const pending = membershipMutation.isPending &&
|
|
membershipMutation.variables?.resourceType === "project" &&
|
|
membershipMutation.variables.resourceId === project.id;
|
|
const starPending = pending && membershipMutation.variables?.starred !== undefined;
|
|
const joinLeavePending = pending && membershipMutation.variables?.starred === undefined;
|
|
const starred = isStarred(membershipsQuery.data, "project", project.id);
|
|
return (
|
|
<EntityRow
|
|
key={project.id}
|
|
leading={<ProjectTile color={project.color ?? null} icon={project.icon ?? null} size="sm" />}
|
|
title={project.name}
|
|
subtitle={project.description?.trim() || undefined}
|
|
to={projectUrl(project)}
|
|
className={state === "left" ? "group min-h-14 text-foreground/55" : "group min-h-14"}
|
|
trailing={
|
|
<div className="flex items-center gap-3">
|
|
{project.visibility === "private" ? <Lock className="size-4 shrink-0 text-muted-foreground" aria-label="Private project" /> : null}
|
|
<span
|
|
className="hidden text-xs text-muted-foreground tabular-nums sm:inline"
|
|
title={`${formatNumber(project.taskCount ?? 0)} task${(project.taskCount ?? 0) === 1 ? "" : "s"}`}
|
|
>
|
|
{formatNumber(project.taskCount ?? 0)} task{(project.taskCount ?? 0) === 1 ? "" : "s"}
|
|
</span>
|
|
{project.budget && (
|
|
<span className="hidden text-xs text-muted-foreground tabular-nums sm:inline">
|
|
{formatProjectBudget(project.budget)}
|
|
</span>
|
|
)}
|
|
{project.targetDate && (
|
|
<span className="hidden text-xs text-muted-foreground md:inline">
|
|
{formatDate(project.targetDate)}
|
|
</span>
|
|
)}
|
|
<StatusBadge status={project.status} />
|
|
{pins.canPin && (
|
|
<NavigationPinButton
|
|
pinKey={projectPinKey(project)}
|
|
label={project.name}
|
|
pins={pins}
|
|
className="size-6 shrink-0 hover:bg-accent"
|
|
/>
|
|
)}
|
|
{workspace.loaded && !workspace.enabled && (
|
|
<>
|
|
<MembershipAction
|
|
state={state}
|
|
pending={joinLeavePending}
|
|
pendingState={joinLeavePending ? membershipMutation.variables?.state : null}
|
|
resourceName={project.name}
|
|
onJoin={() => membershipMutation.mutate({
|
|
resourceType: "project",
|
|
resourceId: project.id,
|
|
resourceName: project.name,
|
|
state: "joined",
|
|
})}
|
|
onLeave={() => membershipMutation.mutate({
|
|
resourceType: "project",
|
|
resourceId: project.id,
|
|
resourceName: project.name,
|
|
state: "left",
|
|
})}
|
|
/>
|
|
<StarToggle
|
|
size="row"
|
|
starred={starred}
|
|
pending={starPending}
|
|
resourceName={project.name}
|
|
onToggle={(next) => membershipMutation.mutate({
|
|
resourceType: "project",
|
|
resourceId: project.id,
|
|
resourceName: project.name,
|
|
starred: next,
|
|
})}
|
|
/>
|
|
</>
|
|
)}
|
|
</div>
|
|
}
|
|
/>
|
|
);
|
|
})}
|
|
</Card>
|
|
</section>
|
|
);
|
|
})}
|
|
</div>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|