import "./components/ui/tidal.css"; import { useId, useRef, useState, type FormEvent } from "react"; import { TidalRuleBuilder, type TidalRuleAction, type TidalRuleActionDefinition } from "./components/ui/rule-builder"; import type { TidalQueryField, TidalQueryRule, TidalQueryConjunction } from "./components/ui/query-builder"; import "./components/ui/rule-builder.css"; import "./components/ui/query-builder.css"; const tidalExampleStyles = ".tidal-scope .rule-builder-demo {\n display: grid;\n width: min(100%, 920px);\n min-width: 0;\n gap: 12px;\n}\n\n.tidal-scope .rule-builder-demo-status,\n.tidal-scope .rule-builder-demo-note {\n min-width: 0;\n margin: 0;\n color: var(--t-muted);\n font-size: 11px;\n line-height: 1.5;\n overflow-wrap: anywhere;\n}\n\n.tidal-scope .rule-builder-demo-status {\n padding-inline-start: 2px;\n color: var(--t-ink);\n font-weight: 650;\n}\n\n.tidal-scope .rule-builder-demo-note {\n padding-block-start: 10px;\n border-block-start: 1px solid var(--t-border);\n}"; const fields: readonly TidalQueryField[] = [ { id: "plan", label: "Plan", kind: "enum", operators: [ { id: "is", label: "is" }, { id: "is-not", label: "is not" }, ], options: [ { value: "starter", label: "Starter" }, { value: "team", label: "Team" }, { value: "scale", label: "Scale" }, ], }, { id: "open-tasks", label: "Open tasks", kind: "number", operators: [ { id: "above", label: "is above" }, { id: "below", label: "is below" }, { id: "equal", label: "equals" }, ], placeholder: "0", }, { id: "project-name", label: "Project name", kind: "text", operators: [ { id: "contains", label: "contains" }, { id: "starts", label: "starts with" }, ], placeholder: "Launch", }, ]; const definitions: readonly TidalRuleActionDefinition[] = [ { id: "assign", label: "Assign owner", kind: "enum", options: [ { value: "ava", label: "Ava Chen" }, { value: "noah", label: "Noah Patel" }, { value: "mila", label: "Mila Santos" }, ], }, { id: "label", label: "Add label", kind: "text", placeholder: "Needs review", }, { id: "priority", label: "Set priority", kind: "enum", options: [ { value: "normal", label: "Normal" }, { value: "high", label: "High" }, { value: "urgent", label: "Urgent" }, ], }, { id: "pause", label: "Pause intake", kind: "none" }, ]; const initialRules: readonly TidalQueryRule[] = [ { id: "plan-team", fieldId: "plan", operatorId: "is", value: "team" }, { id: "tasks-above", fieldId: "open-tasks", operatorId: "above", value: "8", }, ]; const initialActions: readonly TidalRuleAction[] = [ { id: "owner", definitionId: "assign", value: "ava" }, { id: "review", definitionId: "label", value: "Needs review" }, ]; export function RuleBuilderDemo() { const base = useId().replace(/:/g, ""); const nextRule = useRef(0); const nextAction = useRef(0); const [rules, setRules] = useState(initialRules); const [actions, setActions] = useState(initialActions); const [conjunction, setConjunction] = useState("and"); const [status, setStatus] = useState( "Adjust the conditions and ordered actions, then save the local draft.", ); function save(event: FormEvent) { event.preventDefault(); const data = new FormData(event.currentTarget); const actionTypes = [...data.entries()].filter(([name]) => name.endsWith(".type"), ).length; setStatus( `Draft saved locally with ${rules.length} conditions and ${actionTypes} actions. Nothing was run.`, ); } return (
setConjunction(next), onRulesChange: (next) => setRules(next), createRule: () => ({ id: `${base}-condition-${++nextRule.current}`, fieldId: "plan", operatorId: "is", value: "starter", }), }} actionDefinitions={definitions} actions={actions} onActionsChange={(next) => setActions(next)} createAction={() => ({ id: `${base}-action-${++nextAction.current}`, definitionId: "assign", value: "noah", })} summary={

Draft: Match{" "} {conjunction === "and" ? "all" : "any"} of {rules.length}{" "} conditions, then run {actions.length} ordered actions.

} submitLabel="Save rule draft" onSubmit={save} /> {status}

Sample data. Changes stay in this preview and no automation runs.

); } export default function AgentExample() { return (
); }