"use client"; /** * GroupBuilder — group specs (docs/api/databases.md §5.4): * [{ propertyId, direction }] (0–3 levels; board/table/list/gallery). * Board views require the group property to be select/status/multi_select/ * person/date (server validates → 422 otherwise); we surface a hint. */ import { Plus, X } from "lucide-react"; import { cn } from "@/lib/utils"; import { DatabaseProperty, GroupSpec } from "@/hooks/use-database"; const inputCls = "rounded border border-input bg-background px-1.5 py-0.5 text-xs outline-none focus-visible:ring-1 focus-visible:ring-ring"; /** Property types the server accepts as group keys (board). */ export const GROUPABLE_TYPES = new Set(["select", "status", "multi_select", "person", "date"]); export function isGroupable(p: DatabaseProperty): boolean { return GROUPABLE_TYPES.has(p.type); } export interface GroupBuilderProps { value: GroupSpec[] | null; onChange: (group: GroupSpec[] | null) => void; properties: DatabaseProperty[]; /** Board views restrict group keys to select/status/multi_select/person/date. */ viewType?: string; className?: string; } export function GroupBuilder({ value, onChange, properties, viewType, className }: GroupBuilderProps) { const groups = value ?? []; const used = new Set(groups.map((g) => g.propertyId)); const allCandidates = viewType === "board" ? properties.filter(isGroupable) : properties; const available = allCandidates.filter((p) => !used.has(p.id)); if (allCandidates.length === 0) { return (
{viewType === "board" ? "Group by a select, status, multi-select, person or date property (add one first)." : "Add properties before grouping."}
); } return (No grouping — records render in view order.
}