Block A of the EchoDo plan. Workspaces used to live as `objects(type='workspace')`,
which made it impossible to put a real RLS-friendly tenant boundary on the schema
or to give each workspace a stable URL slug. This commit:
- Adds a top-level `workspaces` table (slug unique, owner FK, plan_tier hook).
- Migrates the 8 anchor tables (objects, workspace_members, object_type_defs,
property_definitions, templates, forms, markdown_backlog_items,
cursor_sync_mappings) to FK into `workspaces.id` instead of `objects.id`,
with a hand-augmented data-copy migration that preserves IDs and slug-collision-
proofs on backfill.
- Introduces a `workspaceProcedure` tRPC middleware + `resolveWorkspace` helper
that take a UUID-or-slug `workspace` handle and expose `ctx.workspace`. All
tenant-scoped routers (objects, types, properties, templates, forms, search,
ai, relations, favorites) now flow through it.
- Updates the web app to pass `workspace` slugs from the URL (or store) instead
of the old `workspaceId`, including a workspace-sync layer that rewrites
/<UUID>/... links to /<slug>/...
- Updates the MCP tools (list_objects, create_object, search_objects) and the
workspace://{handle}/tree resource to accept either a slug or UUID so existing
agents keep working.
- Adds a Create Workspace dialog and a Workspace Settings page (rename + slug
rename with redirect, owner-only archive).
Verified locally against a fresh Postgres: migration applies cleanly, slug
uniqueness holds, tenant data is isolated by workspace_id, slug↔UUID resolution
works in both directions, and ON DELETE CASCADE cleans up child rows in the
correct workspace only.
Co-authored-by: Cursor <cursoragent@cursor.com>
100 lines
3.6 KiB
TypeScript
100 lines
3.6 KiB
TypeScript
"use client";
|
|
|
|
import { useParams, useRouter } from "next/navigation";
|
|
import { Plus, PenTool, Loader2 } from "lucide-react";
|
|
import { Button } from "@/components/ui/button";
|
|
import { api } from "@/lib/trpc";
|
|
|
|
export default function WhiteboardsPage() {
|
|
const params = useParams();
|
|
const router = useRouter();
|
|
const workspaceSlug = params.workspaceSlug as string;
|
|
|
|
const { data, isLoading } = api.objects.list.useQuery(
|
|
{ workspace: workspaceSlug, type: "whiteboard", limit: 200 },
|
|
{ enabled: Boolean(workspaceSlug) },
|
|
);
|
|
|
|
const createMutation = api.objects.create.useMutation({
|
|
onSuccess: (newObj) => {
|
|
router.push(`/${workspaceSlug}/whiteboards/${newObj.id}`);
|
|
},
|
|
});
|
|
|
|
const whiteboards = data?.objects ?? [];
|
|
|
|
return (
|
|
<div className="flex h-full flex-col">
|
|
<div className="flex shrink-0 items-center justify-between border-b px-6 py-4">
|
|
<div className="flex items-center gap-3">
|
|
<div className="flex h-9 w-9 items-center justify-center rounded-lg bg-primary/10">
|
|
<PenTool className="size-5 text-primary" />
|
|
</div>
|
|
<h1 className="text-lg font-semibold">Whiteboards</h1>
|
|
</div>
|
|
<Button
|
|
size="sm"
|
|
className="gap-1.5"
|
|
onClick={() =>
|
|
createMutation.mutate({
|
|
type: "whiteboard",
|
|
title: "Untitled Whiteboard",
|
|
workspace: workspaceSlug,
|
|
})
|
|
}
|
|
disabled={createMutation.isPending}
|
|
>
|
|
<Plus className="size-4" />
|
|
New Whiteboard
|
|
</Button>
|
|
</div>
|
|
|
|
<div className="flex-1 overflow-y-auto p-6">
|
|
{isLoading ? (
|
|
<div className="flex items-center justify-center py-20">
|
|
<Loader2 className="size-6 animate-spin text-muted-foreground" />
|
|
</div>
|
|
) : whiteboards.length === 0 ? (
|
|
<div className="flex flex-col items-center justify-center gap-3 rounded-lg border border-dashed py-20 text-muted-foreground">
|
|
<PenTool className="size-10 opacity-40" />
|
|
<p className="text-sm">No whiteboards yet</p>
|
|
<Button
|
|
variant="outline"
|
|
size="sm"
|
|
className="gap-1.5"
|
|
onClick={() =>
|
|
createMutation.mutate({
|
|
type: "whiteboard",
|
|
title: "Untitled Whiteboard",
|
|
workspace: workspaceSlug,
|
|
})
|
|
}
|
|
>
|
|
<Plus className="size-4" />
|
|
Create your first whiteboard
|
|
</Button>
|
|
</div>
|
|
) : (
|
|
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4">
|
|
{whiteboards.map((wb) => (
|
|
<button
|
|
key={wb.id}
|
|
type="button"
|
|
onClick={() => router.push(`/${workspaceSlug}/whiteboards/${wb.id}`)}
|
|
className="group flex flex-col gap-2 rounded-lg border bg-card p-4 text-left transition-colors hover:border-primary/40 hover:bg-accent/50"
|
|
>
|
|
<div className="flex h-32 w-full items-center justify-center rounded-md bg-muted">
|
|
<PenTool className="size-8 text-muted-foreground/40" />
|
|
</div>
|
|
<p className="truncate text-sm font-medium">{wb.title || "Untitled"}</p>
|
|
<p className="text-xs text-muted-foreground">
|
|
{new Date(wb.updatedAt ?? wb.createdAt).toLocaleDateString()}
|
|
</p>
|
|
</button>
|
|
))}
|
|
</div>
|
|
)}
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|