Skip to content

feat(ui): add control template editing and creation support#159

Open
lan17 wants to merge 6 commits intolev/controltemplatesfrom
lev/controltemplates-ui
Open

feat(ui): add control template editing and creation support#159
lan17 wants to merge 6 commits intolev/controltemplatesfrom
lev/controltemplates-ui

Conversation

@lan17
Copy link
Copy Markdown
Contributor

@lan17 lan17 commented Apr 1, 2026

What this does

Adds UI support for creating and editing template-backed controls. This PR targets the lev/controltemplates branch which implements the server-side template rendering and API changes.

video:

Screen.Recording.2026-04-01.at.4.34.22.PM.mov

How it works

Creating template-backed controls: Users paste a TemplateControlInput JSON via the existing "From JSON" flow. The server discriminates template payloads from raw payloads and handles rendering transparently — no separate UI flow needed.

Editing template-backed controls: When a user opens a template-backed control, the edit modal detects template metadata and shows a dedicated editor with:

  • Parameters mode (default): auto-generated form inputs driven by the template's parameter definitions, with a collapsible rendered preview panel
  • Full JSON mode: editable textarea with the full TemplateControlInput JSON for power users
  • A read-only left panel showing the rendered control's description, action, execution, and template info

Controls list: Template-backed controls show a "Template" badge. The enable/disable toggle uses PATCH (not PUT /data) to avoid the 409 that the server returns when sending a raw ControlDefinition to a template-backed control.

New components

Component What it does
TemplateParamForm Auto-generates form inputs from template parameter definitions (string→TextInput, string_list→TagsInput, enum→Select, boolean→Switch, regex_re2→monospace TextInput)
TemplatePreview Debounced render preview that calls POST /control-templates/render and strips template/template_values from the output so users see what the engine sees
TemplateEditContent Template-backed edit modal with Parameters/Full JSON toggle, read-only summary panel, and save via TemplateControlInput payload
useRenderTemplate Mutation hook wrapping the render preview API call

Test plan

13 Playwright tests covering:

  • Template badge display and absence for raw controls
  • Parameter form rendering with fields from template definition
  • Parameters ↔ Full JSON mode switching
  • Preview panel strips template metadata from rendered output
  • Read-only summary shows rendered control info
  • Control name pre-fill and editing
  • Raw control editing regression (standard form, no template UI)
  • From JSON creation flow still works

All 123 tests pass (110 existing + 13 new), 0 regressions.

Notes

  • Template types are defined manually in types.ts until npm run fetch-api-types is run against the updated server. They can be replaced with generated types after.
  • The CreateFromTemplate modal component is included but not wired up (we decided to use "From JSON" instead of a separate creation flow). It can be removed or repurposed later.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@lan17 lan17 force-pushed the lev/controltemplates-ui branch from bb8601a to 7b3bbed Compare April 1, 2026 23:08
lan17 added 6 commits April 1, 2026 17:42
- Add template-backed control detection and "Template" badge in controls list
- Add TemplateEditContent with parameter form, read-only summary, and
  Parameters/Full JSON mode toggle for editing template-backed controls
- Add TemplateParamForm component that auto-generates form inputs from
  template parameter definitions (string, string_list, enum, boolean, regex_re2)
- Add TemplatePreview component with debounced render endpoint calls that
  strips template metadata from the preview output
- Wire enable/disable toggle to use PATCH for template-backed controls
  (avoids 409 from PUT /data on template-backed controls)
- Template-backed controls can be created via "From JSON" by pasting a
  TemplateControlInput payload
- Add template types and render API method to client (manual until
  OpenAPI types are regenerated)
- Add 13 Playwright tests covering template badge, parameter form editing,
  JSON toggle, preview stripping, and raw control regression
- Fix import sort order in template-param-form.tsx
- Fix jsx-no-leaked-render in template-preview.tsx (use ternary)
- Fix set-state-in-effect in template-edit-content.tsx by removing the
  useEffect sync and using key={control.id} to remount on control change
@lan17 lan17 force-pushed the lev/controltemplates-ui branch from 87eb82d to e192acd Compare April 2, 2026 00:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant