"use client"; import { useMemo, useState } from "react"; import { buildBases, type BaseViewType, type BaseFilterScope } from "@/lib/tools/bases"; import { CodeOutput } from "@/components/tools/CodeOutput"; const VIEW_TYPES: BaseViewType[] = ["table", "cards", "list", "map"]; const SCOPES: { id: BaseFilterScope; label: string }[] = [ { id: "none", label: "без фильтра" }, { id: "folder", label: "по папке" }, { id: "tag", label: "по тегу" }, { id: "property", label: "по свойству (выражение)" }, ]; const field = "w-full p-2 text-sm"; const fieldStyle = { border: "1px solid var(--border)", borderRadius: "2px", backgroundColor: "var(--background)", color: "var(--foreground)" } as const; const SCOPE_PLACEHOLDER: Record = { none: "", folder: "Projects", tag: "#проект", property: 'status == "done"', }; export function BasesForm() { const [viewType, setViewType] = useState("table"); const [viewName, setViewName] = useState("Мои заметки"); const [propsText, setPropsText] = useState("file.name, status"); const [filterScope, setFilterScope] = useState("folder"); const [filterValue, setFilterValue] = useState("Projects"); const [sortBy, setSortBy] = useState("file.name"); const [sortDir, setSortDir] = useState<"ASC" | "DESC">("ASC"); const [groupBy, setGroupBy] = useState(""); const [limit, setLimit] = useState(""); const yaml = useMemo( () => buildBases({ viewType, viewName, properties: propsText.split(",").map((s) => s.trim()).filter(Boolean), filterScope, filterValue, sortBy, sortDir, groupBy, limit: limit ? Number(limit) : undefined, }), [viewType, viewName, propsText, filterScope, filterValue, sortBy, sortDir, groupBy, limit], ); return (
{filterScope !== "none" && ( setFilterValue(e.target.value)} /> )}
); }