mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-13 15:55:46 +01:00
## Thinking Path
> - Paperclip is the open source app people use to manage AI agents for
work
> - The board UI reads the company project list in many places: the
sidebar, starred projects, the command palette, the new-task dialog, and
archive-aware pages such as the Mine inbox
> - Active-only consumers read `GET /projects`, and archive-aware ones
read `GET /projects?includeArchived=true`, under two React Query keys
> - A Mine load therefore fetched the same large payload twice (580–590
KB each on our dev instance)
> - The two responses differ only by archived rows; the server's active
list is exactly the rows where `archivedAt` is null
> - This pull request makes every consumer share the
`includeArchived=true` query, and active-only consumers filter it with
`select`
> - The benefit is one project read per page instead of two
## Linked Issues or Issue Description
**What existing behavior does this improve?**
Duplicate project list reads on page load.
**Subsystem affected**
Board UI project queries (`ui/src/lib/company-projects-query.ts` and its
consumers).
**Current behavior**
A cold Mine load sends both `/companies/:id/projects` (sidebar) and
`/companies/:id/projects?includeArchived=true` (inbox).
**Proposed behavior**
One `includeArchived=true` read serves both. Active-only consumers apply
`selectActiveProjects`.
**Reason and benefit**
The project list is one of the largest shell payloads. Reading it once
saves a large response on every page that has both kinds of consumer.
## What Changed
- New `companyProjectsQuery(companyId, { includeArchived? })` in
`ui/src/lib/company-projects-query.ts`. It always uses the
`includeArchived: true` key and fetch. For active-only use it adds a
stable, module-level `select` that keeps rows without `archivedAt`.
- 22 files that read the active list now spread
`companyProjectsQuery(...)`, and so do the plugin SDK project picker and
16 archive-aware pages that wrote the shared key and fetcher inline.
Their `enabled` and other options are unchanged. `OnboardingWizard`'s
one imperative read is unchanged. `pages/Inbox.tsx` already reads the
same key and fetcher, so it shares the entry without an edit.
- Invalidation: project mutations and live events invalidate
`queryKeys.projects.all(companyId)`, which matches the shared key. The
onboarding wizard invalidated the old active-only key; it now
invalidates `projects.all`.
- Tests: new `company-projects-query.test.tsx` (one request for both
consumers, correct filtering, and one refetch after `projects.all`
invalidation). Three existing tests (`CommandPalette`, `CompanyExport`,
`GitHubBotManagement`) now seed or expect the shared key.
- New browser check
`tests/perf/collections/shared-project-list.spec.ts`: after the Mine
inbox read completes, the page has sent no active-only project request.
## Verification
- `pnpm verify` passes.
- `ui`: the consumer suites (`CoordinatorSidebar`, `SidebarProjects`,
`SidebarStarredProjects`, `CommandPalette`, `NewIssueDialog`,
`AgentWorkPanels`, `CoordinatorNeedsYou`, `IssueDetail`,
`ProjectDetail`, `Projects`, `CompanyExport`, `ChatExecutionDefaults`,
`GatewaysList`, `Search`, `IssueProperties`, `persisted-query-cache`)
pass.
- Browser check:
`PAPERCLIP_COLLECTION_PERF_BASE_URL=http://127.0.0.1:<port> pnpm exec
playwright test --config tests/perf/collections/playwright.config.ts
shared-project-list.spec.ts`. It passes on this branch and fails on
`master`.
## Risks
- A page that needs only active projects now downloads archived rows
too. For most companies that is a small difference; the duplicate read
it removes is a full copy.
- The server does not order either list, and consumers sort for display,
so filtering on the client keeps behavior.
## Model Used
- Claude Opus 5.5 (`claude-opus-5-5`), Anthropic, via Claude Code with
tool use (shell, file edits, browser). 1M-token context window. Extended
thinking was off.
## 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
- [ ] All Paperclip CI gates are green
- [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
228 lines
7.6 KiB
TypeScript
228 lines
7.6 KiB
TypeScript
import { companyProjectsQuery } from "@/lib/company-projects-query";
|
|
import { useEffect } from "react";
|
|
import { useParams } from "@/lib/router";
|
|
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
|
|
import { goalsApi } from "../api/goals";
|
|
import { assetsApi } from "../api/assets";
|
|
import { usePanel } from "../context/PanelContext";
|
|
import { useCompany } from "../context/CompanyContext";
|
|
import { useDialogActions } from "../context/DialogContext";
|
|
import { useBreadcrumbs } from "../context/BreadcrumbContext";
|
|
import { queryKeys } from "../lib/queryKeys";
|
|
import { GoalProperties } from "../components/GoalProperties";
|
|
import { GoalTree } from "../components/GoalTree";
|
|
import { StatusBadge } from "../components/StatusBadge";
|
|
import { InlineEditor } from "../components/InlineEditor";
|
|
import { EntityRow } from "../components/EntityRow";
|
|
import { PageSkeleton } from "../components/PageSkeleton";
|
|
import { QueryErrorState, useQueryView } from "../components/QueryView";
|
|
import { cn, projectUrl } from "../lib/utils";
|
|
import { Button } from "@/components/ui/button";
|
|
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
|
|
import { Plus, SlidersHorizontal } from "lucide-react";
|
|
import type { Goal, Project } from "@paperclipai/shared";
|
|
|
|
interface GoalPropertiesToggleButtonProps {
|
|
panelVisible: boolean;
|
|
onShowProperties: () => void;
|
|
}
|
|
|
|
export function GoalPropertiesToggleButton({
|
|
panelVisible,
|
|
onShowProperties,
|
|
}: GoalPropertiesToggleButtonProps) {
|
|
return (
|
|
<Button
|
|
variant="ghost"
|
|
size="icon-xs"
|
|
className={cn(
|
|
"hidden md:inline-flex shrink-0 transition-opacity duration-200",
|
|
panelVisible ? "opacity-0 pointer-events-none w-0 overflow-hidden" : "opacity-100",
|
|
)}
|
|
onClick={onShowProperties}
|
|
title="Show properties"
|
|
>
|
|
<SlidersHorizontal className="h-4 w-4" />
|
|
</Button>
|
|
);
|
|
}
|
|
|
|
export function GoalDetail() {
|
|
const { goalId } = useParams<{ goalId: string }>();
|
|
const { selectedCompanyId, setSelectedCompanyId } = useCompany();
|
|
const { openNewGoal } = useDialogActions();
|
|
const { openPanel, closePanel, panelVisible, setPanelVisible } = usePanel();
|
|
const { setBreadcrumbs } = useBreadcrumbs();
|
|
const queryClient = useQueryClient();
|
|
|
|
const goalQuery = useQuery({
|
|
queryKey: queryKeys.goals.detail(goalId!),
|
|
queryFn: () => goalsApi.get(goalId!),
|
|
enabled: !!goalId
|
|
});
|
|
const { data: goal, isLoading, error } = goalQuery;
|
|
const goalView = useQueryView(goalQuery);
|
|
const resolvedCompanyId = goal?.companyId ?? selectedCompanyId;
|
|
|
|
const { data: allGoals } = useQuery({
|
|
queryKey: queryKeys.goals.list(resolvedCompanyId!),
|
|
queryFn: () => goalsApi.list(resolvedCompanyId!),
|
|
enabled: !!resolvedCompanyId
|
|
});
|
|
|
|
const { data: allProjects } = useQuery({
|
|
...companyProjectsQuery(resolvedCompanyId!, { includeArchived: true }),
|
|
enabled: !!resolvedCompanyId
|
|
});
|
|
|
|
useEffect(() => {
|
|
if (!goal?.companyId || goal.companyId === selectedCompanyId) return;
|
|
setSelectedCompanyId(goal.companyId, { source: "route_sync" });
|
|
}, [goal?.companyId, selectedCompanyId, setSelectedCompanyId]);
|
|
|
|
const updateGoal = useMutation({
|
|
mutationFn: (data: Record<string, unknown>) =>
|
|
goalsApi.update(goalId!, data),
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries({
|
|
queryKey: queryKeys.goals.detail(goalId!)
|
|
});
|
|
if (resolvedCompanyId) {
|
|
queryClient.invalidateQueries({
|
|
queryKey: queryKeys.goals.list(resolvedCompanyId)
|
|
});
|
|
}
|
|
}
|
|
});
|
|
|
|
const uploadImage = useMutation({
|
|
mutationFn: async (file: File) => {
|
|
if (!resolvedCompanyId) throw new Error("No organization selected");
|
|
return assetsApi.uploadImage(
|
|
resolvedCompanyId,
|
|
file,
|
|
`goals/${goalId ?? "draft"}`
|
|
);
|
|
}
|
|
});
|
|
|
|
const childGoals = (allGoals ?? []).filter((g) => g.parentId === goalId);
|
|
const linkedProjects = (allProjects ?? []).filter((p) => {
|
|
if (!goalId) return false;
|
|
if (p.goalIds.includes(goalId)) return true;
|
|
if (p.goals.some((goalRef) => goalRef.id === goalId)) return true;
|
|
return p.goalId === goalId;
|
|
});
|
|
|
|
useEffect(() => {
|
|
setBreadcrumbs([
|
|
{ label: "Goals", href: "/goals" },
|
|
{ label: goal?.title ?? goalId ?? "Goal" }
|
|
]);
|
|
}, [setBreadcrumbs, goal, goalId]);
|
|
|
|
useEffect(() => {
|
|
if (goal) {
|
|
openPanel(
|
|
<GoalProperties
|
|
goal={goal}
|
|
onUpdate={(data) => updateGoal.mutate(data)}
|
|
/>
|
|
);
|
|
}
|
|
return () => closePanel();
|
|
}, [goal]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
|
|
if (isLoading || goalView.kind === "reconnecting") return <PageSkeleton variant="detail" />;
|
|
if (goalView.kind === "error") {
|
|
return <QueryErrorState size="page" error={error} action="load this goal" onRetry={goalView.retry} retrying={goalView.isFetching} />;
|
|
}
|
|
if (!goal) return null;
|
|
|
|
return (
|
|
<div className="space-y-6">
|
|
<div className="space-y-3">
|
|
<div className="flex items-center gap-2">
|
|
<span className="text-xs uppercase text-muted-foreground">
|
|
{goal.level}
|
|
</span>
|
|
<StatusBadge status={goal.status} />
|
|
<div className="ml-auto">
|
|
<GoalPropertiesToggleButton
|
|
panelVisible={panelVisible}
|
|
onShowProperties={() => setPanelVisible(true)}
|
|
/>
|
|
</div>
|
|
</div>
|
|
|
|
<InlineEditor
|
|
value={goal.title}
|
|
onSave={(title) => updateGoal.mutate({ title })}
|
|
as="h2"
|
|
className="text-xl font-bold"
|
|
/>
|
|
|
|
<InlineEditor
|
|
value={goal.description ?? ""}
|
|
onSave={(description) => updateGoal.mutate({ description })}
|
|
as="p"
|
|
className="text-sm text-muted-foreground"
|
|
placeholder="Add a description..."
|
|
multiline
|
|
imageUploadHandler={async (file) => {
|
|
const asset = await uploadImage.mutateAsync(file);
|
|
return asset.contentPath;
|
|
}}
|
|
/>
|
|
</div>
|
|
|
|
<Tabs defaultValue="children">
|
|
<TabsList>
|
|
<TabsTrigger value="children">
|
|
Sub-Goals ({childGoals.length})
|
|
</TabsTrigger>
|
|
<TabsTrigger value="projects">
|
|
Projects ({linkedProjects.length})
|
|
</TabsTrigger>
|
|
</TabsList>
|
|
|
|
<TabsContent value="children" className="mt-4 space-y-3">
|
|
<div className="flex items-center justify-start">
|
|
<Button
|
|
size="sm"
|
|
variant="outline"
|
|
onClick={() => openNewGoal({ parentId: goalId })}
|
|
>
|
|
<Plus className="h-3.5 w-3.5 mr-1.5" />
|
|
Sub Goal
|
|
</Button>
|
|
</div>
|
|
{childGoals.length === 0 ? (
|
|
<p className="text-sm text-muted-foreground">No sub-goals.</p>
|
|
) : (
|
|
<GoalTree goals={childGoals} goalLink={(g) => `/goals/${g.id}`} />
|
|
)}
|
|
</TabsContent>
|
|
|
|
<TabsContent value="projects" className="mt-4">
|
|
{linkedProjects.length === 0 ? (
|
|
<p className="text-sm text-muted-foreground">No linked projects.</p>
|
|
) : (
|
|
<div className="border border-border">
|
|
{linkedProjects.map((project) => (
|
|
<EntityRow
|
|
key={project.id}
|
|
title={project.name}
|
|
subtitle={project.description ?? undefined}
|
|
to={projectUrl(project)}
|
|
trailing={<StatusBadge status={project.status} />}
|
|
/>
|
|
))}
|
|
</div>
|
|
)}
|
|
</TabsContent>
|
|
</Tabs>
|
|
</div>
|
|
);
|
|
}
|