From 37dd2fdaa27cc45a4fad0f0fe910c733f75050fe Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 21 Nov 2026 03:39:51 +0000 Subject: [PATCH 1/7] fix(ui): offer a multi-value field only the filter operators the server accepts The list's quick filter and the shared FilterBuilder keyed operators on the field type alone, so a multi-select offered equals / in, which the server refuses on a JSON column. Both now read one helper, jsonColumnFilterOperators, keyed on the type and multiple through the spec's own sets. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01Utp6CZiaBg6rk7dpy1s9Me --- .../components/src/custom/filter-builder.tsx | 140 ++++++++++++++---- ui/packages/components/src/custom/index.ts | 3 + ui/packages/plugin-list/src/ListView.tsx | 5 +- .../src/conditions/FilterValuePanel.tsx | 6 +- .../src/conditions/conditionModel.ts | 21 ++- 5 files changed, 145 insertions(+), 30 deletions(-) diff --git a/ui/packages/components/src/custom/filter-builder.tsx b/ui/packages/components/src/custom/filter-builder.tsx index 2810b3a84c2..f440145ffec 100644 --- a/ui/packages/components/src/custom/filter-builder.tsx +++ b/ui/packages/components/src/custom/filter-builder.tsx @@ -16,7 +16,13 @@ import { normalizeFilterOperator, type ViewFilterRule, } from "@objectstack/spec/ui" -import { DATE_RANGE_PRESETS, expandEmptyOperator, type DateRangePreset } from "@objectstack/spec/data" +import { + DATE_RANGE_PRESETS, + STRUCTURED_JSON_TYPES, + expandEmptyOperator, + isMultiValueField, + type DateRangePreset, +} from "@objectstack/spec/data" import { SchemaRendererContext, useSettledSchema } from "@object-ui/react" import { FILTER_DATE_LIKE_TYPES, @@ -152,6 +158,12 @@ export interface FilterBuilderProps { label: string type?: string options?: Array<{ value: string; label: string }> // For select fields + /** + * The field's declared `multiple` flag. With the type it decides whether + * the field's value is a list, so which operators the row offers + * ({@link jsonColumnFilterOperators}). + */ + multiple?: boolean /** For lookup/master_detail/user fields — referenced object name */ referenceTo?: string /** Display field on the referenced object (defaults to "name") */ @@ -961,6 +973,7 @@ export function retypeFilterValue( /** The shape of a `fields` entry that the option-domain helpers below read. */ type OptionBearingField = { type?: string + multiple?: boolean options?: ReadonlyArray<{ value: string; label: string }> } @@ -1048,7 +1061,12 @@ function isOptionDrivenValueControl( case "pair": return false default: - return selectLikeTypes.includes(type) || lookupLikeTypes.includes(type) + // A multi-value option field's `contains` picks ONE of its options. + return ( + selectLikeTypes.includes(type) || + lookupLikeTypes.includes(type) || + jsonColumnFilterOperators(field) !== undefined + ) } } @@ -1380,30 +1398,87 @@ export function operatorsForFieldType( */ const NULLNESS_PAIR: ReadonlySet = new Set(["is_null", "is_not_null"]) +/** The two facts of a field descriptor that decide what its value is stored as. */ +export interface FilterFieldStorageFacts { + type?: string + multiple?: boolean +} + /** - * Which row of the spec's ruled 「is empty」 table a column of `fieldType` - * takes — read from `@objectstack/spec`'s `expandEmptyOperator`, the one - * function every server face expands `$empty` with, never from a local type - * list (objectui#11810): + * Which row of the spec's ruled 「is empty」 table a column takes — read from + * `@objectstack/spec`'s `expandEmptyOperator`, the one function every server + * face expands `$empty` with, never from a local type list (objectui#11810): * * - `text` — text-like types: `is_empty` matches null OR `''`; - * - `multi_value` — list-valued types: `is_empty` matches null OR `[]`; + * - `multi_value` — list-valued fields: `is_empty` matches null OR `[]`; * - `null_only` — every other type: `is_empty` matches null only, which is * exactly what `is_null` matches. * - * Keyed on the TYPE alone because that is all a field descriptor here carries: - * a `lookup` / `user` / `select` declared `multiple: true` is `multi_value` on - * the server and is judged `null_only` here. The pair it is then offered, - * `is_empty` / `is_not_empty`, is the one whose server expansion counts `[]`. + * Keyed on the type AND `multiple`, as the spec function is: a `lookup` / + * `user` / `select` declared `multiple: true` is `multi_value`. A host that + * does not pass `multiple` gets the type's own row. */ -function emptyCheckArm(fieldType: string | undefined) { - return expandEmptyOperator({ type: fieldType || "text" }).arm +function emptyCheckArm(field: FilterFieldStorageFacts | undefined) { + return expandEmptyOperator({ type: field?.type || "text", multiple: field?.multiple === true }).arm +} + +/** + * The operators a field stored as a JSON column takes in a filter, or + * `undefined` for every other field (whose operators follow its type bucket). + * + * The server refuses the equality, membership-list, ordering and text-match + * operators on such a field with `400 INVALID_FILTER` — the set + * `JSON_COLUMN_INCOMPATIBLE_OPERATORS` in `@objectstack/core` — and accepts + * `$contains` / `$notContains` (membership) and the null predicates. The + * builder therefore offers only what the server answers: + * + * - a MULTI-VALUE field (`isMultiValueField`: `multiselect` / `checkboxes` / + * `tags`, or a multi-capable type with `multiple: true`) — `contains` / + * `not_contains`, one member each (the spec's `$contains` takes ONE + * comparand), and `is_empty` / `is_not_empty`, whose `$empty` expansion + * counts `[]`; + * - a STRUCTURED-JSON field (`STRUCTURED_JSON_TYPES`: `json`, `address`, …) + * — `is_empty` / `is_not_empty` only: the server's membership test is + * array-only, so a member picked for an object value matches nothing. + * + * Decided from the same two field facts the server's faces read (the + * engine's `declaredJsonStoredFields`: `STRUCTURED_JSON_TYPES` or + * `isMultiValueField`), through the spec's own sets — never a local type list. + * Shared by every filter surface that offers operators per field, so the + * list's quick filter and this builder cannot disagree. + */ +export function jsonColumnFilterOperators( + field: FilterFieldStorageFacts | undefined, +): readonly FilterBuilderOperator[] | undefined { + const type = field?.type || "text" + if (isMultiValueField({ type, multiple: field?.multiple === true })) return MULTI_VALUE_FIELD_OPERATORS + if (STRUCTURED_JSON_TYPES.has(type)) return STRUCTURED_JSON_FIELD_OPERATORS + return undefined +} + +const MULTI_VALUE_FIELD_OPERATORS: readonly FilterBuilderOperator[] = ["contains", "not_contains", "is_empty", "is_not_empty"] +const STRUCTURED_JSON_FIELD_OPERATORS: readonly FilterBuilderOperator[] = ["is_empty", "is_not_empty"] + +/** + * The operators a fresh choice on this FIELD is offered: the JSON-column set + * when the field is stored as one ({@link jsonColumnFilterOperators}), + * otherwise its type bucket ({@link operatorsForFieldType}). + * + * @internal exported for tests + */ +export function operatorsForField( + field: FilterFieldStorageFacts | undefined, + extraOperators: readonly string[] = [], +): ReadonlyArray<{ value: string; label: string }> { + const json = jsonColumnFilterOperators(field) + if (!json) return operatorsForFieldType(field?.type, extraOperators) + return defaultOperators.filter((op) => json.includes(op.value)) } /** * The operators the dropdown MOUNTS for one row (objectui#11810). * - * {@link operatorsForFieldType}, minus `is_null` / `is_not_null` on a column + * {@link operatorsForField}, minus `is_null` / `is_not_null` on a column * whose type cannot tell empty from null (`null_only`, see * {@link emptyCheckArm}). There the two pairs are one predicate under two * labels — every dialect this builder writes expands `is_empty` on such a @@ -1414,18 +1489,26 @@ function emptyCheckArm(fieldType: string | undefined) { * * The row's OWN operator is always mounted. A stored filter that already * reads `is_null` on a `select` column (a sharing rule's `$null`, a saved - * view's `is_null` rule) must still load as what it is: an unmounted operator - * draws a BLANK trigger (objectui#4768 / #7561), and nothing here rewrites a - * stored spelling (objectui#9306 folds spellings, never predicates). + * view's `is_null` rule), or `equals` on a multi-value field the server + * refuses it on, must still load as what it is so the reader can change it: + * an unmounted operator draws a BLANK trigger (objectui#4768 / #7561), and + * nothing here rewrites a stored spelling (objectui#9306 folds spellings, + * never predicates). */ function offeredOperatorsForRow( - fieldType: string | undefined, + field: FilterFieldStorageFacts | undefined, extraOperators: readonly string[] | undefined, rowOperator: string, ): ReadonlyArray<{ value: string; label: string }> { - const drawable = operatorsForFieldType(fieldType, extraOperators) - if (emptyCheckArm(fieldType) !== "null_only") return drawable const held = normalizeFilterBuilderOperator(rowOperator) + if (jsonColumnFilterOperators(field)) { + const offered = operatorsForField(field, extraOperators) + return defaultOperators.filter( + (op) => op.value === held || offered.some((o) => o.value === op.value), + ) + } + const drawable = operatorsForFieldType(field?.type, extraOperators) + if (emptyCheckArm(field) !== "null_only") return drawable return drawable.filter((op) => !NULLNESS_PAIR.has(op.value) || op.value === held) } @@ -1571,10 +1654,14 @@ function FilterBuilder({ const pairsCurrency = filterGroup.conditions.some((c) => pairedCurrencyField(c, fields, needsValueInput)) const addCondition = () => { + // A new row starts on `equals`, or on the first operator its field offers + // when that field does not take `equals` (a multi-value field, which the + // server refuses it on). + const seeded = reconcileOperatorForField("equals", operatorsForField(fields[0], extraOperators)) const newCondition: FilterBuilderRow = { id: crypto.randomUUID(), field: fields[0]?.value || "", - operator: "equals", + operator: isFilterBuilderOperator(seeded) ? seeded : "equals", value: "", } handleChange({ @@ -1672,13 +1759,13 @@ function FilterBuilder({ const getOperatorsForField = (fieldValue: string) => { const field = fields.find((f) => f.value === fieldValue) - return operatorsForFieldType(field?.type, extraOperators) + return operatorsForField(field, extraOperators) } // What the row's operator dropdown mounts — see `offeredOperatorsForRow`. const getOperatorsForRow = (condition: FilterBuilderRow) => { const field = fields.find((f) => f.value === condition.field) - return offeredOperatorsForRow(field?.type, extraOperators, condition.operator) + return offeredOperatorsForRow(field, extraOperators, condition.operator) } /** @@ -1696,7 +1783,7 @@ function FilterBuilder({ isEmpty: t("filterBuilder.operators.is_empty"), isNull: t("filterBuilder.operators.is_null"), } - const arm = emptyCheckArm(field?.type) + const arm = emptyCheckArm(field) // A stored `is_null` held on a `null_only` column mounts both, and on that // column they match the same records: there is no difference to explain. if (arm === "null_only") return null @@ -2069,8 +2156,9 @@ function FilterBuilder({ ) } - // For select/lookup fields with options (single select) - if (field?.options && (selectLikeTypes.includes(field.type || "") || lookupLikeTypes.includes(field.type || ""))) { + // For select/lookup fields with options (single select), and the one + // member a multi-value option field's `contains` names. + if (field?.options && isOptionDrivenValueControl(field, condition.operator)) { // `displayScalarValue`, never `value || ""` (objectui#4873): an option // whose id is `0` — a status code, a level — is a real selection, and // `0 || ""` handed the trigger the same `""` an unfilled row gives it, so diff --git a/ui/packages/components/src/custom/index.ts b/ui/packages/components/src/custom/index.ts index 5fe198a7ca5..e4046bbac7f 100644 --- a/ui/packages/components/src/custom/index.ts +++ b/ui/packages/components/src/custom/index.ts @@ -18,6 +18,9 @@ export { reconcileOperatorForField, isFilterValueComplete, operatorsForFieldType, + operatorsForField, + jsonColumnFilterOperators, + type FilterFieldStorageFacts, type FilterBuilderRow, type FilterBuilderRowGroup, type FilterBuilderProps, diff --git a/ui/packages/plugin-list/src/ListView.tsx b/ui/packages/plugin-list/src/ListView.tsx index 4f8e4ddf697..20a42734ecc 100644 --- a/ui/packages/plugin-list/src/ListView.tsx +++ b/ui/packages/plugin-list/src/ListView.tsx @@ -5757,7 +5757,7 @@ export const ListView = React.forwardRef(({ * The two narrowings now sit downstream of it, one per builder. */ const candidateFields = React.useMemo(() => { - let fields: Array<{ value: string; label: string; type: string; options?: any; referenceTo?: string; displayField?: string }>; + let fields: Array<{ value: string; label: string; type: string; multiple?: boolean; options?: any; referenceTo?: string; displayField?: string }>; // Translate select-field option labels through the i18n resolver. // fieldDef.options may be an array of { value, label } or a keyed object; @@ -5804,6 +5804,9 @@ export const ListView = React.forwardRef(({ value: key, label: tFieldLabel(key, field.label || key), type: field.type || 'text', + // With the type, whether the field's value is a list: the filter + // offers a multi-value field only the operators the server takes. + multiple: field.multiple === true, options: buildOptions(key, field.options), // ⚠️ objectui#6837 half 2: the READ narrows to `reference` (the only // spelling the protocol declares — `FieldSchema` refuses `reference_to` diff --git a/ui/packages/plugin-list/src/conditions/FilterValuePanel.tsx b/ui/packages/plugin-list/src/conditions/FilterValuePanel.tsx index 3055ac336ad..2611f5bd2aa 100644 --- a/ui/packages/plugin-list/src/conditions/FilterValuePanel.tsx +++ b/ui/packages/plugin-list/src/conditions/FilterValuePanel.tsx @@ -36,9 +36,9 @@ import { getBadgeColorClasses, getBadgeHexAppearance } from '@object-ui/fields'; import { ChevronLeft } from 'lucide-react'; import { DATE_RANGE_PRESET_MACRO_WINDOWS, type DateRangePreset } from '@objectstack/spec/data'; import { - QUICK_FILTER_OPERATORS, isValuelessOperator, quickFilterFamily, + quickFilterOperators, seedValueFor, type ConditionField, } from './conditionModel'; @@ -81,7 +81,9 @@ function useDebounced(callback: (value: string) => void, delay: number) { export function FilterValuePanel({ field, row, onChange, onBack, testId = 'filter-values' }: FilterValuePanelProps) { const { t } = useListConditionTranslation(); const family = quickFilterFamily(field); - const offered = QUICK_FILTER_OPERATORS[family]; + const offered = quickFilterOperators(field); + // A row whose operator the field no longer offers (a saved `equals` on a + // multi-value field) still shows it, so the reader can see and change it. const operators = offered.includes(row.operator) ? offered : [row.operator, ...offered]; const operatorLabel = (op: string) => quickOperatorLabel(op, t); diff --git a/ui/packages/plugin-list/src/conditions/conditionModel.ts b/ui/packages/plugin-list/src/conditions/conditionModel.ts index d1343a9428f..217ea754b44 100644 --- a/ui/packages/plugin-list/src/conditions/conditionModel.ts +++ b/ui/packages/plugin-list/src/conditions/conditionModel.ts @@ -24,6 +24,7 @@ import { FILTER_NUMBER_LIKE_TYPES, FILTER_SELECT_LIKE_TYPES, } from '@object-ui/types'; +import { jsonColumnFilterOperators } from '@object-ui/components'; import type { FilterBuilderRow, FilterBuilderRowGroup, SortItem } from '@object-ui/components'; /** One field the condition controls can name: the shape the list's field lists already carry. */ @@ -31,6 +32,8 @@ export interface ConditionField { value: string; label: string; type?: string; + /** The field's declared `multiple` flag: with the type, whether its value is a list. */ + multiple?: boolean; options?: ReadonlyArray<{ value: string | number | boolean; label: string; color?: string }>; referenceTo?: string; displayField?: string; @@ -72,8 +75,24 @@ export const QUICK_FILTER_OPERATORS: Readonly | undefined, +): readonly FilterBuilderRow['operator'][] { + return jsonColumnFilterOperators(field) ?? QUICK_FILTER_OPERATORS[quickFilterFamily(field)]; +} + export function defaultQuickOperator(field: ConditionField | undefined): FilterBuilderRow['operator'] { - return QUICK_FILTER_OPERATORS[quickFilterFamily(field)][0]; + return quickFilterOperators(field)[0]; } const VALUELESS: ReadonlySet = new Set(['is_empty', 'is_not_empty', 'is_null', 'is_not_null']); From d3956cc49155085ea79c67a70bdd76dc64ce6518 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 21 Nov 2026 03:42:53 +0000 Subject: [PATCH 2/7] test(ui): pin the multi-value filter offer against the server's refusal set; changeset Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01Utp6CZiaBg6rk7dpy1s9Me --- .changeset/multivalue-filter-operators.md | 11 ++ ...ter-builder-empty-null-pair-11810.test.tsx | 19 +- ...ter-builder-json-column-operators.test.tsx | 166 ++++++++++++++++++ .../__tests__/listConditions.test.tsx | 149 ++++++++++++++++ 4 files changed, 340 insertions(+), 5 deletions(-) create mode 100644 .changeset/multivalue-filter-operators.md create mode 100644 ui/packages/components/src/__tests__/filter-builder-json-column-operators.test.tsx diff --git a/.changeset/multivalue-filter-operators.md b/.changeset/multivalue-filter-operators.md new file mode 100644 index 00000000000..fab666b4a8e --- /dev/null +++ b/.changeset/multivalue-filter-operators.md @@ -0,0 +1,11 @@ +--- +'@object-ui/components': patch +'@object-ui/plugin-list': patch +--- + +fix(ui): a multi-select field's list filter offers 「包含 / 不包含」 instead of operators the server refuses + +Clause-②: no +Metadata-protocol: none + +Filtering a list by a multi-value field (`multiselect`, `checkboxes`, `tags`, or a `select` / `lookup` / `user` with `multiple: true`) now offers contains, does not contain, is empty and is not empty, and the query runs, where it used to offer equals and is any of, which the server answers with `400 INVALID_FILTER`. A structured-JSON field (`json`, `address`, …) offers is empty / is not empty. A saved filter that already holds a refused operator still loads and shows it, so it can be changed. `FilterBuilder` fields accept `multiple`, and `jsonColumnFilterOperators` / `operatorsForField` are exported from `@object-ui/components`. diff --git a/ui/packages/components/src/__tests__/filter-builder-empty-null-pair-11810.test.tsx b/ui/packages/components/src/__tests__/filter-builder-empty-null-pair-11810.test.tsx index 09629bb5dd1..4443855f429 100644 --- a/ui/packages/components/src/__tests__/filter-builder-empty-null-pair-11810.test.tsx +++ b/ui/packages/components/src/__tests__/filter-builder-empty-null-pair-11810.test.tsx @@ -96,12 +96,21 @@ describe('objectui#11810 — the dropdown offers one empty-check pair unless the }); } + // A list column takes the JSON-column offer (`jsonColumnFilterOperators`): + // the empty pair, whose expansion counts `[]`, and no null pair to a fresh + // choice. A stored null check still loads, with the empty-list hint. for (const type of ['multiselect', 'tags'] as const) { - it(`a ${type} column offers both pairs and the empty-list hint`, async () => { - renderRow({ field: `f_${type}`, operator: 'equals' }); - const { options, hint } = await openOperatorList(); - expect(options).toEqual(expect.arrayContaining([...EMPTY_PAIR, ...NULL_PAIR])); - expect(hint).toBe(LIST_HINT); + it(`a ${type} column offers the empty pair and no null pair; a stored "Is null" keeps the empty-list hint`, async () => { + renderRow({ field: `f_${type}`, operator: 'contains' }); + const offered = await openOperatorList(); + expect(offered.options).toEqual(expect.arrayContaining(EMPTY_PAIR)); + for (const label of NULL_PAIR) expect(offered.options).not.toContain(label); + expect(offered.hint).toBeNull(); + cleanup(); + renderRow({ field: `f_${type}`, operator: 'is_null' }); + const held = await openOperatorList(); + expect(held.options).toEqual(expect.arrayContaining([...EMPTY_PAIR, 'Is null'])); + expect(held.hint).toBe(LIST_HINT); }); } }); diff --git a/ui/packages/components/src/__tests__/filter-builder-json-column-operators.test.tsx b/ui/packages/components/src/__tests__/filter-builder-json-column-operators.test.tsx new file mode 100644 index 00000000000..4a357ef017e --- /dev/null +++ b/ui/packages/components/src/__tests__/filter-builder-json-column-operators.test.tsx @@ -0,0 +1,166 @@ +/** + * ObjectUI + * Copyright (c) 2024-present ObjectStack Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +/** + * A field stored as a JSON column — a multi-value field (`multiselect` / + * `checkboxes` / `tags`, or a multi-capable type with `multiple: true`) or a + * structured-JSON type — takes only the operators the server answers on it. + * The server refuses the equality, list-membership, ordering and text-match + * operators there with `400 INVALID_FILTER` (`JSON_COLUMN_INCOMPATIBLE_OPERATORS` + * in `@objectstack/core`); membership is `contains` / `not_contains`, and no + * value is the empty pair. + * + * What the dropdown offers is pinned here; the wire shape each offered + * operator lowers to, checked against the server's refusal set itself, is + * pinned beside the list's lowering in `plugin-list`'s conditions harness. + */ +import { describe, it, expect, vi, afterEach } from 'vitest'; +import React from 'react'; +import { cleanup, render, screen, fireEvent, waitFor } from '@testing-library/react'; +import '@testing-library/jest-dom'; +import { + FilterBuilder, + jsonColumnFilterOperators, + operatorsForField, + operatorsForFieldType, + type FilterBuilderRowGroup, +} from '../custom/filter-builder'; + +afterEach(cleanup); + +const OPTIONS = [ + { value: 'quality_lead', label: 'Quality lead' }, + { value: 'safety_officer', label: 'Safety officer' }, +]; +const FIELDS = [ + { value: 'responsibilities', label: 'Responsibilities', type: 'select', multiple: true, options: OPTIONS }, + { value: 'labels', label: 'Labels', type: 'multiselect', options: OPTIONS }, + { value: 'stage', label: 'Stage', type: 'select', options: OPTIONS }, + { value: 'address', label: 'Address', type: 'address' }, + { value: 'name', label: 'Name', type: 'text' }, +]; +const MULTI_OFFER = ['contains', 'not_contains', 'is_empty', 'is_not_empty']; +const MULTI_LABELS = ['Contains', 'Does not contain', 'Is empty', 'Is not empty']; + +function renderRow(condition: Record, fields: typeof FIELDS = FIELDS) { + const onChange = vi.fn(); + const value = { id: 'root', logic: 'and', conditions: [{ id: 'c1', value: '', ...condition }] } as unknown as FilterBuilderRowGroup; + render(); + return { onChange }; +} + +async function openOperatorList(): Promise { + fireEvent.keyDown(screen.getAllByRole('combobox')[1], { key: 'ArrowDown' }); + return waitFor(() => { + const found = screen.getAllByRole('option'); + expect(found.length).toBeGreaterThan(0); + return found.map((o) => o.textContent ?? ''); + }); +} + +describe('jsonColumnFilterOperators — the one helper every filter surface reads', () => { + it('a multi-value field, by type or by `multiple: true`, takes contains / not contains / empty pair', () => { + for (const field of [ + { type: 'multiselect' }, + { type: 'checkboxes' }, + { type: 'tags' }, + { type: 'select', multiple: true }, + { type: 'radio', multiple: true }, + { type: 'lookup', multiple: true }, + { type: 'user', multiple: true }, + ]) { + expect(jsonColumnFilterOperators(field), JSON.stringify(field)).toEqual(MULTI_OFFER); + expect(operatorsForField(field).map((op) => op.value)).toEqual(MULTI_OFFER); + } + }); + + it('a structured-JSON field takes the empty pair only', () => { + for (const type of ['json', 'address', 'location', 'repeater']) { + expect(jsonColumnFilterOperators({ type }), type).toEqual(['is_empty', 'is_not_empty']); + } + }); + + it('every other field keeps its type bucket (CONTROL: single select, lookup, text)', () => { + for (const field of [{ type: 'select' }, { type: 'select', multiple: false }, { type: 'lookup' }, { type: 'text' }, undefined]) { + expect(jsonColumnFilterOperators(field)).toBeUndefined(); + expect(operatorsForField(field).map((op) => op.value)).toEqual( + operatorsForFieldType(field?.type).map((op) => op.value), + ); + } + expect(operatorsForField({ type: 'select' }).map((op) => op.value)).toEqual( + expect.arrayContaining(['equals', 'not_equals', 'in', 'not_in']), + ); + }); + + it('what a row can HOLD is still the type bucket, so a stored refused operator stays editable', () => { + expect(operatorsForFieldType('multiselect').map((op) => op.value)).toContain('equals'); + }); +}); + +describe('FilterBuilder — a multi-value row offers only what the server accepts', () => { + it('a `select` with `multiple: true` offers 包含 / 不包含 / 为空 / 不为空 and none of the refused set', async () => { + renderRow({ field: 'responsibilities', operator: 'contains' }); + expect(await openOperatorList()).toEqual(MULTI_LABELS); + }); + + it('a `multiselect` offers the same four', async () => { + renderRow({ field: 'labels', operator: 'contains' }); + expect(await openOperatorList()).toEqual(MULTI_LABELS); + }); + + it('a structured-JSON field offers the empty pair only', async () => { + renderRow({ field: 'address', operator: 'is_empty' }); + expect(await openOperatorList()).toEqual(['Is empty', 'Is not empty']); + }); + + it('a single-value select keeps equals / in (CONTROL)', async () => { + renderRow({ field: 'stage', operator: 'equals' }); + expect(await openOperatorList()).toEqual( + expect.arrayContaining(['Equals', 'Not equals', 'In', 'Not in', 'Is empty', 'Is not empty']), + ); + }); + + it('a stored `equals` on a multi-value field still loads and shows, beside the four', async () => { + renderRow({ field: 'responsibilities', operator: 'equals', value: 'quality_lead' }); + expect(screen.getAllByRole('combobox')[1].textContent).toBe('Equals'); + expect(await openOperatorList()).toEqual(['Equals', ...MULTI_LABELS]); + }); + + it('contains draws a single-option picker of the field’s options', () => { + renderRow({ field: 'labels', operator: 'contains', value: 'quality_lead' }); + // combobox 2 is the value Select (field, operator, value) + expect(screen.getAllByRole('combobox')[2].textContent).toBe('Quality lead'); + expect(screen.queryAllByRole('checkbox')).toHaveLength(0); + }); + + it('switching a row on `equals` to a multi-value field lands on contains', async () => { + const { onChange } = renderRow({ field: 'stage', operator: 'equals', value: 'quality_lead' }); + fireEvent.keyDown(screen.getAllByRole('combobox')[0], { key: 'ArrowDown' }); + const option = await waitFor(() => { + const found = screen.getAllByRole('option').find((o) => o.textContent === 'Responsibilities'); + expect(found).toBeTruthy(); + return found!; + }); + fireEvent.click(option); + const row = onChange.mock.calls[onChange.mock.calls.length - 1][0].conditions[0]; + expect(row).toMatchObject({ field: 'responsibilities', operator: 'contains', value: 'quality_lead' }); + }); + + it('“Add filter” on a multi-value first field seeds contains, not equals', () => { + const onChange = vi.fn(); + render( + , + ); + fireEvent.click(screen.getByRole('button', { name: /add filter/i })); + expect(onChange.mock.calls.at(-1)[0].conditions[0]).toMatchObject({ field: 'responsibilities', operator: 'contains' }); + }); +}); diff --git a/ui/packages/plugin-list/src/conditions/__tests__/listConditions.test.tsx b/ui/packages/plugin-list/src/conditions/__tests__/listConditions.test.tsx index 6b7fdb50739..c4a22862a0f 100644 --- a/ui/packages/plugin-list/src/conditions/__tests__/listConditions.test.tsx +++ b/ui/packages/plugin-list/src/conditions/__tests__/listConditions.test.tsx @@ -24,12 +24,25 @@ import { ConditionChipRow, FilterPanel, SortPanel, describeConditionValue, sortD import { addSortLevel, chipsAreIndependent, + defaultQuickOperator, moveSortItem, quickFilterFamily, + quickFilterOperators, readViewConditions, type ConditionField, } from '../conditionModel'; import { LIST_CONDITION_DEFAULT_TRANSLATIONS } from '../conditionTranslations'; +import { operatorsForField } from '@object-ui/components'; +import { en as enPack, zh as zhPack } from '@object-ui/i18n/locales'; +import { parseFilterAST } from '@objectstack/spec/data'; +import { convertFilterGroupToAST } from '../../ListView'; + +// The server's JSON-column refusal set, read from the module the server's +// faces import it from. That module imports nothing, so it loads on its own. +const REFUSAL_MODULE = new URL('../../../../../../packages/core/src/utils/json-column-operator-refusal.ts', import.meta.url); +const { JSON_COLUMN_INCOMPATIBLE_OPERATORS } = (await import(REFUSAL_MODULE.href)) as { + JSON_COLUMN_INCOMPATIBLE_OPERATORS: ReadonlySet; +}; const STAGE: ConditionField = { value: 'stage', @@ -661,3 +674,139 @@ describe('condition model', () => { expect(describeConditionValue(STAGE, 'is_empty', undefined, t as never)).toBe('is empty'); }); }); + +describe('multi-value fields — the quick filter and the advanced panel offer only what the server accepts', () => { + const OPTIONS = [ + { value: 'quality_lead', label: 'Quality lead' }, + { value: 'safety_officer', label: 'Safety officer' }, + ]; + const MULTI_VALUE: ConditionField[] = [ + { value: 'responsibilities', label: 'Responsibilities', type: 'select', multiple: true, options: OPTIONS }, + { value: 'labels', label: 'Labels', type: 'multiselect', options: OPTIONS }, + { value: 'channels', label: 'Channels', type: 'checkboxes', options: OPTIONS }, + { value: 'tags', label: 'Tags', type: 'tags' }, + { value: 'team', label: 'Team', type: 'user', multiple: true }, + { value: 'accounts', label: 'Accounts', type: 'lookup', multiple: true, referenceTo: 'account' }, + ]; + const STRUCTURED: ConditionField = { value: 'address', label: 'Address', type: 'address' }; + const MULTI_OFFER = ['contains', 'not_contains', 'is_empty', 'is_not_empty']; + + /** The `$`-operators the server sees for one builder row, through the list's own lowering and the spec's parse. */ + function wireOperators(field: string, operator: string, value: unknown): string[] { + const ast = convertFilterGroupToAST({ + id: 'root', + logic: 'and', + conditions: [{ id: 'r', field, operator: operator as never, value: value as never }], + }); + const parsed = parseFilterAST(ast) as Record | undefined; + const ops: string[] = []; + const walk = (node: unknown) => { + if (!node || typeof node !== 'object') return; + for (const [key, sub] of Object.entries(node as Record)) { + if (key === '$and' || key === '$or') { + (sub as unknown[]).forEach(walk); + } else if (sub !== null && typeof sub === 'object' && !Array.isArray(sub)) { + ops.push(...Object.keys(sub as object)); + } else { + ops.push('$eq'); // the bare `{ field: value }` spelling is implicit equality + } + } + }; + walk(parsed); + return ops; + } + const sample = (op: string) => (op === 'in' || op === 'not_in' ? ['quality_lead'] : 'quality_lead'); + + it('offers contains / not contains / is empty / is not empty on every multi-value field, contains first', () => { + for (const field of MULTI_VALUE) { + expect(quickFilterOperators(field), field.type).toEqual(MULTI_OFFER); + expect(defaultQuickOperator(field)).toBe('contains'); + expect(operatorsForField(field).map((op) => op.value), field.type).toEqual(MULTI_OFFER); + } + }); + + it('offers a structured-JSON field the empty pair only: it has no members to name', () => { + expect(quickFilterOperators(STRUCTURED)).toEqual(['is_empty', 'is_not_empty']); + expect(operatorsForField(STRUCTURED).map((op) => op.value)).toEqual(['is_empty', 'is_not_empty']); + }); + + it('no offered operator reaches the server as one its JSON-column refusal names', () => { + for (const field of [...MULTI_VALUE, STRUCTURED]) { + const offered = new Set([...quickFilterOperators(field), ...operatorsForField(field).map((op) => op.value)]); + for (const op of offered) { + const refused = wireOperators(field.value, op, sample(op)).filter((w) => JSON_COLUMN_INCOMPATIBLE_OPERATORS.has(w)); + expect(refused, `${field.type} ${op}`).toEqual([]); + } + } + }); + + it('every operator offered before (equals / not equals / in / not in) is one the server refuses — the control leg', () => { + for (const op of ['equals', 'not_equals', 'in', 'not_in']) { + const refused = wireOperators('responsibilities', op, sample(op)).filter((w) => JSON_COLUMN_INCOMPATIBLE_OPERATORS.has(w)); + expect(refused.length, op).toBeGreaterThan(0); + } + }); + + it('「包含」 sends one member under $contains, the shape the refusal prescribes', () => { + expect( + convertFilterGroupToAST({ + id: 'root', + logic: 'and', + conditions: [{ id: 'r', field: 'responsibilities', operator: 'contains', value: 'quality_lead' }], + }), + ).toEqual(['responsibilities', 'contains', 'quality_lead']); + expect(wireOperators('responsibilities', 'contains', 'quality_lead')).toEqual(['$contains']); + expect(wireOperators('responsibilities', 'not_contains', 'quality_lead')).toEqual(['$notContains']); + }); + + it('a single-value select keeps its operators (CONTROL)', () => { + expect(quickFilterOperators(STAGE)).toEqual(['in', 'not_in', 'is_empty', 'is_not_empty']); + expect(operatorsForField(STAGE).map((op) => op.value)).toContain('equals'); + expect(operatorsForField(STAGE).map((op) => op.value)).toContain('in'); + expect(operatorsForField({ type: 'select', multiple: false }).map((op) => op.value)).toContain('equals'); + }); + + it('contains on an option field picks ONE option; picking another replaces it', () => { + const rows: Array<{ operator: string; value: unknown }> = []; + function Host() { + const [row, setRow] = React.useState({ id: 'r', field: 'responsibilities', operator: 'contains' as const, value: '' as unknown }); + return ( + { + rows.push(next); + setRow(next as never); + }} + /> + ); + } + render(); + expect(screen.getByRole('listbox').getAttribute('aria-multiselectable')).toBeNull(); + fireEvent.click(within(screen.getByTestId('filter-values-option-quality_lead')).getByRole('checkbox')); + fireEvent.click(within(screen.getByTestId('filter-values-option-safety_officer')).getByRole('checkbox')); + expect(rows.map((r) => r.value)).toEqual(['quality_lead', 'safety_officer']); + }); + + it('a saved view holding a refused operator still draws it, so the reader can change it', () => { + render( + {}} + />, + ); + expect(screen.getByTestId('filter-values-operator').textContent).toBe('equals'); + }); + + it('reads 包含 / 不包含 / 为空 / 不为空 in zh-CN and contains / does not contain in en, on both surfaces', () => { + const zhQuick = zhPack.listConditions.operators as Record; + const zhAdvanced = zhPack.filterBuilder.operators as Record; + expect(MULTI_OFFER.map((op) => zhQuick[op])).toEqual(['包含', '不包含', '为空', '不为空']); + expect(MULTI_OFFER.map((op) => zhAdvanced[op])).toEqual(['包含', '不包含', '为空', '不为空']); + const enQuick = enPack.listConditions.operators as Record; + expect(MULTI_OFFER.map((op) => enQuick[op])).toEqual(['contains', 'does not contain', 'is empty', 'is not empty']); + const t = (key: string) => LIST_CONDITION_DEFAULT_TRANSLATIONS[key] ?? key; + expect(describeConditionValue(MULTI_VALUE[0], 'contains', 'quality_lead', t as never)).toBe('contains Quality lead'); + }); +}); From 799e472515181513cc7d91a71372a93c872a6c48 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 21 Nov 2026 03:43:58 +0000 Subject: [PATCH 3/7] test(ui): place the multi-value pins mid-file, clear of the toolbar redo's hunks Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01Utp6CZiaBg6rk7dpy1s9Me --- .../__tests__/listConditions.test.tsx | 276 +++++++++--------- 1 file changed, 138 insertions(+), 138 deletions(-) diff --git a/ui/packages/plugin-list/src/conditions/__tests__/listConditions.test.tsx b/ui/packages/plugin-list/src/conditions/__tests__/listConditions.test.tsx index c4a22862a0f..1ed68fcd372 100644 --- a/ui/packages/plugin-list/src/conditions/__tests__/listConditions.test.tsx +++ b/ui/packages/plugin-list/src/conditions/__tests__/listConditions.test.tsx @@ -24,14 +24,14 @@ import { ConditionChipRow, FilterPanel, SortPanel, describeConditionValue, sortD import { addSortLevel, chipsAreIndependent, - defaultQuickOperator, moveSortItem, quickFilterFamily, - quickFilterOperators, readViewConditions, type ConditionField, } from '../conditionModel'; import { LIST_CONDITION_DEFAULT_TRANSLATIONS } from '../conditionTranslations'; + +import { defaultQuickOperator, quickFilterOperators } from '../conditionModel'; import { operatorsForField } from '@object-ui/components'; import { en as enPack, zh as zhPack } from '@object-ui/i18n/locales'; import { parseFilterAST } from '@objectstack/spec/data'; @@ -403,6 +403,142 @@ describe('FilterValuePanel', () => { }); }); +describe('multi-value fields — the quick filter and the advanced panel offer only what the server accepts', () => { + const OPTIONS = [ + { value: 'quality_lead', label: 'Quality lead' }, + { value: 'safety_officer', label: 'Safety officer' }, + ]; + const MULTI_VALUE: ConditionField[] = [ + { value: 'responsibilities', label: 'Responsibilities', type: 'select', multiple: true, options: OPTIONS }, + { value: 'labels', label: 'Labels', type: 'multiselect', options: OPTIONS }, + { value: 'channels', label: 'Channels', type: 'checkboxes', options: OPTIONS }, + { value: 'tags', label: 'Tags', type: 'tags' }, + { value: 'team', label: 'Team', type: 'user', multiple: true }, + { value: 'accounts', label: 'Accounts', type: 'lookup', multiple: true, referenceTo: 'account' }, + ]; + const STRUCTURED: ConditionField = { value: 'address', label: 'Address', type: 'address' }; + const MULTI_OFFER = ['contains', 'not_contains', 'is_empty', 'is_not_empty']; + + /** The `$`-operators the server sees for one builder row, through the list's own lowering and the spec's parse. */ + function wireOperators(field: string, operator: string, value: unknown): string[] { + const ast = convertFilterGroupToAST({ + id: 'root', + logic: 'and', + conditions: [{ id: 'r', field, operator: operator as never, value: value as never }], + }); + const parsed = parseFilterAST(ast) as Record | undefined; + const ops: string[] = []; + const walk = (node: unknown) => { + if (!node || typeof node !== 'object') return; + for (const [key, sub] of Object.entries(node as Record)) { + if (key === '$and' || key === '$or') { + (sub as unknown[]).forEach(walk); + } else if (sub !== null && typeof sub === 'object' && !Array.isArray(sub)) { + ops.push(...Object.keys(sub as object)); + } else { + ops.push('$eq'); // the bare `{ field: value }` spelling is implicit equality + } + } + }; + walk(parsed); + return ops; + } + const sample = (op: string) => (op === 'in' || op === 'not_in' ? ['quality_lead'] : 'quality_lead'); + + it('offers contains / not contains / is empty / is not empty on every multi-value field, contains first', () => { + for (const field of MULTI_VALUE) { + expect(quickFilterOperators(field), field.type).toEqual(MULTI_OFFER); + expect(defaultQuickOperator(field)).toBe('contains'); + expect(operatorsForField(field).map((op) => op.value), field.type).toEqual(MULTI_OFFER); + } + }); + + it('offers a structured-JSON field the empty pair only: it has no members to name', () => { + expect(quickFilterOperators(STRUCTURED)).toEqual(['is_empty', 'is_not_empty']); + expect(operatorsForField(STRUCTURED).map((op) => op.value)).toEqual(['is_empty', 'is_not_empty']); + }); + + it('no offered operator reaches the server as one its JSON-column refusal names', () => { + for (const field of [...MULTI_VALUE, STRUCTURED]) { + const offered = new Set([...quickFilterOperators(field), ...operatorsForField(field).map((op) => op.value)]); + for (const op of offered) { + const refused = wireOperators(field.value, op, sample(op)).filter((w) => JSON_COLUMN_INCOMPATIBLE_OPERATORS.has(w)); + expect(refused, `${field.type} ${op}`).toEqual([]); + } + } + }); + + it('every operator offered before (equals / not equals / in / not in) is one the server refuses — the control leg', () => { + for (const op of ['equals', 'not_equals', 'in', 'not_in']) { + const refused = wireOperators('responsibilities', op, sample(op)).filter((w) => JSON_COLUMN_INCOMPATIBLE_OPERATORS.has(w)); + expect(refused.length, op).toBeGreaterThan(0); + } + }); + + it('「包含」 sends one member under $contains, the shape the refusal prescribes', () => { + expect( + convertFilterGroupToAST({ + id: 'root', + logic: 'and', + conditions: [{ id: 'r', field: 'responsibilities', operator: 'contains', value: 'quality_lead' }], + }), + ).toEqual(['responsibilities', 'contains', 'quality_lead']); + expect(wireOperators('responsibilities', 'contains', 'quality_lead')).toEqual(['$contains']); + expect(wireOperators('responsibilities', 'not_contains', 'quality_lead')).toEqual(['$notContains']); + }); + + it('a single-value select keeps its operators (CONTROL)', () => { + expect(quickFilterOperators(STAGE)).toEqual(['in', 'not_in', 'is_empty', 'is_not_empty']); + expect(operatorsForField(STAGE).map((op) => op.value)).toContain('equals'); + expect(operatorsForField(STAGE).map((op) => op.value)).toContain('in'); + expect(operatorsForField({ type: 'select', multiple: false }).map((op) => op.value)).toContain('equals'); + }); + + it('contains on an option field picks ONE option; picking another replaces it', () => { + const rows: Array<{ operator: string; value: unknown }> = []; + function Host() { + const [row, setRow] = React.useState({ id: 'r', field: 'responsibilities', operator: 'contains' as const, value: '' as unknown }); + return ( + { + rows.push(next); + setRow(next as never); + }} + /> + ); + } + render(); + expect(screen.getByRole('listbox').getAttribute('aria-multiselectable')).toBeNull(); + fireEvent.click(within(screen.getByTestId('filter-values-option-quality_lead')).getByRole('checkbox')); + fireEvent.click(within(screen.getByTestId('filter-values-option-safety_officer')).getByRole('checkbox')); + expect(rows.map((r) => r.value)).toEqual(['quality_lead', 'safety_officer']); + }); + + it('a saved view holding a refused operator still draws it, so the reader can change it', () => { + render( + {}} + />, + ); + expect(screen.getByTestId('filter-values-operator').textContent).toBe('equals'); + }); + + it('reads 包含 / 不包含 / 为空 / 不为空 in zh-CN and contains / does not contain in en, on both surfaces', () => { + const zhQuick = zhPack.listConditions.operators as Record; + const zhAdvanced = zhPack.filterBuilder.operators as Record; + expect(MULTI_OFFER.map((op) => zhQuick[op])).toEqual(['包含', '不包含', '为空', '不为空']); + expect(MULTI_OFFER.map((op) => zhAdvanced[op])).toEqual(['包含', '不包含', '为空', '不为空']); + const enQuick = enPack.listConditions.operators as Record; + expect(MULTI_OFFER.map((op) => enQuick[op])).toEqual(['contains', 'does not contain', 'is empty', 'is not empty']); + const t = (key: string) => LIST_CONDITION_DEFAULT_TRANSLATIONS[key] ?? key; + expect(describeConditionValue(MULTI_VALUE[0], 'contains', 'quality_lead', t as never)).toBe('contains Quality lead'); + }); +}); + describe('SortPanel — the same field list with the direction on top', () => { it('sorts by amount descending in two clicks after the trigger (three in all)', () => { const onChange = vi.fn(); @@ -674,139 +810,3 @@ describe('condition model', () => { expect(describeConditionValue(STAGE, 'is_empty', undefined, t as never)).toBe('is empty'); }); }); - -describe('multi-value fields — the quick filter and the advanced panel offer only what the server accepts', () => { - const OPTIONS = [ - { value: 'quality_lead', label: 'Quality lead' }, - { value: 'safety_officer', label: 'Safety officer' }, - ]; - const MULTI_VALUE: ConditionField[] = [ - { value: 'responsibilities', label: 'Responsibilities', type: 'select', multiple: true, options: OPTIONS }, - { value: 'labels', label: 'Labels', type: 'multiselect', options: OPTIONS }, - { value: 'channels', label: 'Channels', type: 'checkboxes', options: OPTIONS }, - { value: 'tags', label: 'Tags', type: 'tags' }, - { value: 'team', label: 'Team', type: 'user', multiple: true }, - { value: 'accounts', label: 'Accounts', type: 'lookup', multiple: true, referenceTo: 'account' }, - ]; - const STRUCTURED: ConditionField = { value: 'address', label: 'Address', type: 'address' }; - const MULTI_OFFER = ['contains', 'not_contains', 'is_empty', 'is_not_empty']; - - /** The `$`-operators the server sees for one builder row, through the list's own lowering and the spec's parse. */ - function wireOperators(field: string, operator: string, value: unknown): string[] { - const ast = convertFilterGroupToAST({ - id: 'root', - logic: 'and', - conditions: [{ id: 'r', field, operator: operator as never, value: value as never }], - }); - const parsed = parseFilterAST(ast) as Record | undefined; - const ops: string[] = []; - const walk = (node: unknown) => { - if (!node || typeof node !== 'object') return; - for (const [key, sub] of Object.entries(node as Record)) { - if (key === '$and' || key === '$or') { - (sub as unknown[]).forEach(walk); - } else if (sub !== null && typeof sub === 'object' && !Array.isArray(sub)) { - ops.push(...Object.keys(sub as object)); - } else { - ops.push('$eq'); // the bare `{ field: value }` spelling is implicit equality - } - } - }; - walk(parsed); - return ops; - } - const sample = (op: string) => (op === 'in' || op === 'not_in' ? ['quality_lead'] : 'quality_lead'); - - it('offers contains / not contains / is empty / is not empty on every multi-value field, contains first', () => { - for (const field of MULTI_VALUE) { - expect(quickFilterOperators(field), field.type).toEqual(MULTI_OFFER); - expect(defaultQuickOperator(field)).toBe('contains'); - expect(operatorsForField(field).map((op) => op.value), field.type).toEqual(MULTI_OFFER); - } - }); - - it('offers a structured-JSON field the empty pair only: it has no members to name', () => { - expect(quickFilterOperators(STRUCTURED)).toEqual(['is_empty', 'is_not_empty']); - expect(operatorsForField(STRUCTURED).map((op) => op.value)).toEqual(['is_empty', 'is_not_empty']); - }); - - it('no offered operator reaches the server as one its JSON-column refusal names', () => { - for (const field of [...MULTI_VALUE, STRUCTURED]) { - const offered = new Set([...quickFilterOperators(field), ...operatorsForField(field).map((op) => op.value)]); - for (const op of offered) { - const refused = wireOperators(field.value, op, sample(op)).filter((w) => JSON_COLUMN_INCOMPATIBLE_OPERATORS.has(w)); - expect(refused, `${field.type} ${op}`).toEqual([]); - } - } - }); - - it('every operator offered before (equals / not equals / in / not in) is one the server refuses — the control leg', () => { - for (const op of ['equals', 'not_equals', 'in', 'not_in']) { - const refused = wireOperators('responsibilities', op, sample(op)).filter((w) => JSON_COLUMN_INCOMPATIBLE_OPERATORS.has(w)); - expect(refused.length, op).toBeGreaterThan(0); - } - }); - - it('「包含」 sends one member under $contains, the shape the refusal prescribes', () => { - expect( - convertFilterGroupToAST({ - id: 'root', - logic: 'and', - conditions: [{ id: 'r', field: 'responsibilities', operator: 'contains', value: 'quality_lead' }], - }), - ).toEqual(['responsibilities', 'contains', 'quality_lead']); - expect(wireOperators('responsibilities', 'contains', 'quality_lead')).toEqual(['$contains']); - expect(wireOperators('responsibilities', 'not_contains', 'quality_lead')).toEqual(['$notContains']); - }); - - it('a single-value select keeps its operators (CONTROL)', () => { - expect(quickFilterOperators(STAGE)).toEqual(['in', 'not_in', 'is_empty', 'is_not_empty']); - expect(operatorsForField(STAGE).map((op) => op.value)).toContain('equals'); - expect(operatorsForField(STAGE).map((op) => op.value)).toContain('in'); - expect(operatorsForField({ type: 'select', multiple: false }).map((op) => op.value)).toContain('equals'); - }); - - it('contains on an option field picks ONE option; picking another replaces it', () => { - const rows: Array<{ operator: string; value: unknown }> = []; - function Host() { - const [row, setRow] = React.useState({ id: 'r', field: 'responsibilities', operator: 'contains' as const, value: '' as unknown }); - return ( - { - rows.push(next); - setRow(next as never); - }} - /> - ); - } - render(); - expect(screen.getByRole('listbox').getAttribute('aria-multiselectable')).toBeNull(); - fireEvent.click(within(screen.getByTestId('filter-values-option-quality_lead')).getByRole('checkbox')); - fireEvent.click(within(screen.getByTestId('filter-values-option-safety_officer')).getByRole('checkbox')); - expect(rows.map((r) => r.value)).toEqual(['quality_lead', 'safety_officer']); - }); - - it('a saved view holding a refused operator still draws it, so the reader can change it', () => { - render( - {}} - />, - ); - expect(screen.getByTestId('filter-values-operator').textContent).toBe('equals'); - }); - - it('reads 包含 / 不包含 / 为空 / 不为空 in zh-CN and contains / does not contain in en, on both surfaces', () => { - const zhQuick = zhPack.listConditions.operators as Record; - const zhAdvanced = zhPack.filterBuilder.operators as Record; - expect(MULTI_OFFER.map((op) => zhQuick[op])).toEqual(['包含', '不包含', '为空', '不为空']); - expect(MULTI_OFFER.map((op) => zhAdvanced[op])).toEqual(['包含', '不包含', '为空', '不为空']); - const enQuick = enPack.listConditions.operators as Record; - expect(MULTI_OFFER.map((op) => enQuick[op])).toEqual(['contains', 'does not contain', 'is empty', 'is not empty']); - const t = (key: string) => LIST_CONDITION_DEFAULT_TRANSLATIONS[key] ?? key; - expect(describeConditionValue(MULTI_VALUE[0], 'contains', 'quality_lead', t as never)).toBe('contains Quality lead'); - }); -}); From 40ef4027e0d73ac56c52064f092b537055d47585 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 21 Nov 2026 03:46:33 +0000 Subject: [PATCH 4/7] test(ui): read the refusal set from its source text; pin the offered order Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01Utp6CZiaBg6rk7dpy1s9Me --- ...ter-builder-json-column-operators.test.tsx | 2 +- .../__tests__/listConditions.test.tsx | 26 ++++++++++++++----- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/ui/packages/components/src/__tests__/filter-builder-json-column-operators.test.tsx b/ui/packages/components/src/__tests__/filter-builder-json-column-operators.test.tsx index 4a357ef017e..a2fe1cb4d4d 100644 --- a/ui/packages/components/src/__tests__/filter-builder-json-column-operators.test.tsx +++ b/ui/packages/components/src/__tests__/filter-builder-json-column-operators.test.tsx @@ -121,7 +121,7 @@ describe('FilterBuilder — a multi-value row offers only what the server accept it('a single-value select keeps equals / in (CONTROL)', async () => { renderRow({ field: 'stage', operator: 'equals' }); expect(await openOperatorList()).toEqual( - expect.arrayContaining(['Equals', 'Not equals', 'In', 'Not in', 'Is empty', 'Is not empty']), + ['Equals', 'Does not equal', 'Is empty', 'Is not empty', 'In', 'Not in'], ); }); diff --git a/ui/packages/plugin-list/src/conditions/__tests__/listConditions.test.tsx b/ui/packages/plugin-list/src/conditions/__tests__/listConditions.test.tsx index 1ed68fcd372..b6a9143dcac 100644 --- a/ui/packages/plugin-list/src/conditions/__tests__/listConditions.test.tsx +++ b/ui/packages/plugin-list/src/conditions/__tests__/listConditions.test.tsx @@ -32,17 +32,26 @@ import { import { LIST_CONDITION_DEFAULT_TRANSLATIONS } from '../conditionTranslations'; import { defaultQuickOperator, quickFilterOperators } from '../conditionModel'; +import { readFileSync } from 'node:fs'; +import { dirname, resolve } from 'node:path'; +import { fileURLToPath } from 'node:url'; import { operatorsForField } from '@object-ui/components'; import { en as enPack, zh as zhPack } from '@object-ui/i18n/locales'; import { parseFilterAST } from '@objectstack/spec/data'; import { convertFilterGroupToAST } from '../../ListView'; -// The server's JSON-column refusal set, read from the module the server's -// faces import it from. That module imports nothing, so it loads on its own. -const REFUSAL_MODULE = new URL('../../../../../../packages/core/src/utils/json-column-operator-refusal.ts', import.meta.url); -const { JSON_COLUMN_INCOMPATIBLE_OPERATORS } = (await import(REFUSAL_MODULE.href)) as { - JSON_COLUMN_INCOMPATIBLE_OPERATORS: ReadonlySet; -}; +// The server's JSON-column refusal set, read from the module every server face +// imports it from (`@objectstack/core`, which no UI package depends on): the +// string members of its `JSON_COLUMN_INCOMPATIBLE_OPERATORS` literal. +const HERE = dirname(fileURLToPath(import.meta.url)); +const REFUSAL_SOURCE = readFileSync( + resolve(HERE, '../../../../../../packages/core/src/utils/json-column-operator-refusal.ts'), + 'utf8', +); +const REFUSAL_LITERAL = /JSON_COLUMN_INCOMPATIBLE_OPERATORS[^=]*=\s*new Set\(\[([^\]]*)\]/.exec(REFUSAL_SOURCE)?.[1] ?? ''; +const JSON_COLUMN_INCOMPATIBLE_OPERATORS: ReadonlySet = new Set( + [...REFUSAL_LITERAL.matchAll(/'([^']+)'/g)].map((m) => m[1]), +); const STAGE: ConditionField = { value: 'stage', @@ -445,6 +454,11 @@ describe('multi-value fields — the quick filter and the advanced panel offer o } const sample = (op: string) => (op === 'in' || op === 'not_in' ? ['quality_lead'] : 'quality_lead'); + it('reads the refusal set it checks against (lit control: equals and in are in it, contains and the empty test are not)', () => { + for (const op of ['$eq', '$ne', '$in', '$nin', '$startsWith']) expect(JSON_COLUMN_INCOMPATIBLE_OPERATORS.has(op), op).toBe(true); + for (const op of ['$contains', '$notContains', '$empty', '$null']) expect(JSON_COLUMN_INCOMPATIBLE_OPERATORS.has(op), op).toBe(false); + }); + it('offers contains / not contains / is empty / is not empty on every multi-value field, contains first', () => { for (const field of MULTI_VALUE) { expect(quickFilterOperators(field), field.type).toEqual(MULTI_OFFER); From 0153d1fe7f845bfdc2d5363cc001f760a822e481 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 21 Nov 2026 04:08:44 +0000 Subject: [PATCH 5/7] test(ui): type the multi-value pins' hosts Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01Utp6CZiaBg6rk7dpy1s9Me --- .../filter-builder-json-column-operators.test.tsx | 3 ++- .../src/conditions/__tests__/listConditions.test.tsx | 9 +++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/ui/packages/components/src/__tests__/filter-builder-json-column-operators.test.tsx b/ui/packages/components/src/__tests__/filter-builder-json-column-operators.test.tsx index a2fe1cb4d4d..5decdfb7d55 100644 --- a/ui/packages/components/src/__tests__/filter-builder-json-column-operators.test.tsx +++ b/ui/packages/components/src/__tests__/filter-builder-json-column-operators.test.tsx @@ -161,6 +161,7 @@ describe('FilterBuilder — a multi-value row offers only what the server accept />, ); fireEvent.click(screen.getByRole('button', { name: /add filter/i })); - expect(onChange.mock.calls.at(-1)[0].conditions[0]).toMatchObject({ field: 'responsibilities', operator: 'contains' }); + const group = onChange.mock.calls[onChange.mock.calls.length - 1][0] as FilterBuilderRowGroup; + expect(group.conditions[0]).toMatchObject({ field: 'responsibilities', operator: 'contains' }); }); }); diff --git a/ui/packages/plugin-list/src/conditions/__tests__/listConditions.test.tsx b/ui/packages/plugin-list/src/conditions/__tests__/listConditions.test.tsx index b6a9143dcac..0000ddb8275 100644 --- a/ui/packages/plugin-list/src/conditions/__tests__/listConditions.test.tsx +++ b/ui/packages/plugin-list/src/conditions/__tests__/listConditions.test.tsx @@ -32,6 +32,7 @@ import { import { LIST_CONDITION_DEFAULT_TRANSLATIONS } from '../conditionTranslations'; import { defaultQuickOperator, quickFilterOperators } from '../conditionModel'; +import type { FilterBuilderRow } from '@object-ui/components'; import { readFileSync } from 'node:fs'; import { dirname, resolve } from 'node:path'; import { fileURLToPath } from 'node:url'; @@ -509,16 +510,16 @@ describe('multi-value fields — the quick filter and the advanced panel offer o }); it('contains on an option field picks ONE option; picking another replaces it', () => { - const rows: Array<{ operator: string; value: unknown }> = []; + const rows: FilterBuilderRow[] = []; function Host() { - const [row, setRow] = React.useState({ id: 'r', field: 'responsibilities', operator: 'contains' as const, value: '' as unknown }); + const [row, setRow] = React.useState({ id: 'r', field: 'responsibilities', operator: 'contains', value: '' }); return ( { rows.push(next); - setRow(next as never); + setRow(next); }} /> ); From 6ddf4b101a008aadb8c7c8400165698de2a2aafa Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 21 Nov 2026 05:12:39 +0000 Subject: [PATCH 6/7] docs(components): cite the card owning the predicate-vs-driver divergence in the filter builder The builder now relates the spec's multi-value predicate to the driver's JSON-column refusal, so it names the card that owns their divergence, as the plugin-detail pin requires of every such file. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01Utp6CZiaBg6rk7dpy1s9Me --- ui/packages/components/src/custom/filter-builder.tsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ui/packages/components/src/custom/filter-builder.tsx b/ui/packages/components/src/custom/filter-builder.tsx index f440145ffec..3c59a4ef7f6 100644 --- a/ui/packages/components/src/custom/filter-builder.tsx +++ b/ui/packages/components/src/custom/filter-builder.tsx @@ -1444,6 +1444,9 @@ function emptyCheckArm(field: FilterFieldStorageFacts | undefined) { * Decided from the same two field facts the server's faces read (the * engine's `declaredJsonStoredFields`: `STRUCTURED_JSON_TYPES` or * `isMultiValueField`), through the spec's own sets — never a local type list. + * The driver's own JSON-column test and the spec predicate are related here, + * so the card that owns their divergence is cited: objectstack#17469 + * (`multiple: true` on a type that cannot hold several values). * Shared by every filter surface that offers operators per field, so the * list's quick filter and this builder cannot disagree. */ From a9ef27ad8b1fd574d6aa6a5836dbac91f32592a0 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 21 Nov 2026 05:14:21 +0000 Subject: [PATCH 7/7] test(fields): the equality CONTROL runs on single-value columns; a multiselect row seeds contains The shared filter builder now seeds contains on a multi-value column (the server refuses equality on its JSON column), so the equality control no longer applies there; that seed is pinned on its own. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01Utp6CZiaBg6rk7dpy1s9Me --- ...ConditionField.emptyOperators-10790.test.tsx | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/ui/packages/fields/src/widgets/__tests__/FilterConditionField.emptyOperators-10790.test.tsx b/ui/packages/fields/src/widgets/__tests__/FilterConditionField.emptyOperators-10790.test.tsx index a1b58f20b7a..b5b7aa2d74f 100644 --- a/ui/packages/fields/src/widgets/__tests__/FilterConditionField.emptyOperators-10790.test.tsx +++ b/ui/packages/fields/src/widgets/__tests__/FilterConditionField.emptyOperators-10790.test.tsx @@ -193,7 +193,7 @@ const TYPES: ReadonlyArray<{ type: string; field: string; label: string }> = [ { type: 'multiselect', field: 'tags', label: 'Tags' }, ]; -/** A fresh row on `label`'s column, still on the seed operator (`equals`). */ +/** A fresh row on `label`'s column, still on its seed operator (`equals`; `contains` on a multi-value column). */ async function freshRowOn(label: string) { const utils = renderWidget(''); await addRow(); @@ -226,7 +226,20 @@ describe('WRITER — each operator on each offered field type writes `$empty` (o expectAcceptedByTheFaces(stored); }); - it.each(TYPES)('CONTROL: the seed "equals" row on a $type column is untouched', async ({ field, label }) => { + // A multi-value column no longer seeds "equals": the server refuses equality on + // its JSON column (objectstack#35559), so the shared builder seeds "contains" + // there, which writes nothing until a member is picked. The equality CONTROL + // therefore runs on the single-value columns, and the multi-value seed is + // pinned on its own below. + const SINGLE_VALUE_TYPES = TYPES.filter(({ type }) => type !== 'multiselect'); + + it('CONTROL: a fresh row on a multiselect column seeds "Contains" and writes nothing yet', async () => { + const { onChange } = await freshRowOn('Tags'); + await waitFor(() => expect(screen.getAllByRole('combobox')[1]).toHaveTextContent('Contains')); + expect(lastEmitted(onChange)).toBe(''); + }); + + it.each(SINGLE_VALUE_TYPES)('CONTROL: the seed "equals" row on a $type column is untouched', async ({ field, label }) => { // Green before and after: the same harness and the same faces answer // "accepted" for an arm this change does not touch, so a red operator row // above is about the operator and not about the harness.