"use client"; /** * SortBuilder โ ordered sort specs (docs/api/databases.md ยง5.4): * [{ propertyId, direction }] (0โ8 entries, stable; ties by position/id). * Pure editor; the query engine applies sorting server-side. */ import { ArrowDown, ArrowUp, Plus, X } from "lucide-react"; import { cn } from "@/lib/utils"; import { DatabaseProperty, SortSpec } 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"; export interface SortBuilderProps { value: SortSpec[] | null; onChange: (sort: SortSpec[] | null) => void; properties: DatabaseProperty[]; className?: string; } export function SortBuilder({ value, onChange, properties, className }: SortBuilderProps) { const sorts = value ?? []; const usedProps = new Set(sorts.map((s) => s.propertyId)); const available = properties.filter((p) => !usedProps.has(p.id) || p.isTitle); if (properties.length === 0) { return
Add properties before sorting.
; } return (No sorts โ records stay in position order.
}