/** * The update list of one attached state. Each update applies AFTER the run: either * a template `update` jq (picked by name, whose declared input is authored through * the adapter mapping) or a custom jq over `{ record, output, input }` that authors * the whole op batch itself. An optional op-id expression carries idempotency. */ import type { ReactNode } from 'react'; import { Badge } from '../components/badge'; import { Field } from '../components/field'; import { CloseIcon } from '../components/icons'; import { Button } from '../components/primitives'; import { Select } from '../components/select'; import { TemplatedTextField } from '../components/templated-text-field'; import { AdapterMapping } from './AdapterMapping'; import type { TemplateJqSuggestion } from './BindingJqField'; import { BindingTemplatedJqField } from './BindingTemplatedJqField'; import { findByRef, type ResolvedTemplateJq } from './catalog'; import type { BindingSourceSchemas, StateUpdate, TemplatedTextCatalog } from './types'; const CUSTOM = '__custom__'; function optionLabel(entry: ResolvedTemplateJq): string { return entry.description !== undefined && entry.description !== '' ? `${entry.ref} — ${entry.description}` : entry.ref; } function writesLabel(entry: ResolvedTemplateJq | undefined): string | null { if (entry?.writes === undefined || entry.writes.length === 0) return null; return entry.writes.map((path) => path.join('.')).join(', '); } function UpdateRowEditor({ update, index, updateJq, sources, suggestions, templates, onChange, onRemove, }: { readonly update: StateUpdate; readonly index: number; readonly updateJq: readonly ResolvedTemplateJq[]; readonly sources?: BindingSourceSchemas; readonly suggestions?: readonly TemplateJqSuggestion[]; readonly templates?: TemplatedTextCatalog; readonly onChange: (update: StateUpdate) => void; readonly onRemove: () => void; }): ReactNode { const isCustom = update.jq !== null; const selectValue = isCustom ? CUSTOM : (update.template_jq ?? ''); const resolved = update.template_jq !== null ? findByRef(update.template_jq, updateJq) : undefined; const writes = writesLabel(resolved); return (