Skip to content

Commit 6aacad9

Browse files
fix(ui): condition editors offer a multiple: true field only what its evaluator answers (#36165)
<!-- claude-projects-attribution: {"github_login":"os-project-manager"} --> _Requested by **Leehom** · [project thread](https://claude.ai/code/project/chan_01TenzsRopZj4jMbvjX8uz1X?thread=cmsg_01TenzsRopZj4jMbvjX8uz1XP3RHGWUG7UH3fNa4tBa9UC)_ Part of #35992 — the condition-editor half. The dashboard filter bar half is left open on the card: it is built on its own branch under the same claim, route A per seat note 7066557346 (see Acceptance notes). Clause-②: no Metadata-protocol: none ## 维护者速读 - 在工作室里给"多选"字段(例如可选多人的负责人字段)写条件时,下拉框现在只给"包含 / 不包含 / 为空 / 不为空",不再给一定出错或算错的"等于 / 属于";仪表盘筛选栏这一半没改。 - 属于"多值字段筛选"这组修复,接着上一张让列表筛选支持多值字段的卡做完条件编辑器部分。 - 影响写共享规则条件、数据集筛选、关联列表筛选和流程分支条件的管理员;只改界面给出的选项,已存的条件原样不动,可以直接撤回。 - 要你做的一件事:无。仪表盘筛选栏那一半已由席位定为路线 A(可选的 DataSource 读数据集定义),在同卡另一分支施工。 ## What changes A `select` / `lookup` / `user` field declared `multiple: true` stores a list. The condition editors built their field lists without `multiple`, so the shared `FilterBuilder` treated such a field as single-value and offered `Equals` / `Is any of`. Each editor's evaluator was measured first (below); every one of them refuses or mis-answers those operators, so each now passes `multiple` and the builder offers `jsonColumnFilterOperators`' set (Contains, Does not contain, Is empty, Is not empty). No operator table is copied: every surface asks `operatorsForField` / `jsonColumnFilterOperators`. | Editor | Evaluator | Measured on a list-valued field | Change | |---|---|---|---| | `@object-ui/fields` `FilterConditionField` (sharing-rule criteria, roll-up filters) | engine `find` (data door) | `=` and `$in`: 400 `INVALID_FILTER`; `$contains`, `$or` of `$contains`: rows | passes `multiple` | | Studio `FilterConditionField` + `datasetFilterCondition` (dataset scope / measure filter) | `POST /analytics/dataset/query` | `=` and `$in`: **200 with a count of 0**; `$contains` / `$notContains` / `$empty`: right counts | passes `multiple`; read-back asks `operatorsForField`, so a stored `$eq` / `$in` there opens in Source instead of as an `equals` row | | same editor, a field's `relatedListFilter` | data door | as the first row | passes `multiple` | | Studio flow edge rows (`flow-edge-condition-rows`) | `celEngine` (CEL) | `S == 'u1'` false for `['u1','u2']`; `S.contains('u1')` faults (no overload for list); `'u1' in S` true | passes `multiple`; `contains` / `not_contains` on a list write `S != null && V in S` / `S == null \|\| !(V in S)` and read back; offered set read from `operatorsForField` | The flow rows and the CEL `ConditionBuilder` read their fields from `useObjectFields`, which now carries the served `multiple` (one more read of the same payload, like `required` / `system`). Read first, by risk: 1. `ui/packages/app-shell/src/views/metadata-admin/inspectors/flow-edge-condition-rows.ts` — the membership spellings and the two new read-back patterns (`celToRows` adopts a guard only when `rowsToCel` re-writes it byte for byte). 2. `ui/packages/app-shell/src/views/metadata-admin/inspectors/datasetFilterCondition.ts` — `builderHolds` / `readBackOperator` now ask `operatorsForField(type, multiple)`; a stored `$in` on a list field stops opening as a row. 3. `ui/packages/app-shell/src/views/metadata-admin/previews/useObjectFields.ts` — the `multiple` projection. It also makes `ConditionBuilder`'s existing multi-value 「is empty」 arm reachable from the hook path (it was reachable only through a `fields` prop). Two-minute check: `pnpm --dir ui exec vitest run packages/app-shell/src/views/metadata-admin/inspectors/flow-edge-condition-rows.multiValue-35992.test.ts`. Expect 12 passed. Each spelling there is evaluated by `celEngine`. ## Tests New files named for the card: - `flow-edge-condition-rows.multiValue-35992.test.ts`: the offered set is the helper's. Contains and Does not contain write membership, read back, and the engine answers them on a list, on null, and as any-of. The `==` control is false. A single-value column keeps its equality spelling. - `FlowEdgeInspector.multiValue-35992.test.tsx`: a membership guard on a `multiple: true` user column opens as one row. Its real operator dropdown lists exactly Contains / Does not contain / Is empty / Is not empty. - `datasetFilterCondition.multiValue-35992.test.tsx`: both field catalogs (`buildFieldOptions`, `useObjectFields`) mark exactly the `multiple: true` columns. `$contains` / `$notContains` / `$empty` open as rows, and `$eq` / `$in` go to Source. Single-value controls still open `$eq` / `$in` as rows. - `FilterConditionField.multipleField-35992.test.tsx` (fields): a `multiple: true` user / lookup / select column's real operator dropdown equals `operatorsForField`'s labels. Single-value controls keep Equals. <details><summary>Reverse verification (source at base, new tests kept)</summary> Committed first. The nine source files were then restored to the base `30b0987c` with the new tests kept: **19 failed / 10 passed** (the passing 10 are the single-value controls and the refusal rows). Restored with `git checkout HEAD -- PATH`. `git diff HEAD` came back empty, and all nine `git hash-object` values matched the HEAD blobs. </details> <details><summary>Affected suites</summary> `pnpm --dir ui exec vitest run --maxWorkers=2 packages/app-shell/src/views/metadata-admin/inspectors/ packages/app-shell/src/views/metadata-admin/previews/useObjectFields.draftOverlay-11895.test.tsx packages/fields/src/widgets/__tests__/` → Test Files 279 passed (279), Tests 3679 passed, 1 skipped (3680). The full `@object-ui/app-shell` / `@object-ui/fields` suites are CI's (`Test UI`). </details> ## Acceptance notes - **Dashboard filter bar: not in this PR.** `buildFilterCondition` lowers a select / lookup global filter to `=` / `$in` with no knowledge of the bound field. That field's definition is not reachable at the binding site. A dataset-bound widget learns its base object only from its own query's answer (`AnalyticsResult.object`; `DashboardView` says the same), and the `DataSource` interface has no read for a dataset's definition. The seat ruled route A for it (seat note 7066557346): an optional `DataSource` member that reads a dataset definition, built on its own branch under the same claim. - **Premise correction, measured:** on the dashboard's door, `POST /api/v1/analytics/dataset/query` on `showcase_project_metrics` with `runtimeFilter: { labels: 'frontend' }` or `{ labels: { $in: [...] } }`, the server does not refuse with 400. It answers 200 with a count of 0 (SqlDriver, better-sqlite3). The data door refuses the same filters with 400. `$contains` gives 2, an `$or` of two `$contains` gives 3, and the substring `fron` gives 0, so this is real membership. That difference between the two doors is tracked as #36168, not fixed here. - The CEL `ConditionBuilder` (hook conditions, action visibility, page-block visibility) is not on the shared builder. On a list subject its `==` / `!=` give a constant answer, measured with `celEngine`, and `validateExpression` accepts `record.labels == 'frontend'` with no warning. It is tracked as #36167; its fix needs a membership operator in that builder, which is out of this card's mechanism. - The Studio view / page-block filter (`FilterBuilderField` in `metadata-admin/widgets.tsx`) builds its fields without `multiple` too. It is outside this claim's file surface and is tracked as #36169. ## Verification <details><summary>Local gates</summary> All 38 families from `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack` exited 0, each exit code captured before any pipe. `--ran` reconciliation: 38 derived, 38 run, 0 NOT-MEASURED, and the zero is derived because every family recorded an exit code. After the `@object-ui/app-shell^...` dependency closure was built, `pnpm --filter @object-ui/fields run type-check` and `pnpm --filter @object-ui/app-shell run type-check` both exited 0, each covering the `src` program and `tsconfig.test.json`. `ui/scripts/check-new-cross-file-line-citations.mjs` reported 0 new citations. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01FEkQ5okniknzVVR3KTSVr1)_ <!-- signed: repo:objectstack#4 · os-project-manager · session_01FEkQ5okniknzVVR3KTSVr1 --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 04f9861 commit 6aacad9

14 files changed

Lines changed: 547 additions & 22 deletions
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
'@object-ui/fields': patch
3+
'@object-ui/app-shell': patch
4+
'@object-ui/console': patch
5+
---
6+
7+
fix(fields, console): condition editors offer a multiple: true field only what its evaluator answers
8+
9+
Clause-②: no
10+
Metadata-protocol: none
11+
12+
A `select`, `lookup` or `user` field declared `multiple: true` holds a list, and the condition editors used to treat it as a single value: they offered Equals and Is any of on it. The engine refuses those operators on such a field with 400 `INVALID_FILTER`, a dataset filter answered them with 0, and a flow edge guard written as `record.attendees == 'u1'` is false for every record. Each editor now passes the field's `multiple` to the shared filter builder, which offers such a field Contains, Does not contain, Is empty and Is not empty, the operators a `multiselect` already got:
13+
14+
- the criteria editor (`@object-ui/fields` `FilterConditionField`, e.g. a sharing rule's criteria);
15+
- the Studio filter editor for a dataset's scope and measure filters and a field's related-list filter. A stored `$eq` or `$in` on such a field now opens in Source instead of as an Equals row;
16+
- the Studio flow edge rows. On a list-valued field they write Contains as CEL list membership, `record.attendees != null && 'u1' in record.attendees`, and Does not contain as `record.attendees == null || !('u1' in record.attendees)`. A guard spelled that way opens as a row again.
17+
18+
A single-value field of the same types keeps its operators. The Studio field list now carries the declared `multiple`, so the CEL condition builder also words and writes Is empty on such a field as an empty list, as the spec's 「is empty」 table says. No metadata key, value or default changes.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ export function DatasetDefaultInspector({
458458
// Base-object fields for the filter builders (scope + measure filters operate on
459459
// the base table; relationship-path filters are out of scope for v1).
460460
const filterFields = React.useMemo(
461-
() => fieldOptions.filter((f) => !f.value.includes('.')).map((f) => ({ value: f.value, label: f.label, type: f.type })),
461+
() => fieldOptions.filter((f) => !f.value.includes('.')).map((f) => ({ value: f.value, label: f.label, type: f.type, ...(f.multiple ? { multiple: true } : {}) })),
462462
[fieldOptions],
463463
);
464464
const datasetFilter = draft.filter && typeof draft.filter === 'object' ? (draft.filter as FilterCondition) : undefined;

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,13 @@ export function FilterConditionField({ label, help, value, onCommit, fields, dis
3434
help?: string;
3535
value: FilterCondition | undefined;
3636
onCommit: (fc: FilterCondition | undefined) => void;
37-
fields: Array<{ value: string; label?: string; type?: string }>;
37+
/**
38+
* The columns the rows may name. `multiple` is the field's declared
39+
* `multiple: true`: with the type it decides which operators a row offers
40+
* (`jsonColumnFilterOperators`), and which ones a stored filter can be read
41+
* back as (`conditionToGroup`).
42+
*/
43+
fields: Array<{ value: string; label?: string; type?: string; multiple?: boolean }>;
3844
disabled?: boolean;
3945
locale: SupportedLocale;
4046
/**
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* objectstack#35992 — the edge inspector hands its rows a column's declared
5+
* `multiple`, so a guard on a list-valued column opens as the membership row
6+
* the rows write for it (`flow-edge-condition-rows`), and a fresh row on that
7+
* column is offered membership and the empty checks only.
8+
*
9+
* Direction: without `multiple` reaching the rows, `attendees` is a single-value
10+
* `user` column, whose bucket offers no `contains`, so the stored membership
11+
* guard opens in the formula input and the dropdown offers `Equals`.
12+
*/
13+
14+
import { describe, it, expect, vi, afterEach } from 'vitest';
15+
import { render, screen, fireEvent, cleanup, waitFor, within } from '@testing-library/react';
16+
import '@testing-library/jest-dom';
17+
18+
vi.mock('../previews/useObjectFields', () => ({
19+
useObjectFields: (objectName?: string) => ({
20+
fields: objectName
21+
? [
22+
{ name: 'topic', label: 'Topic', type: 'text', hidden: false },
23+
{ name: 'attendees', label: 'Attendees', type: 'user', hidden: false, multiple: true },
24+
]
25+
: [],
26+
loading: false,
27+
error: null,
28+
}),
29+
}));
30+
31+
import { FlowEdgeInspector } from './FlowEdgeInspector';
32+
import type { MetadataSelection } from '../preview-registry';
33+
34+
afterEach(cleanup);
35+
36+
function draftWith(condition: unknown) {
37+
return {
38+
nodes: [
39+
{ id: 'start', type: 'start', config: { triggerType: 'record-after-create', objectName: 'meeting_note' } },
40+
{ id: 'route', type: 'decision', label: 'Route' },
41+
{ id: 'soon', type: 'end', label: 'Soon' },
42+
],
43+
edges: [
44+
{ id: 'e1', source: 'start', target: 'route' },
45+
{ id: 'e2', source: 'route', target: 'soon', ...(condition === undefined ? {} : { condition }) },
46+
],
47+
};
48+
}
49+
50+
function renderEdge(draft: Record<string, unknown>) {
51+
const onPatch = vi.fn();
52+
const selection: MetadataSelection = { kind: 'edge', id: 'e2' };
53+
render(
54+
<FlowEdgeInspector
55+
type="flow"
56+
name="meeting_flow"
57+
selection={selection}
58+
draft={draft}
59+
onPatch={onPatch}
60+
onClearSelection={vi.fn()}
61+
locale="en-US"
62+
readOnly={false}
63+
/>,
64+
);
65+
return onPatch;
66+
}
67+
68+
describe('edge rows on a multiple: true column (objectstack#35992)', () => {
69+
it('a membership guard on it opens as one row', () => {
70+
renderEdge(draftWith("record.attendees != null && 'u1' in record.attendees"));
71+
expect(screen.getByTestId('flow-edge-condition-rows')).toHaveTextContent('1 condition');
72+
expect(screen.queryByPlaceholderText(/CEL expression/)).toBeNull();
73+
});
74+
75+
it('its operator dropdown offers membership and the empty checks only', async () => {
76+
renderEdge(draftWith("record.attendees != null && 'u1' in record.attendees"));
77+
fireEvent.click(screen.getByTestId('flow-edge-condition-rows'));
78+
// The builder's row inside the popover: field (0), operator (1).
79+
const triggers = within(await screen.findByRole('dialog')).getAllByRole('combobox');
80+
fireEvent.keyDown(triggers[1], { key: 'ArrowDown' });
81+
const offered = await waitFor(() => {
82+
const options = screen.getAllByRole('option').map((o) => o.textContent);
83+
expect(options.length).toBeGreaterThan(0);
84+
return options;
85+
});
86+
expect(offered).toEqual(['Contains', 'Does not contain', 'Is empty', 'Is not empty']);
87+
});
88+
});

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ export function FlowEdgeInspector({
107107
value: `${trigger.fieldPrefix}${f.name}`,
108108
label: f.label || f.name,
109109
type: f.type,
110+
// A list-valued column is offered membership, not equality
111+
// (`flow-edge-condition-rows`' multi-value spellings).
112+
...(f.multiple ? { multiple: true } : {}),
110113
...(f.options ? { options: f.options } : {}),
111114
}))
112115
: [],

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3123,6 +3123,7 @@ function RelatedListFields({
31233123
value: e.name,
31243124
label: typeof e.def.label === 'string' && e.def.label ? (e.def.label as string) : e.name,
31253125
type: typeof e.def.type === 'string' ? (e.def.type as string) : 'text',
3126+
...(e.def.multiple === true ? { multiple: true } : {}),
31263127
})),
31273128
[ownFields],
31283129
);
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* objectstack#35992 — the Studio's FilterCondition editor (`FilterConditionField`
5+
* behind `datasetFilterCondition`: a dataset's scope and measure filters, a
6+
* field's `relatedListFilter`) learns a column's declared `multiple`.
7+
*
8+
* The evaluators behind it were measured on a live showcase backend
9+
* (`SqlDriver`, better-sqlite3), on `showcase_project.labels` (multiselect)
10+
* holding `["frontend","qa"]`, `["backend"]`, `["frontend","design"]`:
11+
*
12+
* - the data door (`POST /data/:object/query`, a related list's read)
13+
* refuses `{ labels: 'frontend' }` and `$in` with 400 and answers
14+
* `$contains` with rows;
15+
* - the dataset door (`POST /analytics/dataset/query`, a dataset's filter)
16+
* answers the same `=` / `$in` with a count of 0, and `$contains` /
17+
* `$notContains` / `$empty` with the right counts.
18+
*
19+
* So on a list-valued column the editor offers what the shared builder offers
20+
* it (`operatorsForField`): membership and the empty checks. A stored `$eq` /
21+
* `$in` there is not a row the builder can draw — it opens in Source rather
22+
* than as an `equals` row a sibling edit would re-commit.
23+
*/
24+
25+
import { describe, it, expect, vi, afterEach } from 'vitest';
26+
import { renderHook, waitFor, cleanup } from '@testing-library/react';
27+
import { conditionToGroup, type BuilderFieldDef } from './datasetFilterCondition';
28+
import { buildFieldOptions, normalizeObject } from './useDatasetFields';
29+
30+
// One client for every render: the hook's effect keys on the client's
31+
// identity, so a fresh object per call would re-run it without end.
32+
const h = vi.hoisted(() => {
33+
const state = { doc: undefined as unknown };
34+
const client = { withPreviewDrafts: () => ({ get: async () => state.doc }) };
35+
return { state, client };
36+
});
37+
38+
vi.mock('../useMetadata', async (importOriginal) => ({
39+
...(await importOriginal<Record<string, unknown>>()),
40+
useMetadataClient: () => h.client,
41+
}));
42+
43+
import { useObjectFields } from '../previews/useObjectFields';
44+
45+
afterEach(cleanup);
46+
47+
const OBJECT_DOC = {
48+
name: 'project',
49+
label: 'Project',
50+
fields: {
51+
owners: { type: 'user', label: 'Owners', multiple: true },
52+
accounts: { type: 'lookup', label: 'Accounts', reference: 'account', multiple: true },
53+
regions: { type: 'select', label: 'Regions', multiple: true, options: [{ value: 'emea', label: 'EMEA' }] },
54+
owner: { type: 'user', label: 'Owner' },
55+
region: { type: 'select', label: 'Region', options: [{ value: 'emea', label: 'EMEA' }] },
56+
},
57+
};
58+
59+
const MULTI = ['owners', 'accounts', 'regions'];
60+
const SINGLE = ['owner', 'region'];
61+
62+
describe('the field catalogs carry a column’s declared multiple (objectstack#35992)', () => {
63+
it('the dataset catalog marks exactly the multiple: true columns', () => {
64+
const options = buildFieldOptions(normalizeObject(OBJECT_DOC, 'project'), [], {});
65+
expect(options.filter((o) => o.multiple === true).map((o) => o.value)).toEqual(MULTI);
66+
expect(options.filter((o) => SINGLE.includes(o.value)).every((o) => !('multiple' in o))).toBe(true);
67+
});
68+
69+
it('the object field hook marks exactly the multiple: true columns', async () => {
70+
h.state.doc = OBJECT_DOC;
71+
const hook = renderHook(() => useObjectFields('project'));
72+
await waitFor(() => expect(hook.result.current.loading).toBe(false));
73+
const fields = hook.result.current.fields;
74+
expect(fields.filter((f) => f.multiple === true).map((f) => f.name)).toEqual(MULTI);
75+
expect(fields.filter((f) => SINGLE.includes(f.name)).every((f) => !('multiple' in f))).toBe(true);
76+
});
77+
});
78+
79+
describe('a stored filter on a multiple: true column reads back as the builder can draw it', () => {
80+
const fields: BuilderFieldDef[] = Object.entries(OBJECT_DOC.fields).map(([value, f]) => ({
81+
value,
82+
type: f.type,
83+
...('multiple' in f && f.multiple ? { multiple: true } : {}),
84+
}));
85+
86+
it.each(MULTI)('%s: $contains / $notContains / $empty open as rows', (field) => {
87+
for (const [stored, operator] of [
88+
[{ [field]: { $contains: 'x' } }, 'contains'],
89+
[{ [field]: { $notContains: 'x' } }, 'not_contains'],
90+
[{ [field]: { $empty: true } }, 'is_empty'],
91+
] as const) {
92+
const read = conditionToGroup(stored, fields);
93+
expect(read.representable, JSON.stringify(stored)).toBe(true);
94+
expect(read.group.conditions.map((c) => c.operator)).toEqual([operator]);
95+
}
96+
});
97+
98+
it.each(MULTI)('%s: $eq / $in go to Source, not to an equals row', (field) => {
99+
for (const stored of [{ [field]: 'x' }, { [field]: { $in: ['x'] } }]) {
100+
expect(conditionToGroup(stored, fields).representable, JSON.stringify(stored)).toBe(false);
101+
}
102+
});
103+
104+
it.each(SINGLE)('%s (single-value control): $eq / $in still open as rows', (field) => {
105+
for (const stored of [{ [field]: 'x' }, { [field]: { $in: ['x'] } }]) {
106+
expect(conditionToGroup(stored, fields).representable, JSON.stringify(stored)).toBe(true);
107+
}
108+
});
109+
});

‎ui/packages/app-shell/src/views/metadata-admin/inspectors/datasetFilterCondition.ts‎

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
* the ambiguous tokens against the field's own operator bucket (objectui#9382).
3535
*/
3636

37-
import { isFilterValueComplete, operatorsForFieldType } from '@object-ui/components';
37+
import { isFilterValueComplete, operatorsForField } from '@object-ui/components';
3838

3939
/**
4040
* FilterBuilder operator → FilterCondition Mongo operator.
@@ -116,7 +116,17 @@ const MONGO_PREIMAGE: Record<string, readonly string[]> = (() => {
116116
})();
117117

118118
/** A field as the inspector already describes it to the builder. */
119-
export interface BuilderFieldDef { value: string; label?: string; type?: string }
119+
export interface BuilderFieldDef {
120+
value: string;
121+
label?: string;
122+
type?: string;
123+
/**
124+
* The field's declared `multiple: true`. With the type it decides the
125+
* operators the builder offers the column (`operatorsForField`): a
126+
* list-valued column takes membership and the empty checks only.
127+
*/
128+
multiple?: boolean;
129+
}
120130

121131
/**
122132
* Which builder operator a stored token reads back as, on a field of this type.
@@ -143,9 +153,9 @@ export interface BuilderFieldDef { value: string; label?: string; type?: string
143153
*
144154
* Among the operators that write this token, pick the one THIS field's bucket
145155
* offers. The bucket table is asked rather than copied, so the answer cannot
146-
* disagree with what the dropdown actually lists; `operatorsForFieldType` is
147-
* called with no opt-in extras because that is how the inspector mounts the
148-
* builder.
156+
* disagree with what the dropdown actually lists; `operatorsForField` (the
157+
* type and `multiple`) is called with no opt-in extras because that is how the
158+
* inspector mounts the builder.
149159
*
150160
* ⛔ Deliberately not a widening. When the type is unknown, or when the bucket
151161
* offers neither candidate or both, this falls back to {@link MONGO_TO_OP} —
@@ -155,10 +165,10 @@ export interface BuilderFieldDef { value: string; label?: string; type?: string
155165
* Whether the fallback can then be drawn is not this function's question:
156166
* {@link builderHolds} asks it of every row, this one included.
157167
*/
158-
function readBackOperator(mop: string, fieldType: string | undefined): string | undefined {
168+
function readBackOperator(mop: string, field: BuilderFieldDef | undefined): string | undefined {
159169
const candidates = MONGO_PREIMAGE[mop];
160-
if (fieldType && candidates && candidates.length > 1) {
161-
const offered = new Set(operatorsForFieldType(fieldType).map((o) => o.value));
170+
if (field?.type && candidates && candidates.length > 1) {
171+
const offered = new Set(operatorsForField(field).map((o) => o.value));
162172
const settled = candidates.filter((c) => offered.has(c));
163173
if (settled.length === 1) return settled[0];
164174
}
@@ -351,7 +361,9 @@ export function groupToCondition(group: BuilderGroup | undefined): FilterConditi
351361
* reconciles it to `equals` and reshapes the value, committing a different
352362
* filter than the one stored (the objectui#9382 defect). The bucket is
353363
* asked exactly as the builder asks it for each row:
354-
* `operatorsForFieldType` of the listed column's type, no opt-ins. A column
364+
* `operatorsForField` of the listed column's type and `multiple`, no
365+
* opt-ins, so a list-valued column holds only membership and the empty
366+
* checks — a stored `$in` / `$eq` on one goes to the Source tab. A column
355367
* listed without a type, or not listed at all, gets the builder's default
356368
* text bucket for both — the bucket the panel WOULD draw, not an unknown
357369
* one. Only a read with NO field list skips this: no caller that draws a
@@ -364,8 +376,8 @@ export function groupToCondition(group: BuilderGroup | undefined): FilterConditi
364376
function builderHolds(row: BuilderCondition, fields: ReadonlyArray<BuilderFieldDef> | undefined): boolean {
365377
if (groupToCondition({ logic: 'and', conditions: [row] }) === undefined) return false;
366378
if (!fields) return true;
367-
const fieldType = fields.find((f) => f.value === row.field)?.type;
368-
return operatorsForFieldType(fieldType).some((o) => o.value === row.operator);
379+
const field = fields.find((f) => f.value === row.field);
380+
return operatorsForField(field).some((o) => o.value === row.operator);
369381
}
370382

371383
/**
@@ -432,7 +444,7 @@ export function conditionToGroup(
432444
// builder can draw.
433445
row = { id: `c${i}`, field, operator: v.$null ? 'is_null' : 'is_not_null', value: '' };
434446
} else {
435-
const op = readBackOperator(mop, fields?.find((f) => f.value === field)?.type);
447+
const op = readBackOperator(mop, fields?.find((f) => f.value === field));
436448
if (!op) return { group: empty, representable: false };
437449
row = { id: `c${i}`, field, operator: op, value: v[mop] };
438450
}

0 commit comments

Comments
 (0)