Skip to content

Commit c801993

Browse files
fix(lint): kanban group-field hint offers a grid grouping only where the engine accepts it (#38635)
<!-- claude-projects-attribution: {"github_login":"os-steve"} --> _Requested by **Steve** · [project thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9JeHmqv6CKCkW8ewrPBLekk)_ Refs #38433 (items 1, 2) Clause-②: no Metadata-protocol: none ## 维护者速读 - 作者与智能体在校验或保存看板视图时看到的修复建议变了:分组字段是多值、JSON 存储或公式字段时,不再建议改用表格分组,而是建议改用表格列;普通文本、数字、日期字段的建议不变。 - 属于看板分组字段校验规则的复核跟进:原建议会把作者引到一个打开即报错的表格分组。 - 只是提示文字和规则说明变了,不改任何校验结论或严重级别;出错时作者只会读到不准确的建议,可直接撤回。 - 无。 ## What changes `list-view-kanban-group-field-uncategorical` now offers the grid-grouping remedy only on the branch where it holds. - **Hint** (`checkKanbanGroupField`, `packages/lint/src/validate-list-view-field-refs.ts`): the tail is keyed on the engine's own refusal set, read from the same spec predicates the two `engine.aggregate` doors use: - multi-valued (`isMultiValueField`, the multi branch) and structured-JSON (`STRUCTURED_JSON_TYPES`) are refused by `assertGroupByNamesNoJsonStoredField`; - virtual `formula` (`isVirtualSearchField`) is refused by `assertGroupByTargetsAreStored`; - both answer `400 INVALID_FIELD`. A list view `grouping` compiles to that group-header query (`compileListViewGroupQuery`), which the grid sends. - For those three classes the hint now ends `or show "FIELD" as a grid column (a list cannot be grouped by REASON)`; every other warned field (text, number, date and the rest of the stored single-valued scalars) keeps `or show "FIELD" as a grid grouping`. - **Explanation** (`rule-explanations.ts`, this rule's entry only): the fix paragraph now says the same, branch by branch: stored single-valued field gives grid grouping; multi-valued, JSON-stored or `formula` gives grid column only, with the reason. - Measured from the rule's code: before this PR a JSON-stored or `formula` group field already warned, on the **single-valued** branch (it is not in `KANBAN_CATEGORICAL_TYPES`), and got the grid-grouping tail. No finding, severity or accept set changes. - **N2 (item 4), decided: keep the short list deliberately.** `select`, boolean and lookup are the heads of the three families the rule accepts (`select`/`radio`, `BOOLEAN_VALUE_TYPES`, `REFERENCE_VALUE_TYPES`). Naming each member would hand-copy `KANBAN_CATEGORICAL_TYPES` into prose that drifts from it, and would lengthen a hint held to 200 characters. Read first, by risk: 1. `packages/lint/src/validate-list-view-field-refs.ts`, the `ungroupable` / `gridRemedy` hunk in `checkKanbanGroupField`: this is where the set is keyed. 2. `packages/lint/src/validate-list-view-kanban-lanes.test.ts`, the new per-field `it.each`. Two-minute check: `pnpm --filter @objectstack/lint exec vitest run --maxWorkers=2 src/validate-list-view-kanban-lanes.test.ts`. Expect 34 passed. The `tags`, `watchers`, `meta`, `address` and `score` rows assert a grid column; `amount`, `due_date` and `subject` assert a grid grouping. ## Tests At head `e0e643722a`: <details><summary>@objectstack/lint: full suite and typecheck</summary> - `pnpm --filter @objectstack/lint exec vitest run --maxWorkers=2`: Test Files 246 passed (246), Tests 9962 passed, 5 skipped (9967). - `pnpm --filter @objectstack/lint typecheck`: exit 0; check:test-typecheck OK. - `src/validate-list-view-kanban-lanes.test.ts`: 34 passed. </details> <details><summary>Ablation</summary> Forced `gridRemedy` to always take the grid-grouping arm, on disk, then ran the target file: 5 failed / 29 passed. The failures were exactly the five ungroupable rows (`tags`, `watchers`, `meta`, `address`, `score`). Restored with `git checkout HEAD --`, tree clean. </details> ## Acceptance notes - Item 3 of the card (a finding of its own for a `grouping.fields[].field` naming a multi-value, JSON-stored or non-stored field) is not in this PR. It is a narrowing and stays on the card. - `engine.aggregate` also refuses a `groupBy` on a credential or `internal`-flagged column (`rejectCredentialEvaluation`, `rejectInternalFieldEvaluation`). The hint is not keyed on those, because the refusal comes from a flag and not from the storage class. A kanban board grouped by a password field is not a realistic producer. Noted only. ## Verification <details><summary>Derived local gates (dispatch-gates --commands, 70 families)</summary> - `dispatch-gates --ran`: 70 derived, 67 run with exit 0, 3 NOT MEASURED (exit 3, prerequisite), 0 unrun. - NOT MEASURED: `check-plugin-teardown-shape --self-test` (shallow clone cannot reach its pinned fixture commit), `check:dual-build-cjs-loads` and `check:lean-entry-closure` (need dist of packages outside this diff's closure). Left to CI. - `check:docs-transcript-drift` was re-run after building `@objectstack/lint`: exit 0. `check:type-check-debt` and `check:query-options-erasure`: exit 0. - `overlap-check --branch=HEAD`: clean against origin/main and #38628, #38605, #38594, #38550. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01ADHkmSwS4mQyXWrddL4r6B)_ <!-- signed: repo:objectstack#3 · os-steve · session_01ADHkmSwS4mQyXWrddL4r6B --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent f3028c5 commit c801993

4 files changed

Lines changed: 64 additions & 3 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'@objectstack/lint': patch
3+
---
4+
5+
Clause-②: no
6+
Metadata-protocol: none
7+
8+
`list-view-kanban-group-field-uncategorical`: the hint offers a grid grouping only for a stored, single-valued field. A board grouped by a multi-valued field, a JSON-stored field (`json`, `address`, `composite` and the like) or a `formula` field is now pointed at a grid column instead, because the engine refuses to group a list by one of those (`400 INVALID_FIELD`); following the old hint produced a grid that passed `os validate` and opened on that error. `os explain` for the rule says the same, branch by branch.

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1558,7 +1558,10 @@ const LIST_VIEW_KANBAN_GROUP_FIELD_UNCATEGORICAL_EXPLANATION: RuleExplanation =
15581558
'declaration. Not judged: a dotted `groupByField`, one that names no field (`list-view-field-unknown`), ' +
15591559
'and a field whose type is not readable.',
15601560
'To fix it, group the board by a single-valued `select` field (one lane per option), a boolean or a ' +
1561-
'lookup; or show the field as a grid column or grouping instead of board lanes.',
1561+
'lookup; or show the field in a grid instead of board lanes. A stored, single-valued field (text, ' +
1562+
'number, date) can be a grid grouping. A multi-valued field, a JSON-stored field (`json`, `address`, ' +
1563+
'`composite` and the like) or a `formula` field can only be a grid column: the engine refuses to group ' +
1564+
'a list by one (`400 INVALID_FIELD`), so a grid grouping on it opens on an error.',
15621565
],
15631566
};
15641567

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,7 @@ import {
506506
BOOLEAN_VALUE_TYPES,
507507
FieldType,
508508
REFERENCE_VALUE_TYPES,
509+
STRUCTURED_JSON_TYPES,
509510
classifyDottedFilterHead,
510511
isAggregateCompatibleWithFieldType,
511512
isMultiValueField,
@@ -1471,6 +1472,20 @@ export function validateListViewFieldRefs(
14711472
const { type, multiple } = verdict.meta;
14721473
const multi = isMultiValueField({ type, multiple } as never);
14731474
if (!multi && KANBAN_CATEGORICAL_TYPES.has(type)) return;
1475+
// The grid remedy is offered only where it holds. A list view `grouping`
1476+
// compiles to the group-header query the grid sends to `engine.aggregate`,
1477+
// which refuses a `groupBy` over a multi-value or structured-JSON field
1478+
// (`assertGroupByNamesNoJsonStoredField`) and over a virtual `formula`
1479+
// field (`assertGroupByTargetsAreStored`), `400 INVALID_FIELD`. Those three
1480+
// classes, read from the same spec predicates, get a grid column instead.
1481+
const ungroupable = multi
1482+
? 'a multi-valued field'
1483+
: STRUCTURED_JSON_TYPES.has(type)
1484+
? 'a JSON-stored field'
1485+
: isVirtualSearchField({ type } as never) ? 'a field computed on read' : null;
1486+
const gridRemedy = ungroupable === null
1487+
? `show "${groupBy}" as a grid grouping`
1488+
: `show "${groupBy}" as a grid column (a list cannot be grouped by ${ungroupable})`;
14741489
findings.push({
14751490
severity: 'warning',
14761491
rule: LIST_VIEW_KANBAN_GROUP_FIELD_UNCATEGORICAL,
@@ -1482,8 +1497,7 @@ export function validateListViewFieldRefs(
14821497
: `"${object}.${groupBy}" is a \`${type}\` field: the board draws a lane per distinct value on its loaded ` +
14831498
'cards, none for a value no card holds, and none on an empty list',
14841499
hint:
1485-
`Group the board by a single-valued \`select\` (one lane per option), a boolean or a lookup, or show ` +
1486-
`"${groupBy}" as a grid grouping`,
1500+
`Group the board by a single-valued \`select\` (one lane per option), a boolean or a lookup, or ${gridRemedy}`,
14871501
});
14881502
};
14891503

‎packages/lint/src/validate-list-view-kanban-lanes.test.ts‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ describe('#35143 — a board grouped by a field with no lanes of its own', () =>
165165
due_date: { type: 'date', label: 'Due' },
166166
tags: { type: 'multiselect', label: 'Tags', options: STATUS_OPTIONS },
167167
watchers: { type: 'lookup', label: 'Watchers', reference: 'sys_user', multiple: true },
168+
meta: { type: 'json', label: 'Meta' },
169+
address: { type: 'address', label: 'Address' },
170+
score: { type: 'formula', label: 'Score', expression: 'amount * 2' },
168171
},
169172
},
170173
];
@@ -197,6 +200,39 @@ describe('#35143 — a board grouped by a field with no lanes of its own', () =>
197200
for (const line of [findings[0].message, findings[0].hint]) expect(line.length, line).toBeLessThanOrEqual(200);
198201
});
199202

203+
// The grid remedy is offered only where `engine.aggregate` accepts the
204+
// `groupBy` a list view grouping compiles to: a stored, single-valued
205+
// scalar. A multi-value, structured-JSON or `formula` field is refused there
206+
// (`400 INVALID_FIELD`), so its hint offers a grid column instead.
207+
it.each([
208+
['amount', true],
209+
['due_date', true],
210+
['subject', true],
211+
['tags', false],
212+
['watchers', false],
213+
['meta', false],
214+
['address', false],
215+
['score', false],
216+
])('the hint for a board grouped by `%s` offers a grid grouping: %s', (field, groupable) => {
217+
const [finding] = groupFindings(groupedBy(field as string));
218+
expect(finding, field as string).toBeDefined();
219+
if (groupable) {
220+
expect(finding.hint).toContain(`"${field}" as a grid grouping`);
221+
expect(finding.hint).not.toContain('grid column');
222+
} else {
223+
expect(finding.hint).toContain(`"${field}" as a grid column`);
224+
expect(finding.hint).not.toContain('grid grouping');
225+
}
226+
expect(finding.hint.length, finding.hint).toBeLessThanOrEqual(200);
227+
});
228+
229+
it('`os explain` offers a grid grouping only for a stored, single-valued field', () => {
230+
const fix = explainRule(LIST_VIEW_KANBAN_GROUP_FIELD_UNCATEGORICAL)!.paragraphs.at(-1)!;
231+
for (const fact of ['grid grouping', 'grid column', 'multi-valued', 'JSON-stored', '`formula`', 'INVALID_FIELD']) {
232+
expect(fix, fact).toContain(fact);
233+
}
234+
});
235+
200236
it('a kanban block on a non-kanban view, a dotted and an unknown group field are not judged', () => {
201237
expect(groupFindings(groupedBy('amount', 'grid'))).toEqual([]);
202238
expect(groupFindings(groupedBy('owner.name'))).toEqual([]);

0 commit comments

Comments
 (0)