Skip to content

Commit 12ccffe

Browse files
fix(studio): conditional formatting refuses == on a list field while typing (#36785)
<!-- claude-projects-attribution: {"github_login":"os-warren"} --> _Requested by **Warren** · [project thread](https://claude.ai/code/project/chan_01U5RdnAAmkSQmZbqh6FtqZ8?thread=cmsg_01U5RdnAAmkSQmZbqh6FtqZ8M6sbZjBjat5VcHCF9RcSaz)_ Fixes #36459 Clause-②: no Metadata-protocol: none ## 维护者速读 - 在视图的「条件格式」里,管理员写「标签等于 VIP」这类把多选字段当单值比较的规则时,编辑框会当场标红并给出改写建议(改成「VIP 在标签里」),保存按钮在改好之前不放行;以前这种规则能存下来,但永远不会给任何一行上色。 - 属于界面体验专题,是「多选字段不能用等于比较」这一修复(字段属性面板已做)在条件格式编辑器上的补齐。 - 出错的话只是条件格式编辑框多报或少报一条提示,不改已有视图和数据,可直接撤回。 - 无。 ## What changes `CelPredicateField` has taken the object's field definitions (`fieldDefs`: name, `type`, `multiple`) since the field inspector's list-equality work: it reads the list-valued fields through `isMultiValueField` and hands them to the lint as `multiValueFields`, so the engine refuses `record.LISTFIELD == 'x'` (`list-equality`) with the membership rewrite. The view conditional formatting editor mounted one `CelPredicateField` per rule but never passed `fieldDefs`, so no field was judged a list there and such a rule linted clean, saved, and never matched a row. - `ConditionalFormattingEditor` takes an optional `fieldDefs` prop and hands it to every rule's `CelPredicateField`. Omitted, the lint is what it was. - Both mount sites pass it: `ViewVariantInspector` (metadata admin view page) builds it from the `useObjectFields` catalog it already reads; `ListViewMoreSection` (Studio list-view panel) builds it from the loaded `fieldCatalog` it already receives, which already carries `multiple`. - The refusal is an `error`, so it counts in the editor's existing blocking-issue report: the host's Save (metadata admin) and autosave hold (Studio panel) stay shut until the rule is rewritten. No spec, rule shape or server change. `ConditionalFormattingEditor` is not in `@object-ui/app-shell`'s published exports, so no export changes (Clause-② no). Changeset: `@object-ui/app-shell` patch. Card item 2 (should the view save refuse the same shape) is dropped by the seat; see Acceptance notes. ## Tests New file `ui/packages/app-shell/src/views/metadata-admin/ConditionalFormattingEditor.listEquality-36459.test.tsx`, against the real `@objectstack/formula` engine: - editor: `record.tags == 'vip'` and `record.tags != 'vip'` on a `select` declared `multiple: true` show the "holds a list" finding with the `in` rewrite and report 1 blocking issue; - editor: `'vip' in record.tags` is clean (0 blocking); - control: `record.stage == 'open'` on a single-value `select` is clean; - mount sites: the view variant inspector (fed `objectFieldsOverride`) and the Studio list-view panel (fed a loaded `fieldCatalog`) both show the finding; the panel reports 1 blocking issue. Reverse verification at `7c65f8b9`, through `scripts/ablation-replace.mjs` (anchor hit 1 → 0, blob changed, restored blob == HEAD, `git diff HEAD` empty): with the `fieldDefs={fieldDefs}` pass-through deleted from `ConditionalFormattingEditor`, the 4 refusing cases fail and the 2 clean cases pass. <details><summary>Local runs under the verify lock (head 7c65f8b)</summary> ``` pnpm --dir ui exec vitest run ConditionalFormattingEditor.listEquality-36459.test.tsx ConditionalFormattingEditor.test.tsx ConditionalFormattingEditor.celGate.test.tsx Test Files 3 passed (3) Tests 36 passed (36) os-verify-lock: VERDICT command-exit 0 pnpm --filter @object-ui/app-shell run type-check os-verify-lock: VERDICT command-exit 0 ablation (pass-through deleted) Tests 4 failed | 2 passed (6) ablation-replace: ok restored: blob == HEAD and `git diff HEAD` is empty ``` ``` dispatch-gates --commands (derived from the branch, head 7c65f8b): 38 families, each run locally, every one exit 0 ✓ dispatch-gates --ran: 38 derived famil(ies) accounted for — 38 run, 0 NOT-MEASURED (a DERIVED zero — all 38 recorded an exit code and none of them is 3). ``` </details> The full `@object-ui/app-shell` suite and every other family run in CI (`Test UI`, `Type Check UI`); their check-runs are the verdict. ## Acceptance notes - Card item 2 (the view save refusing the same shape): dropped — new save-door lint site; new gates default no. On `main` a view's `conditionalFormatting[].condition` is not CEL-linted at save at all (`validate-expressions` lints a field's own `conditionalFormatting`; the `view` write path runs the bulk-confirm text pass only), so refusing it there would be a new gate. Not filed. ## Verification Read first: 1. `ConditionalFormattingEditor.tsx`: the new `fieldDefs` prop and its pass-through to `CelPredicateField`. 2. `ListViewMoreSection.tsx`: `fieldDefs` built from `fieldCatalog` only when it is loaded (riskiest hunk: `undefined` while loading means no list judgement until the catalog arrives). 3. `ViewVariantInspector.tsx`: `celFieldDefs` from the same catalog the field name list comes from. Two-minute check: in Studio, open a list view of an object with a multi-select field, add a conditional formatting rule and type `record.FIELD == 'x'` for that field: the box shows "holds a list" with the `in` rewrite and the view does not save; type `'x' in record.FIELD`: the finding clears. --- _Generated by [Claude Code](https://claude.ai/code/session_01JQwxbXAtnodnKm6tuyEbxU)_ <!-- signed: repo:objectstack#1 · os-warren · session_01JQwxbXAtnodnKm6tuyEbxU --> Co-authored-by: Claude <noreply@anthropic.com>
1 parent d139c7a commit 12ccffe

5 files changed

Lines changed: 242 additions & 0 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
---
4+
5+
fix(studio): a view's conditional formatting rule that compares a list field with a single value is refused while typing
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
A formatting rule such as `record.tags == 'vip'` on a list field (`multiselect`, `checkboxes`, `tags`, or a `select` / `lookup` / `user` declared `multiple: true`) compares a list with a single value, so it never matches any row and the style never shows. The conditional formatting editor accepted it without a word. It now hands the lint the object's field types and `multiple`, as the field inspector's condition editors already do, so the rule is flagged while the author types, with the membership rewrite (`'vip' in record.tags`), and counts as a blocking issue for Save. Both places the editor appears do this: the view inspector in the metadata admin and the list-view panel in Studio. A membership test on the same field, and `==` on a single-value field, stay clean.
11+
12+
`ConditionalFormattingEditor` takes an optional `fieldDefs` prop (each field's name, `type` and `multiple`); omitted, the lint is what it was before. What the server accepts on save is unchanged.
Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* objectstack#36459 — a view's conditional formatting editor hands the lint the
5+
* object's field types and `multiple`, so `record.<list field> == 'x'` — a list
6+
* compared with a scalar, one constant answer on every row, so the rule never
7+
* styles anything — is refused (`list-equality`, with the membership rewrite)
8+
* while the author types. A membership test on the same field is accepted.
9+
*
10+
* Pinned against the REAL `@objectstack/formula` engine:
11+
* - the editor itself: `tags` (a `select` declared `multiple: true`) is the
12+
* list subject; `stage` (a plain `select`) is the scalar CONTROL; `'vip' in
13+
* record.tags` is the shape that does match;
14+
* - both mount sites hand the object's field definitions through: the view
15+
* variant inspector (metadata admin) and the Studio list-view panel's
16+
* "more" section.
17+
*
18+
* Direction: without `fieldDefs` reaching the editor no field is judged a list,
19+
* `record.tags == 'vip'` lints clean and the refusing cases are red; the
20+
* controls are green either way.
21+
*/
22+
23+
import '@testing-library/jest-dom/vitest';
24+
// The CEL authoring helpers load these through dynamic imports; paying the first
25+
// load at module top keeps it out of every clocked window (`check:test-source-alias`).
26+
import '@objectstack/formula';
27+
import '@objectstack/lint';
28+
import * as React from 'react';
29+
import { describe, it, expect, vi, afterEach } from 'vitest';
30+
import { render, screen, fireEvent, cleanup, waitFor, within } from '@testing-library/react';
31+
32+
const TICKET_FIELDS = {
33+
name: { name: 'name', label: 'Name', type: 'text' },
34+
tags: {
35+
name: 'tags', label: 'Tags', type: 'select', multiple: true,
36+
options: [{ value: 'vip', label: 'VIP' }, { value: 'new', label: 'New' }],
37+
},
38+
stage: {
39+
name: 'stage', label: 'Stage', type: 'select',
40+
options: [{ value: 'open', label: 'Open' }, { value: 'done', label: 'Done' }],
41+
},
42+
} as const;
43+
const TICKET = { name: 'ticket', label: 'Ticket', fields: TICKET_FIELDS };
44+
45+
const clients = vi.hoisted(() => ({
46+
fake: {
47+
get: async () => undefined,
48+
list: async () => [] as unknown[],
49+
listDrafts: async () => [] as unknown[],
50+
withPreviewDrafts() {
51+
return this;
52+
},
53+
},
54+
}));
55+
vi.mock('./useMetadata', async (importOriginal) => {
56+
const mod = await importOriginal<typeof import('./useMetadata')>();
57+
return { ...mod, useMetadataClient: () => clients.fake };
58+
});
59+
60+
import { ConditionalFormattingEditor, type ConditionalFormattingRuleDraft } from './ConditionalFormattingEditor';
61+
import { ViewVariantInspector } from './inspectors/ViewVariantInspector';
62+
import { ListViewMoreSection } from '../studio-design/ListViewMoreSection';
63+
import { mapObjectFields } from '../ViewConfigPanel';
64+
import { loaded } from './loadState';
65+
66+
afterEach(cleanup);
67+
68+
const t = (k: string) => k;
69+
const FIELD_DEFS = Object.values(TICKET_FIELDS).map((f) => ({
70+
name: f.name,
71+
type: f.type,
72+
multiple: 'multiple' in f ? f.multiple : undefined,
73+
}));
74+
const LIST_FINDING = /`record\.tags` holds a list/;
75+
76+
function EditorHarness({
77+
initial,
78+
report,
79+
}: {
80+
initial: string;
81+
report: (count: number) => void;
82+
}) {
83+
const [rules, setRules] = React.useState<ConditionalFormattingRuleDraft[]>([{ condition: initial, style: {} }]);
84+
return (
85+
<ConditionalFormattingEditor
86+
rules={rules}
87+
onChange={setRules}
88+
objectName="ticket"
89+
fieldNames={Object.keys(TICKET_FIELDS)}
90+
fieldDefs={FIELD_DEFS}
91+
t={t}
92+
onBlockingIssuesChange={report}
93+
/>
94+
);
95+
}
96+
97+
/** Type `source` into the first rule's condition inside `scope`. */
98+
function typeCondition(source: string, scope: HTMLElement = document.body) {
99+
const box = within(scope).getByTestId('cf-rule-0').querySelector('textarea') as HTMLElement;
100+
fireEvent.change(box, { target: { value: source } });
101+
}
102+
103+
describe('ConditionalFormattingEditor — list-equality while typing (#36459)', () => {
104+
it('refuses == on a select declared multiple: true, with the membership rewrite, and reports it as blocking', async () => {
105+
const report = vi.fn();
106+
render(<EditorHarness initial="" report={report} />);
107+
typeCondition("record.tags == 'vip'");
108+
await waitFor(() => expect(report.mock.calls.at(-1)?.[0]).toBe(1), { timeout: 5000 });
109+
const finding = await screen.findByText(LIST_FINDING);
110+
expect(finding.textContent).toMatch(/\bin\b/);
111+
});
112+
113+
it('refuses != on the same list field', async () => {
114+
const report = vi.fn();
115+
render(<EditorHarness initial="" report={report} />);
116+
typeCondition("record.tags != 'vip'");
117+
await waitFor(() => expect(report.mock.calls.at(-1)?.[0]).toBe(1), { timeout: 5000 });
118+
expect(await screen.findByText(LIST_FINDING)).toBeInTheDocument();
119+
});
120+
121+
it('accepts the membership test that does match a list', async () => {
122+
const report = vi.fn();
123+
render(<EditorHarness initial="" report={report} />);
124+
typeCondition("'vip' in record.tags");
125+
await waitFor(() => expect(report.mock.calls.at(-1)?.[0]).toBe(0), { timeout: 5000 });
126+
expect(screen.queryByText(/holds a list/)).toBeNull();
127+
});
128+
129+
it('CONTROL — == on a single-value select is clean', async () => {
130+
const report = vi.fn();
131+
render(<EditorHarness initial="" report={report} />);
132+
typeCondition("record.stage == 'open'");
133+
await waitFor(() => expect(report.mock.calls.at(-1)?.[0]).toBe(0), { timeout: 5000 });
134+
expect(screen.queryByText(/holds a list/)).toBeNull();
135+
});
136+
});
137+
138+
describe('both mount sites hand the editor the object’s field definitions (#36459)', () => {
139+
it('the view variant inspector refuses == on a list field in a formatting rule', async () => {
140+
function Harness() {
141+
const [draft, setDraft] = React.useState<Record<string, unknown>>({
142+
name: 'tickets',
143+
object: 'ticket',
144+
list: {
145+
type: 'grid',
146+
data: { provider: 'object', object: 'ticket' },
147+
columns: ['name'],
148+
conditionalFormatting: [{ condition: '', style: {} }],
149+
},
150+
});
151+
return (
152+
<ViewVariantInspector
153+
type="view"
154+
name="tickets"
155+
draft={draft}
156+
onPatch={(patch: Record<string, unknown>) => setDraft((d) => ({ ...d, ...patch }))}
157+
onSelectionChange={() => {}}
158+
onClearSelection={() => {}}
159+
readOnly={false}
160+
locale={'en-US'}
161+
variantKey="list"
162+
familyKey="list"
163+
isHome={false}
164+
objectFieldsOverride={mapObjectFields(TICKET as never)}
165+
/>
166+
);
167+
}
168+
render(<Harness />);
169+
const editor = await screen.findByTestId('cf-editor');
170+
typeCondition("record.tags == 'vip'", editor);
171+
expect(await within(editor).findByText(LIST_FINDING, {}, { timeout: 5000 })).toBeInTheDocument();
172+
});
173+
174+
it('the Studio list-view panel refuses == on a list field, and holds the autosave', async () => {
175+
const report = vi.fn();
176+
function Harness() {
177+
const [body, setBody] = React.useState<Record<string, unknown>>({
178+
type: 'grid',
179+
columns: ['name'],
180+
conditionalFormatting: [{ condition: '', style: {} }],
181+
});
182+
return (
183+
<ListViewMoreSection
184+
body={body}
185+
writeBody={setBody}
186+
objectName="ticket"
187+
fieldNames={Object.keys(TICKET_FIELDS)}
188+
fieldCatalog={loaded(FIELD_DEFS.map((f) => ({ ...f, multiple: f.multiple === true || undefined })))}
189+
readOnly={false}
190+
locale={'en-US'}
191+
onBlockingIssuesChange={report}
192+
/>
193+
);
194+
}
195+
render(<Harness />);
196+
const editor = screen.getByTestId('cf-editor');
197+
typeCondition("record.tags == 'vip'", editor);
198+
await waitFor(() => expect(report.mock.calls.at(-1)?.[0]).toBe(1), { timeout: 5000 });
199+
expect(within(editor).getByText(LIST_FINDING)).toBeInTheDocument();
200+
});
201+
});

‎ui/packages/app-shell/src/views/metadata-admin/ConditionalFormattingEditor.tsx‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { Button, Input, cn } from '@object-ui/components';
2929
import { Plus, Trash2, ChevronUp, ChevronDown } from 'lucide-react';
3030
import { CelPredicateField } from './CelPredicateField.js';
3131
import type { CelLintIssue } from './celAuthoring.js';
32+
import type { CelFieldDef } from './clientValidation.js';
3233

3334
/**
3435
* Scope roots bound at RUNTIME for a row predicate, advertised to autocomplete.
@@ -181,6 +182,16 @@ export interface ConditionalFormattingEditorProps {
181182
objectName?: string;
182183
/** Field names of {@link objectName} for autocomplete. */
183184
fieldNames?: string[];
185+
/**
186+
* The object's field definitions — each field's `type` and `multiple` —
187+
* handed to every rule's {@link CelPredicateField}, which reads the
188+
* list-valued ones through `isMultiValueField`. A condition such as
189+
* `record.tags == 'vip'` on a list field compares a list with a scalar, so
190+
* it never matches any row; with these it is refused while the author types
191+
* (`list-equality`, with the `in` rewrite). Omitted: no field is judged a
192+
* list, the lint is what it was before this prop.
193+
*/
194+
fieldDefs?: ReadonlyArray<CelFieldDef>;
184195
disabled?: boolean;
185196
/** i18n resolver (`(key) => string`). */
186197
t: (key: string) => string;
@@ -239,6 +250,7 @@ export function ConditionalFormattingEditor({
239250
onChange,
240251
objectName,
241252
fieldNames,
253+
fieldDefs,
242254
disabled,
243255
t,
244256
onBlockingIssuesChange,
@@ -377,6 +389,7 @@ export function ConditionalFormattingEditor({
377389
placeholder="record.status == 'overdue'"
378390
objectName={objectName}
379391
fieldNames={fieldNames}
392+
fieldDefs={fieldDefs}
380393
// Row predicates bind the row as `record.*` and nothing else at
381394
// runtime — `83fe6e741` (Phase 2 of the objectui#5330 canon)
382395
// retired the bare shorthand and `data.*`. So this lints in the

‎ui/packages/app-shell/src/views/metadata-admin/inspectors/ViewVariantInspector.tsx‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,13 @@ export function ViewVariantInspector({
281281
// (e.g. CelPredicateField / ConditionalFormattingEditor).
282282
const tLocal = React.useCallback((k: string) => t(k, locale), [locale]);
283283
const fieldNames = React.useMemo(() => objectFields.map((f) => f.name), [objectFields]);
284+
// Each field's `type` and `multiple`, so a formatting rule that compares a
285+
// list field with a scalar is refused while typing. Memoized: the CEL editor
286+
// re-derives its list-valued fields only when this identity changes.
287+
const celFieldDefs = React.useMemo(
288+
() => objectFields.map((f) => ({ name: f.name, type: f.type, multiple: f.multiple })),
289+
[objectFields],
290+
);
284291
const cfRules = Array.isArray(variant.conditionalFormatting)
285292
? (variant.conditionalFormatting as unknown[])
286293
: [];
@@ -539,6 +546,7 @@ export function ViewVariantInspector({
539546
rules={cfRules as any}
540547
objectName={binding.value || undefined}
541548
fieldNames={fieldNames}
549+
fieldDefs={celFieldDefs}
542550
disabled={readOnly}
543551
t={tLocal}
544552
onChange={(rules) =>

‎ui/packages/app-shell/src/views/studio-design/ListViewMoreSection.tsx‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,21 @@ export function ListViewMoreSection({
114114
const rules = Array.isArray(body.conditionalFormatting) ? (body.conditionalFormatting as unknown[]) : [];
115115
const form = React.useMemo(() => panelViewForm(locale), [locale]);
116116
const schema = getListVariantSchema();
117+
// Each field's `type` and `multiple` from the loaded catalog, so a formatting
118+
// rule that compares a list field with a scalar is refused while typing. The
119+
// CEL editor keys its lint on the list-valued names, not on this array.
120+
const fieldDefs =
121+
fieldCatalog.status === 'loaded'
122+
? fieldCatalog.data.map((f) => ({ name: f.name, type: f.type, multiple: f.multiple }))
123+
: undefined;
117124
return (
118125
<div className="space-y-3 border-t pt-3" data-testid="list-view-more">
119126
<div data-testid="list-view-conditional-formatting">
120127
<ConditionalFormattingEditor
121128
rules={rules as never}
122129
objectName={objectName}
123130
fieldNames={fieldNames}
131+
fieldDefs={fieldDefs}
124132
disabled={readOnly}
125133
t={tLocal}
126134
onChange={(next) => {

0 commit comments

Comments
 (0)