Skip to content

Extract the template preview compile request for reuse - #534

Merged
pierre-b merged 2 commits into
devfrom
feat/compile-template-preview
Nov 12, 2026
Merged

pierre-b merged 2 commits into
devfrom
feat/compile-template-preview

Conversation

@pierre-b

@pierre-b pierre-b commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

First PR of the Broadcasts screens of the console redesign (spec 5). Console only.

What changes

  • New console/src/components/templates/compileTemplatePreview.ts:
    • buildTemplatePreviewRequest({ workspace, email, testData }) returns { request } (the templates.compile request: MJML source in code mode, the visual tree otherwise, subject, preview text, custom text when not blank, test data, tracking settings) or { error: 'missing_content' | 'invalid_tree' }. A tree string that parses to something other than an object ("null", "42") is invalid_tree and is not sent.
    • compileTemplatePreview(input) compiles it, and rejects with TemplatePreviewError (code) when no request can be built.
  • TemplatePreviewDrawer builds its request through it. Missing content still shows "Missing workspace ID or template data."; an invalid tree now always shows "Invalid template structure data." (a tree that parsed to null used to show "Template structure data is missing or invalid.").
  • The plan of the Broadcasts screens: plans/console-redesign-screens-5-broadcasts-plan.md, reviewed before any code; its review corrections are in the plan.

The Broadcasts composer and detail page, the automation email step and the transactional notification page will use it for their template previews (later PRs).

Tests

  • compileTemplatePreview.test.ts: code mode, visual mode with an object tree and a JSON string tree, unparsable tree, tree strings that parse to no object, missing content in each mode and only the editor mode's content counting, custom text only when not blank, test data, tracking settings, compile called with the request, rejection without a server call.
  • TemplatePreviewDrawer.test.tsx: the two error messages, without a compile call; existing cases unchanged.

Known, not handled

  • The doc comment of TemplatePreviewErrorCode says "a tree that is not JSON"; invalid_tree also covers JSON that is not an object.

…view a template

TemplatePreviewDrawer builds its templates.compile request through
buildTemplatePreviewRequest, and compileTemplatePreview compiles it for the
broadcast, automation and transactional screens of the console redesign.

Also adds the plan of the Broadcasts screens.
@pierre-b
pierre-b marked this pull request as ready for review November 12, 2026 15:29
@pierre-b
pierre-b merged commit 6fd8432 into dev Nov 12, 2026
4 checks passed
@codecov

codecov Bot commented Nov 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.97%. Comparing base (c8256be) to head (43eff12).
⚠️ Report is 1 commits behind head on dev.

Additional details and impacted files
@@           Coverage Diff           @@
##              dev     #534   +/-   ##
=======================================
  Coverage   88.97%   88.97%           
=======================================
  Files         377      377           
  Lines       73836    73836           
=======================================
  Hits        65692    65692           
  Misses       5435     5435           
  Partials     2709     2709           
Flag Coverage Δ
unit 88.97% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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