Metric
One headline number worked out by the database from a query: a total, an average, a count. Use it for dashboard figures; use Stat only for a number you already have.
Props
sourceId: string | binding | callsql: string | binding | call — A single read-only SELECT statement.filters(optional): array of { column: string, op: "eq" | "neq" | "lt" | "lte" | "gt" | "gte" | "in" | "notin" | "between" | "contains" | "startswith" | "endswith" | "isnull" | "isnotnull" | "since", values?: array } | binding — Filters applied by the database. Send the whole list each time; an empty list clears them. Or a binding ({ "@path": "/filters" }) to read a list kept in the surface's data model: give every view on a page the same path, with a FilterBar writing to it, and they all follow one set of filters. A filter on a column a view's rows lack (a total with no region column, under a filter by region) is left out for that view, which is drawn without it and says so in a note.column(optional): stringaggregate: "sum" | "avg" | "count" | "count_distinct" | "min" | "max" | "median" | "stddev" | "variance" | "percentile"percentile(optional): number — For the percentile aggregate, a fraction from 0 to 1: 0.9 is the 90th percentile.label: string | binding | callformat(optional): "number" | "compact" | "currency" | "percent"currency(optional): stringemptyMessage(optional): string | binding | call — What the people using the page read when the query answers with no rows, in place of the component's own empty text. Say what is missing and what to try: "No orders this week yet."errorMessage(optional): string | binding | call — What the people using the page read when the query fails, in place of the database's error text, which is kept for developers. Say what went wrong in their terms and what to do.minHeight(optional): integer — The least height of this component's box, in pixels. It is as tall as what it holds, or this, whichever is more.
Example
The same component written three ways. Each draws the same surface.
As JSX, with analyticsMarkup from @surfaces-ui/spec/react:
<Ui.Metric
sourceId="lake"
sql="SELECT * FROM orders"
column="amount"
aggregate="sum"
label="Revenue"
format="currency"
/>As an agent sends it (one component of an A2UI updateComponents message):
{
"id": "revenue",
"component": "Metric",
"sourceId": "lake",
"sql": "SELECT * FROM orders",
"column": "amount",
"aggregate": "sum",
"label": "Revenue",
"format": "currency"
}As a json-render spec, which fromJsonRender converts:
{
"root": "revenue",
"elements": {
"revenue": {
"type": "Metric",
"props": {
"sourceId": "lake",
"sql": "SELECT * FROM orders",
"column": "amount",
"aggregate": "sum",
"label": "Revenue",
"format": "currency"
}
}
}
}