Skip to content
SprecherEast
Issue 640

feat: Chart block for posts and events, with a Markdown converter for agents

Back to our plan
Done
enhancementfrontendcmsvisualizationpriority: highshared-component

Re-scoped 2026-11-03 (#645): the owner (Amine, 2026-11-03, Claude in Chrome side panel, text) asked for more charts, diagrams and infographics so a neighbor who knows nothing about taxes can follow the 2027 budget post, and told us to be inventive and think unconventionally. This issue now ships the MUST chart kinds units and stacked (and bar), with the Markdown tag, and raises the post body cap in SUGGESTION_CAPS and suggestion.schema.json from 3,000 to 12,000 characters (the budget post's Markdown is about 4 to 5 KB), with the JSON-versus-Zod contract test updated. Other kinds follow later. Depends on #639 and #663.

Problem

In plain words: editors and agents need to put a chart in a post or an event, by filling in a few rows of numbers in Admin, or by writing one tag in an agent's Markdown draft.

Summary of the owner's request (2026-11-02, Claude conversation, text): he wants graphs and diagrams that look good. The owner (Amine, 2026-11-03, Claude Code session, text) asked for the chart to be a common component across the app.

Today (checked 2026-11-03):

  • Blocks. Editorial blocks are configured in src/platform/richtext/editorial/*BlockConfig.ts, mapped by to…Props, and registered in EDITORIAL_BLOCKS and richTextBlocks.tsx.
  • Markdown. Payload 3.91.0's block jsx converter writes array and object props as prop={[...]} (propsToJSXString, package source). Converters for the other blocks come with #593.
  • Depends on sub-issue 1 (Chart and ChartSpec).

Proposed fix

  • chartBlockConfig.ts:
    • title, summary (required: the takeaway in words), kind, a display or orientation shown by kind (admin.condition), unit, as of
    • certainty (reused)
    • sources (linkFields)
    • rows (label, series key, value, note; at most 60)
    • links (from, to, value; only for flow, added in 3)
  • chart.ts: toChartSpec(stored) returns a valid ChartSpec, or the field error from the zod schema. A share that doesn't add to 100 ± 0.5 or a negative value is refused on save.
  • Register it in EDITORIAL_BLOCKS (posts and events) and in richTextBlocks.tsx (<Chart className="col-start-2" spec={toChartSpec(node.fields)} />).
  • jsx converter. <Chart kind="…" title="…" summary="…" unit="…" data={[…]} /> (or x={[…]} series={[…]}). Import validates with the same schema, so submitSuggestion returns the error to the agent. The tag goes in intelligence/prompts/draft.md with one example.
  • Watch out: src/platform/richtext/ is used by every post and event. Check that the existing blocks still render.

Native first, one line per step:

  1. Native: Payload BlocksFeature, field validation, admin.condition and the block jsx converter.
  2. Official plugins: none.
  3. Open source: none beyond sub-issue 1.
  4. Our code: the block config, the mapper and the converter pair, with their tests.

Acceptance criteria

  • Not done: An editor adds a Chart block to a post and to an event, and each kind from sub-issue 1 renders on the page.
  • Not done: Saving an invalid chart (share ≠ 100, a negative value, an empty title or summary) shows a field error.
  • Not done: Markdown → block → Markdown round-trips for each kind in a test. payload.config.agentTools.test.ts refuses a suggestion with a malformed <Chart>, with a clear error.
  • Not done: The existing editorial blocks' tests still pass. A post with every block renders at 320 and 1280, light and dark (screenshots in the PR).

Area

frontend, cms, visualization

Priority

high


Generated by Claude Code, opens in a new tab

See it on GitHub, opens in a new tab