feat: add project workspaces (DB, API, service, and UI)
New project_workspaces table with primary workspace designation. Full CRUD routes, service with auto-primary promotion on delete, workspace management UI in project properties panel, and workspace data included in project/issue ancestor responses. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,16 +1,17 @@
|
||||
import { useState } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import type { Project } from "@paperclip/shared";
|
||||
import { StatusBadge } from "./StatusBadge";
|
||||
import { formatDate } from "../lib/utils";
|
||||
import { goalsApi } from "../api/goals";
|
||||
import { projectsApi } from "../api/projects";
|
||||
import { useCompany } from "../context/CompanyContext";
|
||||
import { queryKeys } from "../lib/queryKeys";
|
||||
import { Separator } from "@/components/ui/separator";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
|
||||
import { Plus, X } from "lucide-react";
|
||||
import { Plus, Star, Trash2, X } from "lucide-react";
|
||||
|
||||
interface ProjectPropertiesProps {
|
||||
project: Project;
|
||||
@@ -28,7 +29,11 @@ function PropertyRow({ label, children }: { label: string; children: React.React
|
||||
|
||||
export function ProjectProperties({ project, onUpdate }: ProjectPropertiesProps) {
|
||||
const { selectedCompanyId } = useCompany();
|
||||
const queryClient = useQueryClient();
|
||||
const [goalOpen, setGoalOpen] = useState(false);
|
||||
const [workspaceName, setWorkspaceName] = useState("");
|
||||
const [workspaceCwd, setWorkspaceCwd] = useState("");
|
||||
const [workspaceRepoUrl, setWorkspaceRepoUrl] = useState("");
|
||||
|
||||
const { data: allGoals } = useQuery({
|
||||
queryKey: queryKeys.goals.list(selectedCompanyId!),
|
||||
@@ -50,6 +55,35 @@ export function ProjectProperties({ project, onUpdate }: ProjectPropertiesProps)
|
||||
}));
|
||||
|
||||
const availableGoals = (allGoals ?? []).filter((g) => !linkedGoalIds.includes(g.id));
|
||||
const workspaces = project.workspaces ?? [];
|
||||
|
||||
const invalidateProject = () => {
|
||||
queryClient.invalidateQueries({ queryKey: queryKeys.projects.detail(project.id) });
|
||||
if (selectedCompanyId) {
|
||||
queryClient.invalidateQueries({ queryKey: queryKeys.projects.list(selectedCompanyId) });
|
||||
}
|
||||
};
|
||||
|
||||
const createWorkspace = useMutation({
|
||||
mutationFn: (data: Record<string, unknown>) => projectsApi.createWorkspace(project.id, data),
|
||||
onSuccess: () => {
|
||||
setWorkspaceName("");
|
||||
setWorkspaceCwd("");
|
||||
setWorkspaceRepoUrl("");
|
||||
invalidateProject();
|
||||
},
|
||||
});
|
||||
|
||||
const updateWorkspace = useMutation({
|
||||
mutationFn: (input: { workspaceId: string; data: Record<string, unknown> }) =>
|
||||
projectsApi.updateWorkspace(project.id, input.workspaceId, input.data),
|
||||
onSuccess: invalidateProject,
|
||||
});
|
||||
|
||||
const removeWorkspace = useMutation({
|
||||
mutationFn: (workspaceId: string) => projectsApi.removeWorkspace(project.id, workspaceId),
|
||||
onSuccess: invalidateProject,
|
||||
});
|
||||
|
||||
const removeGoal = (goalId: string) => {
|
||||
if (!onUpdate) return;
|
||||
@@ -62,6 +96,16 @@ export function ProjectProperties({ project, onUpdate }: ProjectPropertiesProps)
|
||||
setGoalOpen(false);
|
||||
};
|
||||
|
||||
const submitWorkspace = () => {
|
||||
if (!workspaceName.trim() || !workspaceCwd.trim()) return;
|
||||
createWorkspace.mutate({
|
||||
name: workspaceName.trim(),
|
||||
cwd: workspaceCwd.trim(),
|
||||
repoUrl: workspaceRepoUrl.trim() || null,
|
||||
isPrimary: workspaces.length === 0,
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<div className="space-y-1">
|
||||
@@ -148,6 +192,83 @@ export function ProjectProperties({ project, onUpdate }: ProjectPropertiesProps)
|
||||
<Separator />
|
||||
|
||||
<div className="space-y-1">
|
||||
<div className="py-1.5 space-y-2">
|
||||
<div className="text-xs text-muted-foreground">Workspaces</div>
|
||||
{workspaces.length === 0 ? (
|
||||
<p className="text-sm text-muted-foreground">No project workspaces configured.</p>
|
||||
) : (
|
||||
<div className="space-y-2">
|
||||
{workspaces.map((workspace) => (
|
||||
<div key={workspace.id} className="rounded-md border border-border p-2 space-y-1">
|
||||
<div className="flex items-center justify-between gap-2">
|
||||
<span className="text-sm font-medium truncate">{workspace.name}</span>
|
||||
<div className="flex items-center gap-1">
|
||||
{workspace.isPrimary ? (
|
||||
<span className="inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] border border-border text-muted-foreground">
|
||||
<Star className="h-2.5 w-2.5" />
|
||||
Primary
|
||||
</span>
|
||||
) : (
|
||||
<Button
|
||||
variant="outline"
|
||||
size="xs"
|
||||
className="h-5 px-1.5 text-[10px]"
|
||||
onClick={() => updateWorkspace.mutate({ workspaceId: workspace.id, data: { isPrimary: true } })}
|
||||
>
|
||||
Set primary
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-xs"
|
||||
onClick={() => removeWorkspace.mutate(workspace.id)}
|
||||
aria-label={`Delete workspace ${workspace.name}`}
|
||||
>
|
||||
<Trash2 className="h-3 w-3" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
<p className="text-xs font-mono text-muted-foreground break-all">{workspace.cwd}</p>
|
||||
{workspace.repoUrl && (
|
||||
<p className="text-xs text-muted-foreground truncate">{workspace.repoUrl}</p>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
<div className="space-y-1.5 rounded-md border border-border p-2">
|
||||
<input
|
||||
className="w-full rounded border border-border bg-transparent px-2 py-1 text-xs outline-none"
|
||||
value={workspaceName}
|
||||
onChange={(e) => setWorkspaceName(e.target.value)}
|
||||
placeholder="Workspace name"
|
||||
/>
|
||||
<input
|
||||
className="w-full rounded border border-border bg-transparent px-2 py-1 text-xs font-mono outline-none"
|
||||
value={workspaceCwd}
|
||||
onChange={(e) => setWorkspaceCwd(e.target.value)}
|
||||
placeholder="/absolute/path/to/workspace"
|
||||
/>
|
||||
<input
|
||||
className="w-full rounded border border-border bg-transparent px-2 py-1 text-xs outline-none"
|
||||
value={workspaceRepoUrl}
|
||||
onChange={(e) => setWorkspaceRepoUrl(e.target.value)}
|
||||
placeholder="Repo URL (optional)"
|
||||
/>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="xs"
|
||||
className="h-6 px-2"
|
||||
disabled={!workspaceName.trim() || !workspaceCwd.trim() || createWorkspace.isPending}
|
||||
onClick={submitWorkspace}
|
||||
>
|
||||
Add workspace
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Separator />
|
||||
|
||||
<PropertyRow label="Created">
|
||||
<span className="text-sm">{formatDate(project.createdAt)}</span>
|
||||
</PropertyRow>
|
||||
|
||||
Reference in New Issue
Block a user