Skip to content

Commit ed32291

Browse files
committed
fix(drill): the list URL says a boolean, $in/$nin, $ne and the text operators, so "Open in list" and "View all" open the exact list again
The object list route gains `filter[FIELD][bool]=true|false`, the `[ne|contains|notcontains|startswith|endswith|icontains]` suffixes and the repeated `[in]` / `[nin]` membership params. Each reads back through parseUrlFilterTriples as the node convertFiltersToAST lowers the same condition to, comparand type included, and exactRecordListFilter now proves that per condition before it accepts one. A drill on a yes/no bucket or under an $in / $ne / text-operator scope, and a related list's "View all" with such a filter, get their list destination back; $or, $between, an empty set and a boolean under $ne stay refused. Claude-Session: https://claude.ai/code/session_01L6bhgW9yrPaVhdtD84RWcR Co-authored-by: Claude <noreply@anthropic.com>
1 parent b309866 commit ed32291

10 files changed

Lines changed: 609 additions & 33 deletions
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
---
4+
5+
fix(drill): "Open in list" and a related list's "View all" open the exact list again for a yes/no bucket, an `$in` / `$nin` set, `$ne` and the text operators
6+
7+
Clause-②: yes (widening)
8+
Metadata-protocol: none
9+
10+
The object list route (`/apps/APP/OBJECT/data?filter[...]`) gains six spellings, each read back as the very comparison the drill drawer queries, comparand type included:
11+
12+
- `filter[FIELD][bool]=true|false` is equality to the boolean. `filter[FIELD]=true` still means the text "true".
13+
- `filter[FIELD][ne|contains|notcontains|startswith|endswith|icontains]=VALUE` is `$ne` and the five text operators.
14+
- `filter[FIELD][in]=A&filter[FIELD][in]=B` (and `[nin]`) is a set, one repeated param per member.
15+
16+
A drill or "View all" whose filter uses only these and the earlier spellings now offers its list destination; anything the route still cannot say exactly (`$or`, `$between`, an empty set, a boolean under `$ne`) still offers none rather than a wider list. The list page shows each new condition as a chip with the filter builder's own operator label, removes it with the chip, and keeps it through "Save as view".

‎ui/packages/app-shell/src/views/ObjectDataPage.filterChipI18n-9159.test.tsx‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,3 +256,37 @@ describe('the is-empty filter chips are translated (objectui#11547)', () => {
256256
expect(packLabelOf('zh', EMPTY_FILTER.labelKey)).not.toBe(packLabelOf('zh', NULL_FILTER.labelKey));
257257
});
258258
});
259+
260+
/**
261+
* objectstack#30743 — a membership or negation chip draws its operator through
262+
* the filter builder's label and its comparand verbatim, on the real page and
263+
* the real packs: the label half translated, the comparand half not.
264+
*/
265+
describe('the membership and negation chips (objectstack#30743)', () => {
266+
const packLabelOf = (language: string, key: string): unknown =>
267+
key.split('.').reduce<unknown>(
268+
(node, part) => (node as Record<string, unknown> | undefined)?.[part],
269+
(builtInLocales as Record<string, unknown>)[language],
270+
);
271+
272+
it.each([
273+
['in', 'filterBuilder.operators.in'],
274+
['nin', 'filterBuilder.operators.not_in'],
275+
])('`[%s]` renders the zh label of `%s` beside the members, joined', (suffix, key) => {
276+
renderAt('zh', `filter[${FIELD}][${suffix}]=alice&filter[${FIELD}][${suffix}]=bob`);
277+
expect(chipOperatorText()).toBe(`${packLabelOf('zh', key)} alice, bob`);
278+
});
279+
280+
it('`[ne]` renders the zh "does not equal" label beside the comparand', () => {
281+
renderAt('zh', `filter[${FIELD}][ne]=alice`);
282+
const rendered = chipOperatorText();
283+
expect(rendered).toBe(`${packLabelOf('zh', 'filterBuilder.operators.not_equals')} alice`);
284+
expect(rendered).not.toContain('filterBuilder.operators');
285+
});
286+
287+
it('CONTROL: the en pack differs, so the label half really went through `t`', () => {
288+
renderAt('en', `filter[${FIELD}][in]=alice`);
289+
expect(chipOperatorText()).toBe(`${packLabelOf('en', 'filterBuilder.operators.in')} alice`);
290+
expect(packLabelOf('zh', 'filterBuilder.operators.in')).not.toBe(packLabelOf('en', 'filterBuilder.operators.in'));
291+
});
292+
});

‎ui/packages/app-shell/src/views/ObjectDataPage.saveAsViewFilterFold.test.ts‎

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import {
2929
URL_FILTER_OPS,
3030
NULL_FILTER,
3131
EMPTY_FILTER,
32+
URL_COMPARE_OPS,
33+
URL_LIST_OPS,
3234
parseUrlFilterTriples,
3335
type FilterTriple,
3436
} from './drillUrlFilters';
@@ -103,7 +105,7 @@ describe('Save as view folds URL drill triples to spec rules (objectui#3419)', (
103105
// and the emptiness PAIR, whose one param carries a direction rather than a
104106
// comparand and so is not in that range map) so an operator added to the URL
105107
// contract fails HERE rather than at publish time. `parseUrlFilterTriples`
106-
// emits nothing outside this set.
108+
// emits nothing outside this set and the next test's (objectstack#30743).
107109
//
108110
// ⚠️ `NULL_FILTER.notOp` joined the set in objectui#9508. Listing only
109111
// `op` would have left this pin GREEN while the contract grew an operator
@@ -150,6 +152,33 @@ describe('Save as view folds URL drill triples to spec rules (objectui#3419)', (
150152
expect(gate.success).toBe(true);
151153
});
152154

155+
it('folds the negation, text, membership and boolean triples too (objectstack#30743)', () => {
156+
// Computed from the two maps for the reason the test above gives: an
157+
// operator added to either map fails here, not at publish time.
158+
expect(Object.values(URL_COMPARE_OPS)).toEqual([
159+
'!=', 'contains', 'notcontains', 'startswith', 'endswith', 'icontains',
160+
]);
161+
expect(Object.values(URL_LIST_OPS)).toEqual(['in', 'nin']);
162+
const triples: FilterTriple[] = [
163+
...Object.values(URL_COMPARE_OPS).map((op, i) => ['c' + i, op, 'v' + i] as FilterTriple),
164+
...Object.values(URL_LIST_OPS).map((op, i) => ['l' + i, op, ['a', 'b']] as FilterTriple),
165+
['done', '=', true],
166+
];
167+
const { spec, gate } = saveAsView(triples);
168+
expect(spec.filter).toEqual([
169+
{ field: 'c0', operator: 'not_equals', value: 'v0' },
170+
{ field: 'c1', operator: 'contains', value: 'v1' },
171+
{ field: 'c2', operator: 'not_contains', value: 'v2' },
172+
{ field: 'c3', operator: 'starts_with', value: 'v3' },
173+
{ field: 'c4', operator: 'ends_with', value: 'v4' },
174+
{ field: 'c5', operator: 'icontains', value: 'v5' },
175+
{ field: 'l0', operator: 'in', value: ['a', 'b'] },
176+
{ field: 'l1', operator: 'not_in', value: ['a', 'b'] },
177+
{ field: 'done', operator: 'equals', value: true },
178+
]);
179+
expect(gate.success).toBe(true);
180+
});
181+
153182
it('keeps the is-NOT-null direction intact through the fold too (objectui#9508)', () => {
154183
// A drill that can be WRITTEN into the URL must also be savable, or the
155184
// user reads a chip the saved view then silently does not carry.

‎ui/packages/app-shell/src/views/ObjectDataPage.tsx‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ import {
5757
groupFilterChips,
5858
deleteFieldFilterParams,
5959
URL_FILTER_OPS,
60+
URL_TRIPLE_OP_WORD,
6061
type FilterTriple,
6162
} from './drillUrlFilters.js';
6263
import {
@@ -147,6 +148,9 @@ const TRIPLE_OP_TO_SPEC_ALIAS: Record<string, string> = {
147148
...Object.fromEntries(
148149
Object.entries(URL_FILTER_OPS).map(([suffix, symbol]) => [symbol, suffix]),
149150
),
151+
// objectstack#30743 — negation, text and membership triples carry their
152+
// canonical word already, which `normalizeFilterOperator` returns unchanged.
153+
...URL_TRIPLE_OP_WORD,
150154
};
151155

152156
/**
@@ -171,7 +175,7 @@ const TRIPLE_OP_TO_SPEC_ALIAS: Record<string, string> = {
171175
* from the persisted view with a debug-level note, never written off-spec:
172176
* declared = enforced, and a view body that fails the record gate is rejected
173177
* whole at publish time, which would lose the user's other conditions too.
174-
* (`parseUrlFilterTriples` only ever emits the five operators bridged above, so
178+
* (`parseUrlFilterTriples` only ever emits operators bridged above, so
175179
* the drop path is defence in depth against the URL contract growing an
176180
* operator the spec has no word for.)
177181
*/
@@ -675,7 +679,9 @@ export function ObjectDataPage({ dataSource, objects }: any) {
675679
unwatched second English spelling that hides a pack miss
676680
(objectui#3469 deleted exactly that pattern from this console).
677681
*/}
678-
<span className="text-muted-foreground">{textKey ? t(textKey) : text}</span>
682+
<span className="text-muted-foreground">
683+
{textKey && text !== undefined ? `${t(textKey)} ${text}` : textKey ? t(textKey) : text}
684+
</span>
679685
<button
680686
type="button"
681687
onClick={() => removeUrlFilter(field)}

‎ui/packages/app-shell/src/views/ObjectView.urlFilterSuffix-9196.test.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,15 @@ const objectRoute = (qs: string) => parseUrlEqualityFilterTriples(new URLSearchP
7878

7979
describe("objectui#9196 — the card's three rows, both readers, one run", () => {
8080
it('row 1 — an unknown operator suffix is dropped by BOTH readers', () => {
81-
expect(dataSurface('filter[owners][contains]=u1')).toEqual([]);
81+
// `[contains]` was this row's unknown suffix until objectstack#30743 gave
82+
// the `/data` surface a text-operator spelling; `[like]` is still unknown
83+
// to both.
84+
expect(dataSurface('filter[owners][like]=u1')).toEqual([]);
85+
expect(objectRoute('filter[owners][like]=u1')).toEqual([]);
86+
});
87+
88+
it('row 1, after objectstack#30743 — `[contains]` executes on /data ONLY, and is dropped on the object route', () => {
89+
expect(dataSurface('filter[owners][contains]=u1')).toEqual([['owners', 'contains', 'u1']]);
8290
expect(objectRoute('filter[owners][contains]=u1')).toEqual([]);
8391
});
8492

@@ -160,6 +168,7 @@ describe('objectui#9196 — no emitted field name ever carries a bracket', () =>
160168
]);
161169
expect(inputs.flatMap((qs) => dataSurface(qs))).toEqual([
162170
['amount', '>=', '100'],
171+
['owners', 'contains', 'u1'],
163172
['owners', '=', 'u1'],
164173
['account.region', '=', 'NA'],
165174
]);

‎ui/packages/app-shell/src/views/__tests__/exactRecordListFilter-25888.test.ts‎

Lines changed: 80 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import { describe, it, expect } from 'vitest';
1414
import { exactRecordListFilter, recordListPath } from '../useOpenRecordList';
1515
import { parseUrlFilterTriples } from '../drillUrlFilters';
16+
import { convertFiltersToAST } from '@object-ui/core';
1617

1718
const readAll = () => true;
1819
const PARENT = { record_id: 'C-1' };
@@ -69,17 +70,92 @@ describe('exactRecordListFilter — the AND of the sources, written exactly or n
6970
]);
7071
});
7172

73+
it('writes the spellings objectstack#30743 added: a boolean, a negation, the text operators, both sets', () => {
74+
const filter = exactRecordListFilter(
75+
[
76+
PARENT,
77+
[
78+
['done', '=', true],
79+
['archived', '=', false],
80+
['status', 'in', ['paid', 'sent']],
81+
['stage', 'nin', ['lost']],
82+
['owner', '!=', 'u1'],
83+
['name', 'contains', 'acme'],
84+
['name', 'notcontains', 'test'],
85+
['code', 'startswith', 'INV'],
86+
['code', 'endswith', '-X'],
87+
['email', 'icontains', 'ACME'],
88+
],
89+
],
90+
readAll,
91+
);
92+
expect(roundTrip(filter)).toEqual([
93+
['record_id', '=', 'C-1'],
94+
['done', '=', true],
95+
['archived', '=', false],
96+
['status', 'in', ['paid', 'sent']],
97+
['stage', 'nin', ['lost']],
98+
['owner', '!=', 'u1'],
99+
['name', 'contains', 'acme'],
100+
['name', 'notcontains', 'test'],
101+
['code', 'startswith', 'INV'],
102+
['code', 'endswith', '-X'],
103+
['email', 'icontains', 'ACME'],
104+
]);
105+
});
106+
107+
it('reads each of those back as the node the drill drawer queries, comparand type included', () => {
108+
// The drawer lowers the drill's object filter through `convertFiltersToAST`;
109+
// the list lowers nothing, it reads triples. The two must be one question.
110+
const cases: Record<string, unknown>[] = [
111+
{ done: true },
112+
{ done: false },
113+
{ status: { $in: ['paid', 'sent'] } },
114+
{ stage: { $nin: ['lost'] } },
115+
{ owner: { $ne: 'u1' } },
116+
{ name: { $contains: 'acme' } },
117+
{ name: { $notContains: 'test' } },
118+
{ code: { $startsWith: 'INV' } },
119+
{ code: { $endsWith: '-X' } },
120+
{ email: { $icontains: 'ACME' } },
121+
];
122+
for (const condition of cases) {
123+
expect(roundTrip(exactRecordListFilter([condition], readAll))).toEqual([convertFiltersToAST(condition)]);
124+
}
125+
});
126+
127+
it('a set of numbers reads back as its members\' text, the posture equality and the bounds already have', () => {
128+
expect(roundTrip(exactRecordListFilter([{ priority: { $in: [1, 2] } }], readAll))).toEqual([
129+
['priority', 'in', ['1', '2']],
130+
]);
131+
});
132+
133+
it('a set and an equality on one field are two params, both kept', () => {
134+
expect(roundTrip(exactRecordListFilter([{ status: { $in: ['a', 'b'] } }, { status: 'a' }], readAll))).toEqual([
135+
['status', 'in', ['a', 'b']],
136+
['status', '=', 'a'],
137+
]);
138+
});
139+
140+
it('a repeated set that agrees is written once', () => {
141+
const set = { status: { $in: ['a', 'b'] } };
142+
expect(roundTrip(exactRecordListFilter([set, set], readAll))).toEqual([['status', 'in', ['a', 'b']]]);
143+
});
144+
72145
it('a repeated condition that agrees is written once', () => {
73146
const filter = exactRecordListFilter([PARENT, [['record_id', '=', 'C-1']]], readAll);
74147
expect(roundTrip(filter)).toEqual([['record_id', '=', 'C-1']]);
75148
});
76149

77150
it.each([
78151
['an `or`', ['or', ['status', '=', 'a'], ['status', '=', 'b']]],
79-
['a set operator', [['status', 'in', ['a', 'b']]]],
80-
['a negation', [['status', '!=', 'a']]],
81-
['a text operator', [['name', 'contains', 'x']]],
82-
['a boolean comparand', [['done', '=', true]]],
152+
['an empty set', { status: { $in: [] } }],
153+
['a set holding an empty string', { status: { $in: ['a', ''] } }],
154+
['a set holding a boolean', { status: { $in: ['a', true] } }],
155+
['two different sets on one field', { $and: [{ status: { $in: ['a', 'b'] } }, { status: { $in: ['a'] } }] }],
156+
['a negation of a boolean', [['done', '!=', true]]],
157+
['a text operator with a number', { name: { $contains: 5 } }],
158+
['a `$between`', { amount: { $between: [1, 9] } }],
83159
['an empty-string comparand', [['status', '=', '']]],
84160
['a field-reference comparand', { amount: { $eq: { $field: 'budget' } } }],
85161
['a second, different comparand for the relationship', [['record_id', '=', 'C-2']]],

0 commit comments

Comments
 (0)