Skip to content
This repository was archived by the owner on Nov 4, 2026. It is now read-only.

Commit 01b3cee

Browse files
os-teslaclaude
andauthored
fix(app-shell): an unmapped dataset-filter operator is inert, not destructive (#9381)
* fix(app-shell): bridge `Is null` to the spec's `$null` instead of erasing the filter `groupToCondition` had no row for `isNull` / `isNotNull`, so an `Is null` row fell through to the unmapped-operator drop. A dropped last row makes the function return `undefined`, and the dataset inspector commits on every change, so switching the only condition's operator to an ordinary menu entry committed `{ filter: undefined }` and destroyed the stored `dataset.filter`. Nothing errored and the panel still showed the condition. Both directions now carry the spec's `$null` predicate, kept distinct from the `$exists` pair the two `isEmpty` rows already used. Operators this bridge does not map are still dropped rather than emitted in a spelling that means something else; that behaviour and the list of offered-but-unmappable operators are pinned alongside the fix. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UzHd6hDYatoDn17BuwKxnZ * fix(app-shell): an unmapped dataset-filter operator is inert, not destructive `groupToCondition` answers `undefined` both when the author CLEARED the filter and when nothing survived serialization, and the dataset inspector — which commits on every change — treated the two the same. The host applies patches as `{ ...draft, ...patch }`, so that commit SET `dataset.filter` to `undefined`, which is exactly the shape `objectChangePatch` uses deliberately to erase it. Two ordinary gestures reached it: switching the only condition's operator to one this bridge did not map, and — needing no operator at all — blanking the value of the only row. The stored filter was destroyed silently in both. The two meanings are now distinguished by `isClearedGroup`: a group that still holds rows commits nothing and leaves the stored filter alone; a group with no rows is the author's own clear gesture and still commits `undefined`. Deliberately not "emit something anyway" — a filter in a spelling that means something else is worse than a dropped one, so the unmapped arm still drops. `notContains`, `startsWith` and `endsWith` are no longer unmapped: each bridges to the spec's own token, backed by the Filter Protocol's canonical text-operator cases and its declared-type door, which passes them over `text` and refuses them over `number` / `date` — the only bucket this builder offers them on. `between` stays out until it has a both-bounds-present rule, and is now inert. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UzHd6hDYatoDn17BuwKxnZ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent dfb5850 commit 01b3cee

7 files changed

Lines changed: 578 additions & 24 deletions
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
---
4+
5+
Stop the Studio dataset-filter bridge from ERASING a stored filter when an edit
6+
cannot be serialized (objectui#9372). Behaviour change, not just a fix: three more
7+
operators are now STORED where they used to be dropped.
8+
9+
**The erase.** `groupToCondition` answers `undefined` both when the author CLEARED the
10+
filter and when nothing survived serialization, and the inspector — which commits on
11+
every change — treated the two the same. The host applies patches as
12+
`{ ...draft, ...patch }`, so that commit SET `dataset.filter` (or a `measure.filter`)
13+
to `undefined`, which is exactly the patch shape `objectChangePatch` uses deliberately
14+
to erase it. Nothing errored.
15+
16+
Two ordinary gestures reached it. Switching the only condition's operator to one this
17+
bridge did not map — `notContains`, `startsWith`, `endsWith` and `between`, all four
18+
ordinary entries in this inspector's menu, none of them opt-in. And, needing no
19+
operator at all, simply BLANKING the value of the only row: an incomplete row is
20+
dropped by the same path, the last part goes with it, and the answer is `undefined`.
21+
22+
**The fix, unconditional and ahead of any per-operator question.** The two meanings are
23+
now distinguished: a group that still holds rows commits NOTHING and the stored filter
24+
is left alone; only a group with no rows — Clear all, or the last row removed — still
25+
commits `undefined`, because that is the author's own gesture. An operator this bridge
26+
cannot express is therefore inert, whichever operators it maps.
27+
28+
⚠️ Deliberately not "emit something anyway". A filter emitted in a spelling that means
29+
something else is worse than one that was dropped, so the unmapped arm still drops.
30+
31+
**And three of the four are no longer unmapped.** `notContains`, `startsWith` and
32+
`endsWith` now serialize to the spec's own `$notContains` / `$startsWith` / `$endsWith`
33+
and read back as the operator the author picked. The comment calling them operators
34+
"this dialect genuinely cannot express" was stale: `FILTER_OPERATORS` carries all four.
35+
Each is backed by a conformance reading rather than a guess — the Filter Protocol's
36+
canonical `FILTER_TEXT_CASES` covers all three, the spec's declared-type door passes
37+
them over `text` and refuses them over `number` / `date` / `boolean`, and this builder
38+
offers them only on its text bucket.
39+
40+
`between` stays unmapped, for a reason about this bridge rather than the vocabulary:
41+
the builder pads a half-typed pair with an empty bound and the spec's comparand door
42+
accepts `[1, '']`, so emitting it needs a both-bounds-present rule first. It is now
43+
unmapped and inert instead of unmapped and destructive.
44+
45+
Forward note for anyone pinning stored filters: a dataset filter written by this
46+
version may carry `$notContains` / `$startsWith` / `$endsWith`, which an older
47+
app-shell reads as non-representable and degrades to "edit it in the Source tab".
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* The inspector does not COMMIT an erase (objectui#9372).
5+
*
6+
* ## Why this file exists next to the pure one
7+
*
8+
* `datasetFilterCondition.unmappedInert-9372.test.ts` pins the decision —
9+
* {@link isClearedGroup} tells the author's CLEAR gesture apart from a
10+
* serialization that produced nothing. A decision nobody consults is a channel
11+
* with no reader, and the pure file cannot tell the difference: it would stay
12+
* green with the guard sitting unused beside the old `onCommit(...)` call.
13+
*
14+
* This file drives the real component, with the real `FilterBuilder` mounted
15+
* inside it, and watches the ONE thing that caused the data loss — the patch.
16+
*
17+
* ## The gesture, and why it is the value and not the operator menu
18+
*
19+
* The card's route is an operator pick, but the same defect is reachable by
20+
* blanking the VALUE of the only row, with no operator involved at all: the
21+
* incomplete-row `continue` drops it, the last part goes, and the commit is
22+
* `undefined`. The host applies patches as `{ ...draft, ...patch }`, so that
23+
* commit SETS `filter` to `undefined` — the patch shape `objectChangePatch`
24+
* uses deliberately to erase it. Blanking a text input is also the one gesture
25+
* that needs no Radix listbox interaction, so this pin holds without driving a
26+
* select open in a headless DOM.
27+
*
28+
* ## The control
29+
*
30+
* "`onPatch` was not called" is also what an unopened popover, a mis-queried
31+
* input and a dead handler all look like. So the same file types a REAL value
32+
* through the same input and asserts the patch that produces — if that control
33+
* stops firing, the absence below stops meaning anything.
34+
*/
35+
import { describe, it, expect, vi, afterEach, type Mock } from 'vitest';
36+
import { render, screen, fireEvent, cleanup } from '@testing-library/react';
37+
import '@testing-library/jest-dom';
38+
39+
// Stub the catalog hooks so the inspector renders without a MetadataClient /
40+
// network, but with ONE text field so the filter popover has something to draw.
41+
vi.mock('./useDatasetFields', () => ({
42+
useObjectOptions: () => ({ options: [], loading: false }),
43+
useDatasetFieldCatalog: () => ({
44+
relationships: [],
45+
fieldOptions: [{ value: 'name', label: 'Name', type: 'text' }],
46+
loading: false,
47+
}),
48+
useDatasetUsage: () => ({ reports: 0, dashboards: 0, loading: false }),
49+
fieldTypeToDimensionType: (t: string) => (t === 'date' ? 'date' : 'string'),
50+
}));
51+
52+
import { DatasetDefaultInspector } from './DatasetDefaultInspector';
53+
54+
afterEach(cleanup);
55+
56+
const baseProps = { type: 'dataset', name: 'sales', locale: 'en-US' as const };
57+
58+
/** A dataset whose filter is ALREADY stored — the thing that got destroyed. */
59+
const draft = {
60+
name: 'sales',
61+
label: 'Sales',
62+
object: 'opportunity',
63+
include: [],
64+
dimensions: [],
65+
measures: [],
66+
filter: { name: { $eq: 'acme' } },
67+
};
68+
69+
/** The inspector's patch channel, typed as the component declares it. */
70+
type PatchSpy = Mock<(patch: Record<string, unknown>) => void>;
71+
const patchSpy = (): PatchSpy => vi.fn<(patch: Record<string, unknown>) => void>();
72+
73+
/** Render, open the Scope filter popover, and hand back the row's value input. */
74+
function openScopeFilter(onPatch: PatchSpy) {
75+
render(<DatasetDefaultInspector {...baseProps} draft={draft} onPatch={onPatch} readOnly={false} />);
76+
// The trigger summarises the stored filter; seeing it at all is already a
77+
// reading that `conditionToGroup` found the stored shape representable.
78+
fireEvent.click(screen.getByText('1 condition'));
79+
return screen.getByDisplayValue('acme') as HTMLInputElement;
80+
}
81+
82+
describe('DatasetDefaultInspector — a filter edit that cannot be stored commits nothing (objectui#9372)', () => {
83+
it('CONTROL: typing a real value still commits it, so the absence below is about the blank', () => {
84+
const onPatch = patchSpy();
85+
const input = openScopeFilter(onPatch);
86+
fireEvent.change(input, { target: { value: 'contoso' } });
87+
expect(onPatch).toHaveBeenCalledWith({ filter: { name: { $eq: 'contoso' } } });
88+
});
89+
90+
it('THE DEFECT: blanking the only row\'s value does NOT patch `filter` to undefined', () => {
91+
const onPatch = patchSpy();
92+
const input = openScopeFilter(onPatch);
93+
fireEvent.change(input, { target: { value: '' } });
94+
// Before the repair this called `onPatch({ filter: undefined })`, which the
95+
// host spreads over the draft — the stored filter destroyed, nothing shown
96+
// to the author, and `JSON.stringify` then omits the key on save.
97+
for (const [patch] of onPatch.mock.calls) {
98+
expect(
99+
patch,
100+
'the inspector committed a patch carrying `filter`; if it is undefined, that ERASES the stored filter',
101+
).not.toHaveProperty('filter');
102+
}
103+
});
104+
105+
it('and the author\'s own CLEAR gesture still reaches the draft', () => {
106+
// The other half: "Clear all" empties the group, which IS the clear
107+
// gesture, and must still commit `undefined`. Without this the repair
108+
// could have been a blanket "never commit undefined", stranding the filter
109+
// an author asked to remove.
110+
const onPatch = patchSpy();
111+
render(<DatasetDefaultInspector {...baseProps} draft={draft} onPatch={onPatch} readOnly={false} />);
112+
fireEvent.click(screen.getByText('1 condition'));
113+
fireEvent.click(screen.getByText('Clear all'));
114+
expect(onPatch).toHaveBeenCalledWith({ filter: undefined });
115+
});
116+
});

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

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import { InspectorComboField, type InspectorComboOption } from './InspectorCombo
3434
import { toFieldName } from '../previews/object-fields-io.js';
3535
import { formatMeasure } from '@object-ui/core';
3636
import { useDisplayLocale } from '@object-ui/i18n';
37-
import { conditionToGroup, groupToCondition, type FilterCondition } from './datasetFilterCondition.js';
37+
import { conditionToGroup, groupToCondition, isClearedGroup, type BuilderGroup, type FilterCondition } from './datasetFilterCondition.js';
3838
import {
3939
useObjectOptions,
4040
useDatasetFieldCatalog,
@@ -244,6 +244,31 @@ function DatasetFilterField({ label, help, value, onCommit, fields, disabled }:
244244
}) {
245245
const { group, representable } = conditionToGroup(value);
246246
const count = group.conditions.length;
247+
/**
248+
* Commit an edit — unless nothing survived serialization while rows are
249+
* still on screen (objectui#9372).
250+
*
251+
* `groupToCondition` answers `undefined` both when the author CLEARED the
252+
* filter and when every row was dropped, and this commit is what turns the
253+
* second one into data loss: `onCommit` lands as `onPatch({ filter })`, the
254+
* host applies it as `{ ...draft, ...patch }`, so `filter` is SET to
255+
* `undefined` — the very patch shape `objectChangePatch` uses to erase it.
256+
* An unmapped operator (`between`) or a blanked value on the only row would
257+
* therefore destroy a working stored filter, silently.
258+
*
259+
* Holding the patch leaves the stored value alone, which is the whole
260+
* requirement. ⛔ It is deliberately not "emit something anyway": a filter in
261+
* a spelling that means something else is worse than one that was dropped.
262+
* ⚠️ Known and accepted: the builder re-seeds its own state from `value`
263+
* whenever the two differ, so an unexpressible row is lost from the panel on
264+
* the next render the inspector happens to do. Losing an edit the bridge
265+
* could never have stored is not in the same class as destroying one it had.
266+
*/
267+
const commitFilterGroup = (g: BuilderGroup) => {
268+
const next = groupToCondition(g);
269+
if (next === undefined && !isClearedGroup(g)) return;
270+
onCommit(next);
271+
};
247272
return (
248273
<div className="space-y-1">
249274
<Label className="text-xs text-muted-foreground">{label}</Label>
@@ -263,7 +288,7 @@ function DatasetFilterField({ label, help, value, onCommit, fields, disabled }:
263288
{fields.length === 0 ? (
264289
<p className="text-xs text-muted-foreground">Pick a base object to add filter conditions.</p>
265290
) : (
266-
<FilterBuilder fields={fields as any} value={group as any} onChange={(g: any) => onCommit(groupToCondition(g))} />
291+
<FilterBuilder fields={fields as any} value={group as any} onChange={commitFilterGroup} />
267292
)}
268293
</PopoverContent>
269294
</Popover>

‎packages/app-shell/src/views/metadata-admin/inspectors/datasetFilterCondition.nullOperators-9363.test.ts‎

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,14 @@ describe('groupToCondition — the null predicates this inspector offers (object
108108
});
109109

110110
it('still drops an operator it does not map, rather than emitting a wrong filter', () => {
111-
// Deliberate, and kept: see this file's header. These four are OFFERED by
112-
// the menu and dropped, which erases the same way — tracked as its own
113-
// finding, not widened here on the way past.
114-
expect(groupToCondition(row('notContains', 'a'))).toBeUndefined();
111+
// Deliberate, and kept: see this file's header.
112+
//
113+
// objectui#9372 took the other three of the four this listed — the
114+
// `notContains` / `startsWith` / `endsWith` rows are asserted as EMITTED
115+
// in `datasetFilterCondition.unmappedInert-9372`, with the conformance
116+
// reading behind each — and made the remaining drop inert. `between` is
117+
// what is left: still offered, still dropped, and no longer destructive.
115118
expect(groupToCondition(row('between', [1, 5]))).toBeUndefined();
116-
expect(groupToCondition(row('startsWith', 'a'))).toBeUndefined();
117-
expect(groupToCondition(row('endsWith', 'a'))).toBeUndefined();
118119
});
119120

120121
it('an empty group is still `undefined` — that is the author CLEARING the filter', () => {
@@ -191,15 +192,21 @@ const OFFERED = offeredAcrossBuckets([]);
191192
/**
192193
* Offered, and deliberately NOT expressible by this bridge today.
193194
*
194-
* Each one drops on commit, and a drop of the last surviving row erases the
195-
* stored filter — the same mechanism objectui#9363 fixed for the null pair.
196-
* They are listed rather than fixed here because mapping them is a separate
197-
* decision per operator (`between` needs a both-bounds-present rule before it
198-
* can be emitted at all), and a blanket "stop dropping" would emit filters that
199-
* mean something else. Mapping one is what makes this list shrink — and this
200-
* assertion go red until it is updated.
195+
* Each one drops on commit. ⚠️ That drop used to ERASE the stored filter when
196+
* no other row survived — the same mechanism objectui#9363 fixed for the null
197+
* pair — and objectui#9372 ended that: the caller now tells "nothing survived"
198+
* apart from "the author cleared", so a drop is inert
199+
* (`datasetFilterCondition.unmappedInert-9372`). Being on this list is now a
200+
* missing capability, not data loss.
201+
*
202+
* objectui#9372 also took three of the four this listed. `between` is what
203+
* remains, and it remains for a reason that is about THIS bridge rather than
204+
* the spec's vocabulary: the builder pads a half-typed pair with `''` and the
205+
* spec's comparand door accepts `[1, '']`, so it needs a both-bounds-present
206+
* rule before it can be emitted at all. Mapping it is what makes this list
207+
* shrink — and this assertion go red until it is updated.
201208
*/
202-
const DECLARED_UNEXPRESSIBLE = ['between', 'endsWith', 'notContains', 'startsWith'];
209+
const DECLARED_UNEXPRESSIBLE = ['between'];
203210

204211
/** A value that keeps a row from being dropped as INCOMPLETE, per operator. */
205212
function probeValue(operator: string): unknown {

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ describe('datasetFilterCondition', () => {
2121
});
2222

2323
it('drops unmapped operators rather than emitting a bad filter', () => {
24-
expect(groupToCondition({ logic: 'and', conditions: [{ field: 'x', operator: 'notContains', value: 'a' }] }))
24+
// The claim is unchanged; the FIXTURE moved. `notContains` stopped being
25+
// an unmapped operator in objectui#9372 (it is bridged to `$notContains`,
26+
// asserted there), so keeping it here would have pinned a branch it no
27+
// longer reaches — an assertion that passes because nothing is produced.
28+
// `between` is the operator this bridge still declines to emit.
29+
expect(groupToCondition({ logic: 'and', conditions: [{ field: 'x', operator: 'between', value: [1, 5] }] }))
2530
.toBeUndefined();
2631
});
2732

0 commit comments

Comments
 (0)