On this page
- Status: Accepted. Batch D2a (2026-09-03), commit
a237ad68; renderer split (P2-18) batch D2b, commit4e1b872b. - Owners: Platform (site programme).
- Extends: ADR 0019 D6 (one widget registry — amended below), ADR 0038, ADR 0039.
Context#
A card must be able to show a tenant-dataset measure the same way it shows a compiled metric —
without cloning the widget catalog. Two families of data source (compiled MetricQueryInput and
org_dataset field references) need to reach the same twelve chart kinds through the same renderer,
never a second parallel set of "dataset chart" kinds.
Decisions#
D1 — WidgetSpec.dataSource becomes dataSources, a set
packages/schema (widget registry, apps/web/src/server/widget-registry.ts) declares
readonly dataSources: readonly WidgetDataSourceKind[] per kind, replacing the earlier scalar
dataSource. 'org_dataset' joins 'metric' on the twelve chart kinds plus the three promoted
comparison kinds (stat_versus, period_compare, growth_table) — one catalogue, no cloned kinds.
A kind that accepts metric on one dashboard and org_dataset on another is exactly the same
WidgetSpec row; the config union already discriminates on config.dataSource at the instance
level.
D2 — orgDatasetBinding: one config object, not N optional parameters
orgDatasetBindingConfigSchema (apps/web/src/server/widget-config-schemas.ts): dataset key,
measure key, optional secondary measure, dimension(s), time grain (including month), anchor (the
snapshot month for a stock measure), up to 10 filters (AND across, OR within each), optional
scenario/version axes, topN/sort/orientation. dimKey is a catalog KEY that parameterises a
compiled query — never a compiled identifier (ADR 0023's rule, verbatim). Every future binding need
becomes a field on this one object, validated once, instead of another optional parameter on
explore.dataset's ~18-parameter surface.
D3 — org-dataset-resolver.ts: one compiler, over the rollup, inside RLS
apps/web/src/server/datasets/org-dataset-resolver.ts turns a binding into a compiled query over
agg_org_dataset_period (never the bridge/record tables — §49's "aggregates read the rollup" rule)
and shapes the result into the exact frame explore.query returns, so every chart-switch widget
kind renders an org_dataset series through the SAME builders (packages/charts/src/builders/*) a
metric series does. It is not a second DSL evaluator: dataset-expr.ts/dataset-rollup.ts (ADR 0040) already compiled every measure's formula into the materialized cell; this module only reads
those cells and reduces them across a caller-requested window. Availability (ADR 0039 D6) is
re-derived honestly per cell — a request-level mismatch (a dimKey outside applicable_filters, a
grain the dataset does not carry) resolves not_applicable_at_grain before any row is read; a brand
is pinned and RLS applies inside the caller exactly as every other resolver. Exposed as
explore.orgDatasetQuery, routed through the binding cache (ADR 0044).
D4 — Editor: source toggle, then dataset/measure/dimension/grain pickers
add-widget-panel.tsx gains a source toggle (metric vs tenant dataset) that swaps in dataset,
measure, dimension, and grain pickers reading the org's confirmed fields (never status:'suggested'
ones — ADR 0038 D4). A guard test asserts the resolver never fabricates a zero for a non-ok cell.
D5 — Renderer split (P2-18): one shared module, downloaded on demand
MetricWidget (KPI tile, metric table, ten chart kinds — the single largest client component on
every deck route) was split into an on-demand module with shared placeholders
(widget-placeholders.tsx), so a page downloads only the widget kinds it actually draws instead of
every kind any dashboard could draw. Deck routes: -21 KB raw / -5 KB gzip; the §76 route-bundle cap
ratchets down to the measured value (see the roadmap and programme-ledger amendments). This is the
lever the dual-source binding's own budget growth (filter-scope law on every card, the
org_dataset binding path itself) had been raised against — P2-18 pays that debt down rather than
raising the cap again.
Consequences#
- A card's data source is a property of its CONFIG, never its KIND — a dashboard can mix metric-backed and dataset-backed cards of the same widget kind with no special-casing in the renderer.
- Adding a third data source family later (a future
plan_dataset, say) is again adataSourcesentry plus a resolver, never a fork of the chart-kind catalogue. - The renderer split makes the dual-source registry's own weight payable in code-splitting terms rather than a permanently wider first-load budget.
Implementation status (declared 2026-09-03)#
| Decision | Status | Evidence |
|---|---|---|
D1 dataSources set |
Landed | WidgetDataSourceKind[] on every WidgetSpec; widget- extended |
D2 orgDataset object |
Landed | orgDataset, widget- |
D3 resolver + explore. |
Landed | datasets/; org- (163 vs 468 oracle table test) |
| D4 editor pickers | Landed | add- source toggle + dataset/measure/dimension/grain pickers |
| D5 renderer split (P2-18) | Landed | metric- + widget-; deck routes -21 KB raw / -5 KB gzip; caps ratcheted down |