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>
138 lines
4.4 KiB
TypeScript
138 lines
4.4 KiB
TypeScript
"use client";
|
|
|
|
import * as React from "react";
|
|
import { ExternalLink, Loader2 } from "lucide-react";
|
|
|
|
import { Button } from "@/components/ui/button";
|
|
import { api } from "@/lib/trpc";
|
|
import { usePanelStore } from "@/lib/stores/panel-store";
|
|
import { cn } from "@/lib/utils";
|
|
|
|
import type { FormField } from "./form-renderer";
|
|
|
|
function formatCellValue(value: unknown): string {
|
|
if (value === undefined || value === null) return "—";
|
|
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
return String(value);
|
|
}
|
|
if (Array.isArray(value)) {
|
|
return value.map((x) => (typeof x === "string" ? x : JSON.stringify(x))).join(", ");
|
|
}
|
|
try {
|
|
return JSON.stringify(value);
|
|
} catch {
|
|
return "—";
|
|
}
|
|
}
|
|
|
|
function tableColumns(fields: FormField[]): FormField[] {
|
|
return fields.filter((f) => f.type !== "section_header" && f.type !== "divider");
|
|
}
|
|
|
|
export interface FormResponsesProps {
|
|
formId: string;
|
|
workspaceHandle: string;
|
|
fields: FormField[];
|
|
className?: string;
|
|
}
|
|
|
|
export function FormResponses({ formId, workspaceHandle, fields, className }: FormResponsesProps) {
|
|
const open = usePanelStore((s) => s.open);
|
|
const cols = React.useMemo(() => tableColumns(fields), [fields]);
|
|
|
|
const listQuery = api.forms.listResponses.useQuery(
|
|
{ workspace: workspaceHandle, formId },
|
|
{ enabled: Boolean(formId) && Boolean(workspaceHandle) },
|
|
);
|
|
|
|
if (listQuery.isPending) {
|
|
return (
|
|
<div className={cn("flex justify-center py-12", className)}>
|
|
<Loader2 className="size-6 animate-spin text-muted-foreground" aria-hidden />
|
|
<span className="sr-only">Loading responses</span>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
if (listQuery.isError) {
|
|
return (
|
|
<p className={cn("text-sm text-muted-foreground", className)}>
|
|
Could not load responses.
|
|
</p>
|
|
);
|
|
}
|
|
|
|
const rows = listQuery.data?.responses ?? [];
|
|
|
|
if (rows.length === 0) {
|
|
return (
|
|
<p className={cn("text-sm text-muted-foreground", className)}>No responses yet.</p>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<div className={cn("w-full overflow-x-auto rounded-md border border-border", className)}>
|
|
<table className="w-full min-w-[640px] border-collapse text-left text-sm">
|
|
<thead>
|
|
<tr className="border-b border-border bg-muted/40">
|
|
{cols.map((f) => (
|
|
<th
|
|
key={f.id}
|
|
className="whitespace-nowrap px-3 py-2 font-medium text-muted-foreground"
|
|
>
|
|
{f.label}
|
|
</th>
|
|
))}
|
|
<th className="whitespace-nowrap px-3 py-2 font-medium text-muted-foreground">
|
|
Submitted
|
|
</th>
|
|
<th className="whitespace-nowrap px-3 py-2 font-medium text-muted-foreground">
|
|
Task
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{rows.map((row) => {
|
|
const data =
|
|
row.data && typeof row.data === "object" && row.data !== null
|
|
? (row.data as Record<string, unknown>)
|
|
: {};
|
|
|
|
const submitted =
|
|
row.submittedAt instanceof Date
|
|
? row.submittedAt.toLocaleString()
|
|
: String(row.submittedAt ?? "—");
|
|
|
|
return (
|
|
<tr key={row.id} className="border-b border-border last:border-0">
|
|
{cols.map((f) => (
|
|
<td key={f.id} className="max-w-[240px] truncate px-3 py-2 align-top">
|
|
{formatCellValue(data[f.id])}
|
|
</td>
|
|
))}
|
|
<td className="whitespace-nowrap px-3 py-2 align-top text-muted-foreground">
|
|
{submitted}
|
|
</td>
|
|
<td className="px-3 py-2 align-top">
|
|
{row.createdObjectId ? (
|
|
<Button
|
|
type="button"
|
|
variant="link"
|
|
className="inline-flex h-auto items-center gap-1 p-0 text-primary"
|
|
onClick={() => open("object-detail", row.createdObjectId)}
|
|
>
|
|
Open task
|
|
<ExternalLink className="size-3.5 opacity-70" aria-hidden />
|
|
</Button>
|
|
) : (
|
|
<span className="text-muted-foreground">—</span>
|
|
)}
|
|
</td>
|
|
</tr>
|
|
);
|
|
})}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
);
|
|
}
|