Skip to content

Commit af566c2

Browse files
feat(spec): count_true / count_false — a boolean column's Yes / No counts in the list footer (#35944)
<!-- claude-projects-attribution: {"github_login":"os-sales"} --> _Requested by **Sales** · [project thread](https://claude.ai/code/project/chan_01D5bWFY3rFzgJcytD5gD4Uu?thread=cmsg_01D5bWFY3rFzgJcytD5gD4Uu2rdPF6kmGfUJf93RWp8ZKf)_ Fixes #35702 Clause-②: yes (widening) Metadata-protocol: added Skills-docs: none — no page under `skills/**` lists the column summary members; the docs that do (`content/docs/ui/views.mdx`, the generated `content/docs/references/ui/view.mdx`, the `plugin-grid` README) are updated here repo:objectstack#1 · os-sales · session_01L6bhgVspkxqkUdkYxY1RHf Flow: dev-thread rule (maintainer 2026-11-20 09:22:50Z 「所有 p1 都按照新规则执行」): the card thread builds itself; L1 and the isolated L2 run in parallel at hand-back, the maintainer's 09:22Z ruling for every p1 card (deviates from contract-review.md:18 until the skill card lands). The second and last PR of #35702 (PR 1 #35919, merged f909734, left exactly this): the boolean 「是」/「否」 counts the card's 要做的 lists — 「补两种计算:布尔字段的「是」的条数、「否」的条数」. Clause-② is a widening: `ColumnSummarySchema` gains two members, and the derived rows of `ColumnSummaryAggregation` gain a `reads` list (`from` stays, the first of them). Contract face, L2 at `CONTRACT_REVIEW_TIER`. Null-cell ruling: record 7051689474 on #35702 — the maintainer chose 「不算,未填单独算「空」」 (option A, 2026-11-20 22:01:58Z). `count_true` counts the cells holding `true`, `count_false` the cells holding `false` (`count_FIELD` − `sum_FIELD`, never the record count); a cell with no value is in neither and shows under 「空」 (`count_empty`), so 是 + 否 = the filled count; with every value null, or no rows, 「是」 reads 0. That is what this PR builds. ## 维护者速读 - 列表底部计算行里,开关(布尔)列的菜单最前面多了「「是」的条数」「「否」的条数」两项,选了显示成「是 12」「否 3」。这两个数目前只出现在底部计算行:服务端已能在分组标题上算出它们,但控制台的分组标题读的是另一套汇总设置,还没有画出来。 - 属于「列表页重做」专题里「列表底部计算行」这张卡的最后一部分,做完这张卡就关闭。 - 没填值的记录两边都不算,算在「空」里(按你在决策卡上的选择);别的类型的列菜单里不会出现这两项,元数据里硬写到数字列上会在校验时被拒;出问题撤回这个改动即可。 - 无。 ## What changes - **Spec** (`packages/spec/src/ui/view.zod.ts`, `view-grouping-query.ts`). `ColumnSummarySchema` gains `count_true` and `count_false`. Both map by DERIVATION, the fork-i route the four filled / empty members took — no new `AggregationFunction`, no driver change: booleans aggregate as numbers on every backend (ruling #11152, `aggregation-conformance`'s `sum(flag)` row on six backends), so `count_true` = `SUM(field)` and `count_false` = `COUNT(field) − SUM(field)`. `COLUMN_SUMMARY_AGGREGATION`'s derived rows carry `reads`, every node the member reads (`count_true`: `['sum']`; `count_false`: `['sum', 'count']`; the four filled / empty: `['count']`). `columnSummaryNodeFunctions(mapping)` is the one reading of a row's nodes; the group header compiler uses it, and so do the footer's whole-set query and the lint below. `deriveColumnSummary` reads `count_true` as the sum, `0` when the sum answered no value (no non-null cell), and `count_false` as the non-null count less the sum. `COLUMN_SUMMARY_FIELD_TYPES` / `isColumnSummaryCompatibleWithFieldType` restrict the two members to the boolean class (`boolean`, `toggle`, pinned equal to `BOOLEAN_VALUE_TYPES`). - **Lint** (`packages/lint/src/validate-list-view-field-refs.ts`). `columnSummaryRefusal` judges a restricted member by that table: `count_true` / `count_false` over any other type is `list-view-summary-field-type-refused` (`error`). The aggregate door ACCEPTS `SUM(field)` over a number, so without this the footer would print a total under the label 「是」 and nothing would refuse it. Its `os explain` entry gains the paragraph. - **Footer** (`ui/packages/plugin-grid`). `offeredColumnSummaries` lists Count of Yes / Count of No first on a boolean or toggle column, and only where the spec's table allows them. `wholeSetSummaryNodes` asks every node a member reads (one `SUM(approved)` and one `COUNT(approved)` serve both counts and `count_empty`). The page fallback computes them off the rows as the cell reads them: only a real `true` / `false` is a value, so a null cell is neither, as on the server. The figure is drawn as `Yes 12` / `No 3`, a plain count. - **i18n.** `grid.summary.countTrue` / `countFalse` (the footer word, the pack's own Yes / No) and `menuCountTrue` / `menuCountFalse` (the menu entry) in all eleven packs. - Docs: `content/docs/ui/views.mdx`, the `plugin-grid` README; generated `content/docs/references/ui/view.mdx`, `api-surface/ui.json`, `export-origins/ui.json`. Changeset `35702-boolean-yes-no-counts.md` (`@objectstack/spec` and `@objectstack/lint` minor, `Metadata-protocol: added`; `@object-ui/plugin-grid`, `@object-ui/i18n` patch). Read first, by risk: `packages/spec/src/ui/view-grouping-query.ts` (the `reads` rows, `deriveColumnSummary`'s new branch, `summaryAggregationNodes`' loop), `packages/lint/src/validate-list-view-field-refs.ts` (`columnSummaryRefusal`'s restricted arm, which now resolves the field before the aggregate-kind early return), `ui/packages/plugin-grid/src/useWholeSetSummary.ts` (`wholeSetSummaryNodes`). ## Tests New: - `packages/spec/src/ui/view-grouping-query.test.ts` — `count_true / count_false`: the compiled nodes (one `sum_approved`, the shared `count_approved`); per group, a null cell in neither count and `true + false = filled` (3 / 2 / 1 null; all null reads 0 / 0; no true reads 0); a sum that answered no value reads 0 true, a missing column reads `undefined`, a string-spelled sum reads as a number; the field-type table (boolean class only, pinned to `BOOLEAN_VALUE_TYPES`, fail-closed on shape); `columnSummaryNodeFunctions` over every row kind; the alias collision on a field named `sum_approved`. The mapping-table pin carries the two new rows and `reads` on every derived row. - `packages/rest/src/list-view-grouping-query-door.test.ts` §7b — the real aggregate door, on driver-sql (better-sqlite3) and the in-memory tier: the compiled grouped query and the footer's whole-set query (no `groupBy`) answer each unit's and the whole set's true / false / empty counts, tallied off the seeded rows (every fourth unset); the one-row unit with no true reads 0. - `packages/lint/src/validate-list-view-field-refs.test.ts` — refuses the two members over a number and a text field (object form too), accepts them on booleans, and agrees with the spec's table over every `FieldType`. - `ui/packages/plugin-grid/src/__tests__/footerCalculationPicker-35702.test.tsx` — the boolean / toggle offer (the two counts first, no arithmetic); never on number, currency, text, select, date, lookup; a boolean column's menu lists Count of Yes / Count of No first, a pick draws `Yes 1` then `No 1`. - `ui/packages/i18n`: `zh-Hant.ts` regenerated from `zh-Hans.ts` (`gen:zh-hant`; the first CI run's Test UI 8/16 red was this file hand-written). - `ui/packages/plugin-grid/src/__tests__/footerSummaryScope-12081.test.tsx` — 300 rows over pages of 25: the yes / no / empty counts read the whole set off one `SUM` and one `COUNT` node; with no aggregate door they are the page's, labelled `(this page)`, and an unset cell is neither. Migrated: the `COLUMN_SUMMARY_AGGREGATION` pin (`reads` on the derived rows), `view.test.ts`'s member list, the `ui/packages/types` parity list (two members added). Voided: none. <details><summary>Local runs</summary> Head `5107231a` (the last commit is the generated `zh-Hant.ts` only; every run below is on `1d91bf50` or later unless named): - `@objectstack/spec`: `vitest run src/ui/view-grouping-query.test.ts src/ui/view.test.ts` — `Test Files 2 passed (2)`, `Tests 550 passed (550)`, lock `VERDICT command-exit 0`. `typecheck` (incl. `check:test-typecheck`) exit 0. `check:api-surface`, `check:docs`, `check:export-origins` were red before `gen:api-surface` / `gen:schema` + `gen:docs` / `gen:export-origins`, green after; `check:authorable-surface`, `check:liveness`, `check:llms-txt` exit 0. - `@objectstack/lint`: `validate-list-view-field-refs`, `validate-sortable-fields`, `rule-explanations` — `Test Files 3 passed (3)`, `Tests 316 passed (316)`; `typecheck` exit 0. - `@objectstack/rest`: `list-view-grouping-query-door.test.ts` (driver-sql better-sqlite3 + in-memory) — `Test Files 1 passed (1)`, `Tests 55 passed (55)`; `typecheck` exit 0. - `ui`: `plugin-grid` (`footerCalculationPicker-35702`, `footerSummaryScope-12081`, `useColumnSummary`, `useColumnSummary.i18n-4024`, `column-features`) + `types/spec-subschema-parity` — `Test Files 6 passed (6)`, `Tests 141 passed (141)`; the whole `packages/i18n/` project after the regeneration — `Test Files 105 passed (105)`, `Tests 1957 passed | 13 skipped`; `vitest run scripts/` — `Test Files 172 passed | 2 skipped`. - Derived gate families (`dispatch-gates --commands`, 120 on this tree): `--ran` reads 118 run, 2 NOT MEASURED, 0 UNRUN. NOT MEASURED: `check:dual-build-cjs-loads` (PREREQUISITE NOT MET: dists of untouched packages absent), `check:type-check-debt` (ran past the local 300 s window). One recorded red is the container, not the diff: `check:dts-closure` names `packages/cli`, `plugins/organizations` and `verify` `.d.ts` missing, packages this PR does not touch, built `OS_SKIP_DTS=1` here for the browser stand. CI's runs are the reading for all three. - NOT MEASURED locally: `@object-ui/plugin-grid` / `@object-ui/i18n` `type-check` (the ui dependency closure's declarations are not built in this container: every error is TS2307 on an `@object-ui/*` import or downstream of one, none in the two changed source files); Type Check UI is the reading. </details> ## Acceptance notes - Card acceptance 「布尔列有「是」「否」的条数」: the boolean column's menu offers both, first; they draw at once, over the whole matched set (the existing whole-set read) or the page, labelled as the page's. - Disclosed, not in scope: the record edit form draws an unset boolean as an unticked box (`ui/packages/fields/src/widgets/BooleanField.tsx:124,139`), while the list cell draws it as "No value". Under A an unset value is not counted as 「否」 even though the form shows it unticked. - A `count_true` / `count_false` column's whole-set figure waits for the object's field catalogue, as every `sum` node does (`isMoneyAggregate`: a `record`-mode currency check, ADR-0144 D6); the page figure shows until then, labelled as the page's. - The group header compiler reads no field types, so a hand-written `count_true` over a number reaching the server unlinted would answer that column's sum. The lint is the refusal (`os validate`, `os build`, the save door through the reference-integrity suite), the same tier the aggregate × field-type pairs are judged at. ## Verification Browser (showcase, own backend :43744 + console dev :53744 off this branch, admin), evidence in `/mnt/project-files/build-seat1/35702-pr2/`: - Field Zoo's list, the Boolean column's footer menu: Count of Yes, Count of No, then Unique, Filled, Empty, Percent filled, Percent empty, None (`b-02-boolean-menu.png`). The Number and Rating columns' menus list Sum / Avg / Min / Max and the counts, the Name and Select columns the counts only — no Count of Yes / No on any of them. - On a personal view of Field Zoo (Name, Boolean, Number): pick Count of Yes → `PATCH /api/v1/data/sys_personal_view/ID` 200 with only `f_boolean` gaining `summary: "count_true"` → the cell reads "Yes 1" (`b-12`) → reload → still "Yes 1" (`b-13`) → pick Count of No → PATCH 200, "No 1" (`b-14`). The two seeded rows hold `true` and `false`. - The runtime's aggregate door on the same stand, `POST /api/v1/data/showcase_field_zoo/query` with the footer's nodes answers `{ count: 2, sum_f_boolean: 1, count_f_boolean: 2 }` (Yes 1, No 1). - The package view `showcase_field_zoo.default`: the pick's draft save answers 403 and the pick is taken back, PR 1's documented behaviour for a view a read-only package ships. - NOT MEASURED in the browser: a null boolean cell (the showcase's Field Zoo refuses a new row without its required master-detail) and the whole-set path over more than one page (two rows); both are pinned on the real door (§7b) and in the 300-row footer suite. Two-minute check: on any object with a boolean field, open its table view as an admin, click under the boolean column — the menu starts with "Count of Yes" / "Count of No"; pick one, the cell reads "Yes N" at once. ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic beyond the pure mapping helpers that already live there. - [x] 2. Every name I added uses the casing for its kind. - [x] 3. No formatter ran; the repo-wide `pnpm lint` is CI's. - [x] 4. One issue, one branch off an up-to-date `main`, one pull request. - [x] 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset. - [x] 6. `packages/spec` touched: its generated artifacts are regenerated and committed. - [x] 7. No hand edits to `content/docs/references/`, `packages/*/CHANGELOG.md` or `content/docs/releases/`. - [x] 8. Title, body and comments are in English. - [x] The *Before Submitting* list in CONTRIBUTING.md is done. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01L6bhgVspkxqkUdkYxY1RHf <!-- signed: repo:objectstack#1 · os-sales · session_01L6bhgVspkxqkUdkYxY1RHf --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent e3e202a commit af566c2

30 files changed

Lines changed: 554 additions & 55 deletions
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
'@objectstack/spec': minor
3+
'@objectstack/lint': minor
4+
'@object-ui/plugin-grid': patch
5+
'@object-ui/i18n': patch
6+
---
7+
8+
feat(spec): `count_true` / `count_false` column summaries — a boolean column's Yes and No counts in the list footer and group headers
9+
10+
Clause-②: yes (widening)
11+
Metadata-protocol: added
12+
13+
`ListColumn.summary` accepts two more members, `count_true` and `count_false`: the number of rows whose boolean (or toggle) cell is true, and the number whose cell is false. A cell with no value is neither; it stays `count_empty`'s, so `count_true + count_false = count_filled`.
14+
15+
Both are answered on the server with no new aggregation function: booleans aggregate as numbers on every backend, so `count_true` is `SUM(field)` and `count_false` is `COUNT(field) − SUM(field)`, read off the group header row (or the footer's whole-set row) by `deriveColumnSummary`. `COLUMN_SUMMARY_AGGREGATION`'s derived rows now carry `reads`, every node the member reads (`from` is its first); `columnSummaryNodeFunctions(mapping)` is the one reading of a row's nodes, which the group header compiler, the footer's whole-set query and the lint now share. `COLUMN_SUMMARY_FIELD_TYPES` / `isColumnSummaryCompatibleWithFieldType` say the two members apply to `boolean` and `toggle` only.
16+
17+
`@objectstack/lint` refuses `count_true` / `count_false` over any other field type under `list-view-summary-field-type-refused` (an error, so `os validate` and the save door fail): over a number the same `SUM(field)` is a total, and the footer would print it as a count.
18+
19+
`@object-ui/plugin-grid`'s footer menu offers Count of Yes and Count of No first on a boolean or toggle column, and only there; the footer draws them as `Yes 12` / `No 3`, from the whole matched set when the server answers it and from the page, labelled as the page's, when it does not. `@object-ui/i18n` adds the `grid.summary` keys `countTrue`, `countFalse`, `menuCountTrue` and `menuCountFalse` in every pack.

‎content/docs/references/ui/view.mdx‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ Compound-cell prefix configuration
130130

131131
## ColumnSummary
132132

133-
Aggregation function for the column footer summary — and, on a grouped list view, the per-group header summary (server-side): count (COUNT(*), the group count), count_unique (count_distinct), sum, avg, min, max map onto the query AST's AggregationFunction; count_filled, count_empty, percent_filled, percent_empty derive from one COUNT(field) node (the non-null count) and the group count — count_filled = COUNT(field), count_empty = count − COUNT(field), percent_filled = COUNT(field) / count (0 when count is 0), percent_empty = 1 − percent_filled. Server-side "empty" is null on every face; the footer's client-side reading of empty strings and empty arrays as empty is the renderer's to converge
133+
Aggregation function for the column footer summary — and, on a grouped list view, the per-group header summary (server-side): count (COUNT(*), the group count), count_unique (count_distinct), sum, avg, min, max map onto the query AST's AggregationFunction; count_filled, count_empty, percent_filled, percent_empty derive from one COUNT(field) node (the non-null count) and the group count — count_filled = COUNT(field), count_empty = count − COUNT(field), percent_filled = COUNT(field) / count (0 when count is 0), percent_empty = 1 − percent_filled. count_true and count_false are a boolean column's yes and no counts, boolean fields only — count_true = SUM(field), count_false = COUNT(field) − SUM(field); a null cell is neither. Server-side "empty" is null on every face; the footer's client-side reading of empty strings and empty arrays as empty is the renderer's to converge
134134

135135
### Allowed Values
136136

@@ -141,6 +141,8 @@ Aggregation function for the column footer summary — and, on a grouped list vi
141141
* `count_unique`
142142
* `percent_empty`
143143
* `percent_filled`
144+
* `count_true`
145+
* `count_false`
144146
* `sum`
145147
* `avg`
146148
* `min`
@@ -157,7 +159,7 @@ Column footer summary configuration
157159

158160
| Property | Type | Required | Description |
159161
| :--- | :--- | :--- | :--- |
160-
| **type** | `Enum<'none' \| 'count' \| 'count_empty' \| 'count_filled' \| 'count_unique' \| 'percent_empty' \| 'percent_filled' \| 'sum' \| 'avg' \| 'min' \| 'max'>` | ✅ | Aggregation function |
162+
| **type** | `Enum<'none' \| 'count' \| 'count_empty' \| 'count_filled' \| 'count_unique' \| 'percent_empty' \| 'percent_filled' \| 'count_true' \| 'count_false' \| 'sum' \| 'avg' \| 'min' \| 'max'>` | ✅ | Aggregation function |
161163
| **field** | `string` | optional | Field to aggregate (defaults to the column field) |
162164

163165

@@ -725,7 +727,7 @@ List chart view configuration
725727
| **wrap** | `boolean` | optional | Allow text wrapping |
726728
| **type** | `string` | optional | Renderer type override (e.g., "currency", "date") |
727729
| **pinned** | `Enum<'left' \| 'right'>` | optional | Pin/freeze column to left or right side |
728-
| **summary** | `Enum<'none' \| 'count' \| 'count_empty' \| 'count_filled' \| 'count_unique' \| 'percent_empty' \| 'percent_filled' \| 'sum' \| 'avg' \| 'min' \| 'max'> \| { type: Enum<'none' \| 'count' \| 'count_empty' \| 'count_filled' \| 'count_unique' \| …>; field?: string }` | optional | Footer aggregation for this column — the function alone, or `{ type, field }` to aggregate another field |
730+
| **summary** | `Enum<'none' \| 'count' \| 'count_empty' \| 'count_filled' \| 'count_unique' \| 'percent_empty' \| 'percent_filled' \| 'count_true' \| 'count_false' \| 'sum' \| 'avg' \| 'min' \| 'max'> \| { type: Enum<'none' \| 'count' \| 'count_empty' \| 'count_filled' \| 'count_unique' \| …>; field?: string }` | optional | Footer aggregation for this column — the function alone, or `{ type, field }` to aggregate another field |
729731
| **prefix** | `{ field: string; type?: Enum<'badge' \| 'text'> }` | optional | Field rendered inline before this cell value |
730732
| **link** | `boolean` | optional | Functions as the primary navigation link (triggers View navigation) |
731733
| **action** | `string` | optional | Registered Action ID to execute when clicked |

‎content/docs/ui/views.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ columns: [
228228
| `sortable` | `boolean` | Allow column sorting |
229229
| `resizable` | `boolean` | Allow column resize |
230230
| `wrap` | `boolean` | Allow text wrapping |
231-
| `summary` | `enum \| { type, field? }` | Footer aggregation: `none`, `count`, `count_empty`, `count_filled`, `count_unique`, `percent_empty`, `percent_filled`, `sum`, `avg`, `min`, `max`. The object form aggregates a different field than the column's own |
231+
| `summary` | `enum \| { type, field? }` | Footer aggregation: `none`, `count`, `count_empty`, `count_filled`, `count_unique`, `percent_empty`, `percent_filled`, `count_true`, `count_false` (a boolean column's yes / no counts; a cell with no value is neither), `sum`, `avg`, `min`, `max`. The object form aggregates a different field than the column's own |
232232
| `prefix` | `{ field, type?: 'badge' \| 'text' }` | Compound cell — render another field's value inline before this cell's value |
233233
| `align` | `'left' \| 'center' \| 'right'` | Text alignment |
234234
| `link` | `boolean` | Cell functions as the primary navigation link |

‎packages/lint/src/rule-explanations.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4283,6 +4283,12 @@ const LIST_VIEW_SUMMARY_FIELD_TYPE_REFUSED_EXPLANATION: RuleExplanation = {
42834283
'`dataSource.object`, else `properties.objectName`; its grouped header numbers come from its ' +
42844284
'`aggregations` (`grid-aggregation-field-type-refused`), not from the column summaries.',
42854285
AGGREGATE_PAIR_ROWS,
4286+
'The yes / no counts of a boolean column, `count_true` and `count_false`, lower to `SUM(field)` ' +
4287+
'(booleans aggregate as numbers, so the sum is the number of true cells) and `COUNT(field)`. The ' +
4288+
'door accepts that sum over a number too, where it is a total rather than a count, so these two ' +
4289+
'members are judged by the spec\'s member × field-type table (`COLUMN_SUMMARY_FIELD_TYPES`) and ' +
4290+
'refused, under this id, over anything but a `boolean` or `toggle` field. A null cell is neither ' +
4291+
'true nor false: it is counted by `count_empty`.',
42864292
'The fix is a field of a type the function accepts (`summary: { type, field }` aggregates another ' +
42874293
'field), or a summary the field accepts: `count`, or a filled / empty count, takes any field. ' +
42884294
'A `formula` field stores no value, whatever its `returnType`, so a total over it has to be ' +

‎packages/lint/src/validate-list-view-field-refs.test.ts‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,6 +1593,34 @@ describe('[#32449] a column summary whose function the aggregate door refuses',
15931593
}
15941594
});
15951595

1596+
it('[#35702] refuses the boolean yes / no counts over anything but a boolean — the door would answer a total', () => {
1597+
expect(refused(withColumns(
1598+
{ field: 'is_locked', summary: 'count_true' },
1599+
{ field: 'title', summary: { type: 'count_false', field: 'is_all_day' } },
1600+
))).toEqual([]);
1601+
for (const [column, words] of [
1602+
[{ field: 'estimate', summary: 'count_true' }, '"count_true" over "estimate" (`number`)'],
1603+
[{ field: 'is_locked', summary: { type: 'count_false', field: 'title' } }, '"count_false" over "title" (`text`)'],
1604+
] as const) {
1605+
const findings = withColumns(column);
1606+
expect(findings.map((f) => [f.rule, f.path, f.severity])).toEqual([
1607+
[LIST_VIEW_SUMMARY_FIELD_TYPE_REFUSED, 'views[0].list.columns[1].summary', 'error'],
1608+
]);
1609+
expect(findings[0].message).toContain(`summary ${words} is a true / false count`);
1610+
expect(findings[0].hint).toMatch(/^Point "count_(true|false)" at a boolean or toggle field/);
1611+
}
1612+
// Every declared `FieldType`: refused exactly where the spec's member table refuses.
1613+
for (const member of ['count_true', 'count_false']) {
1614+
for (const type of FieldType.options) {
1615+
const objects = [{ name: 'duly_task', label: 'Task', fields: [{ name: 'probe', type, label: 'Probe' }] }];
1616+
const findings = refused(validateListViewFieldRefsUnrecorded(stackWith({ data: { provider: 'object', object: 'duly_task' }, columns: [{ field: 'probe', summary: member }] }, objects)));
1617+
expect(findings.length, `${member} over ${type}`).toBe(type === 'boolean' || type === 'toggle' ? 0 : 1);
1618+
}
1619+
}
1620+
// Unjudgeable stays unjudged: an unknown field is the existence rule's, a dotted path is skipped.
1621+
expect(refused(withColumns({ field: 'title', summary: { type: 'count_true', field: 'owner.name' } }))).toEqual([]);
1622+
});
1623+
15961624
it('skips what it cannot judge: an unknown field (the existence rule\'s), a dotted path, no declared type, a type outside `FieldType`', () => {
15971625
expect(withColumns({ field: 'title', summary: { type: 'sum', field: 'nope_field' } }).map((f) => [f.rule, f.path])).toEqual([
15981626
[LIST_VIEW_FIELD_UNKNOWN, 'views[0].list.columns[1].summary.field'],

‎packages/lint/src/validate-list-view-field-refs.ts‎

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,14 @@
372372
* door, and judged by this module's {@link columnSummaryRefusal}, under this
373373
* rule id.
374374
*
375+
* [#35702] The boolean yes / no counts `count_true` / `count_false` ride
376+
* `SUM(field)` (and `COUNT(field)`), which the door ACCEPTS over a number as
377+
* well — where it answers a total, not a count of true cells. So they are
378+
* judged by the spec's member × field-type table instead
379+
* (`COLUMN_SUMMARY_FIELD_TYPES` through `isColumnSummaryCompatibleWithFieldType`,
380+
* the boolean class only), under the same rule id: the footer would print a
381+
* total labelled as a count, with no refusal anywhere to say so.
382+
*
375383
* Not judged: `none`; `count` (fieldless, `COUNT(*)`); the four DERIVED
376384
* members (`count_filled` / `count_empty` / `percent_filled` /
377385
* `percent_empty`), which ride one `COUNT(field)` node and so compare no
@@ -466,7 +474,13 @@ import {
466474
isAggregateCompatibleWithFieldType,
467475
virtualFieldAggregateRemedy,
468476
} from '@objectstack/spec/data';
469-
import { COLUMN_SUMMARY_AGGREGATION, ListViewSchema, type ColumnSummary } from '@objectstack/spec/ui';
477+
import {
478+
COLUMN_SUMMARY_AGGREGATION,
479+
COLUMN_SUMMARY_FIELD_TYPES,
480+
ListViewSchema,
481+
isColumnSummaryCompatibleWithFieldType,
482+
type ColumnSummary,
483+
} from '@objectstack/spec/ui';
470484

471485
import {
472486
aggregateAcceptsDeclaration,
@@ -924,16 +938,28 @@ export function columnSummaryRefusal(
924938
const member = typeof summary === 'string' ? summary : isRec(summary) ? summary.type : undefined;
925939
if (typeof member !== 'string' || !Object.prototype.hasOwnProperty.call(COLUMN_SUMMARY_AGGREGATION, member)) return undefined;
926940
const mapping = COLUMN_SUMMARY_AGGREGATION[member as ColumnSummary];
941+
// A member the spec restricts to some field types (the boolean yes / no counts) is judged by that table.
942+
const restricted = Object.prototype.hasOwnProperty.call(COLUMN_SUMMARY_FIELD_TYPES, member);
927943
// `none`, the fieldless `count` and the derived `COUNT(field)` members compare no value.
928-
if (mapping.kind !== 'aggregate' || mapping.fieldless) return undefined;
929-
const fn = mapping.function;
944+
if (!restricted && (mapping.kind !== 'aggregate' || mapping.fieldless)) return undefined;
930945
const field = strName(isRec(summary) && summary.field !== undefined ? summary.field : column.field);
931946
if (!field || field.includes('.')) return undefined;
932947
const verdict = resolveFieldPath(graph, object, field);
933948
if (!verdict || isUnjudgeable(verdict) || verdict.kind !== 'ok') return undefined;
934949
const fieldType = verdict.meta?.type;
935950
if (!isJudgeableAggregateType(fieldType)) return undefined;
936951
const shape = { type: fieldType, multiple: verdict.meta?.multiple === true };
952+
if (restricted) {
953+
if (isColumnSummaryCompatibleWithFieldType(member, fieldType)) return undefined;
954+
return {
955+
message:
956+
`summary "${member}" over "${field}" (${declaredAs(shape)}) is a true / false count, for a ` +
957+
'boolean or toggle field only: here it would print a total as a count',
958+
hint: `Point "${member}" at a boolean or toggle field, or count "${field}" with count_filled or count_empty.`,
959+
};
960+
}
961+
if (mapping.kind !== 'aggregate') return undefined;
962+
const fn = mapping.function;
937963
if (aggregateAcceptsDeclaration(fn, shape)) return undefined;
938964
return {
939965
message:

‎packages/rest/src/list-view-grouping-query-door.test.ts‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ interface Row {
141141
owner: string;
142142
/** Nullable on purpose — the field the derived `count_filled` pin reads. */
143143
notes: string | null;
144+
/** A nullable boolean — the field the derived `count_true` / `count_false` pin reads. */
145+
approved: boolean | null;
144146
}
145147

146148
function makeRow(unit: string | null, ordinal: number): Row {
@@ -154,6 +156,8 @@ function makeRow(unit: string | null, ordinal: number): Row {
154156
owner: `owner_${ordinal % 4}`,
155157
// Every fifth row has no note — the server's "empty" (null), never ''.
156158
notes: ordinal % 5 === 0 ? null : `note ${ordinal}`,
159+
// Every fourth row unset, the rest true / false alternating.
160+
approved: ordinal % 4 === 0 ? null : ordinal % 2 === 0,
157161
};
158162
}
159163

@@ -283,6 +287,7 @@ function objectSchema(name: string) {
283287
amount: { name: 'amount', type: 'number' as const, label: 'Amount' },
284288
owner: { name: 'owner', type: 'text' as const, label: 'Owner' },
285289
notes: { name: 'notes', type: 'text' as const, label: 'Notes' },
290+
approved: { name: 'approved', type: 'boolean' as const, label: 'Approved' },
286291
seq: { name: 'seq', type: 'number' as const, label: 'Stored Order' },
287292
},
288293
};
@@ -806,6 +811,48 @@ describe('§7 `count_filled` is derived on the header row, and the view filter r
806811
});
807812
});
808813

814+
// ─── §7b The boolean yes / no counts (#35702) ─────────────────────────────────
815+
816+
describe('§7b `count_true` / `count_false` are SUM(field) and COUNT(field) over a boolean, on both faces', () => {
817+
const FLAG_VIEW: ListViewGroupQuerySource = {
818+
grouping: { fields: [{ field: 'business_unit' }] },
819+
columns: [
820+
{ field: 'approved', summary: 'count_true' },
821+
{ field: 'id', summary: { type: 'count_false', field: 'approved' } },
822+
{ field: 'business_unit', summary: { type: 'count_empty', field: 'approved' } },
823+
],
824+
};
825+
const tally = (rows: readonly Row[], value: boolean | null) => rows.filter((r) => r.approved === value).length;
826+
827+
it.each(TIERS)('%s: per group and over the whole set, a null cell counts as neither', async (tier) => {
828+
const query = compileListViewGroupQuery(FLAG_VIEW);
829+
expect(query.aggregations).toEqual([
830+
{ function: 'count', alias: LIST_VIEW_GROUP_COUNT_ALIAS },
831+
{ function: 'sum', field: 'approved', alias: 'sum_approved' },
832+
{ function: 'count', field: 'approved', alias: 'count_approved' },
833+
]);
834+
const headers = await onTier(tier, () => records(OBJECT_CONTIGUOUS, query));
835+
for (const [unit] of UNITS) {
836+
const row = headers.find((h) => h.business_unit === unit) as ListViewGroupHeaderRow;
837+
const rows = CONTIGUOUS.filter((r) => r.business_unit === unit);
838+
expect(deriveColumnSummary(row, 'count_true', 'approved'), `${tier}/${unit} true`).toBe(tally(rows, true));
839+
expect(deriveColumnSummary(row, { type: 'count_false', field: 'approved' }, 'id'), `${tier}/${unit} false`).toBe(tally(rows, false));
840+
expect(deriveColumnSummary(row, { type: 'count_empty', field: 'approved' }, 'business_unit')).toBe(tally(rows, null));
841+
}
842+
// `harbour_office` is one row, ordinal 1: false. Its true count is 0, not blank.
843+
const harbour = headers.find((h) => h.business_unit === 'harbour_office') as ListViewGroupHeaderRow;
844+
expect(deriveColumnSummary(harbour, 'count_true', 'approved')).toBe(0);
845+
846+
// The footer's whole-set question: the same nodes with no `groupBy`.
847+
const whole = await onTier(tier, () => records(OBJECT_CONTIGUOUS, { aggregations: query.aggregations }));
848+
expect(whole).toHaveLength(1);
849+
const [set] = whole as ListViewGroupHeaderRow[];
850+
expect(deriveColumnSummary(set, 'count_true', 'approved')).toBe(tally(CONTIGUOUS, true));
851+
expect(deriveColumnSummary(set, 'count_false', 'approved')).toBe(tally(CONTIGUOUS, false));
852+
expect(tally(CONTIGUOUS, true) + tally(CONTIGUOUS, false) + tally(CONTIGUOUS, null)).toBe(TOTAL_ROWS);
853+
});
854+
});
855+
809856
// ─── §8 Rows inside a group are the existing paged find ──────────────────────
810857

811858
describe('§8 `limit` / `offset` slice INSIDE one group', () => {

‎packages/spec/api-surface/ui.json‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
"BulkActionResultSchema (const)",
9090
"CHART_AGGREGATE_COMPARISON_SUFFIX (const)",
9191
"COLUMN_SUMMARY_AGGREGATION (const)",
92+
"COLUMN_SUMMARY_FIELD_TYPES (const)",
9293
"COMPILED_PAGE_KINDS (const)",
9394
"CalendarConfig (type)",
9495
"CalendarConfigSchema (const)",
@@ -125,6 +126,7 @@
125126
"ColumnSummaryAggregation (type)",
126127
"ColumnSummaryConfig (type)",
127128
"ColumnSummaryConfigSchema (const)",
129+
"ColumnSummaryDerivedSource (type)",
128130
"ColumnSummarySchema (const)",
129131
"ColumnSummaryValue (type)",
130132
"CompileListViewGroupQueryOptions (interface)",
@@ -556,6 +558,7 @@
556558
"checkPageRequiresKind (function)",
557559
"checkPageSourceCompleteness (function)",
558560
"columnSummaryAlias (function)",
561+
"columnSummaryNodeFunctions (function)",
559562
"compileListViewGroupQuery (function)",
560563
"compileListViewGroupRowsQuery (function)",
561564
"dashboardForm (const)",
@@ -578,6 +581,7 @@
578581
"hasReservedComponentNamespace (function)",
579582
"isActionParamValuePresent (function)",
580583
"isAggregatedViewContainer (function)",
584+
"isColumnSummaryCompatibleWithFieldType (function)",
581585
"isExpressionBindableTextKey (function)",
582586
"isKnownComponentType (function)",
583587
"isRecordContextBlockType (function)",

0 commit comments

Comments
 (0)