Skip to content

Commit 2771575

Browse files
feat(components): the filter panel offers relative dates on date rows (#29263)
<!-- claude-projects-attribution: {"github_login":"zhuangjianguo"} --> _Requested by **Steedos** · [project thread](https://claude.ai/code/project/chan_018ETKaNwMZCNRYD7D8Q9Ubb?thread=cmsg_018ETKaNwMZCNRYD7D8Q9UbbPw4YoBPXoEgXDh4EUyz68a)_ Fixes #29115 Clause-②: no Metadata-protocol: none ## 维护者速读 - **改了什么**:列表筛选面板里日期/日期时间字段的「介于」新增 13 个相对区间(今天、本周、本月、近 30 天……),「早于/晚于」新增今天、昨天、明天;选中后存的是宏(如 `{week_start}`),不再是当天的固定日期。 - **为什么改**:销售按「本周」或「早于今天」筛选并保存后,第二天、下周一筛选结果就悄悄错了,没有任何提示。 - **风险与回滚**:只改共享的筛选组件 `FilterBuilder`(列表、看板、日历、Studio 视图筛选、数据集和共享规则条件都用它);存储形状仍是普通 `ViewFilterRule`,没有新运算符、新键。回滚即 revert 本 PR,已存的宏值服务端照常解析。 - **先看**:`ui/packages/components/src/custom/filter-builder.tsx`(`renderValueInput` 外包一层选择、`changeOperator` 切换运算符时清空不匹配的相对值)、`ui/packages/components/src/custom/filterRelativeDates.ts`(宏对 → 预设的反查,读 spec 表不留副本)。 - **两分钟验证**:`pnpm --dir ui exec vitest run packages/components/src/__tests__/filter-builder-relative-dates-29115.test.tsx`,预期 49 个测试全绿。 - **需要你做的**:无,席位落地。 ## What changes On a `date` or `datetime` row of the filter builder: - **`between`** offers the spec's `DATE_RANGE_PRESETS` (all 13, in spec order) beside `Custom…`, which keeps today's two date inputs. A chosen preset is stored as its window from `DATE_RANGE_PRESET_MACRO_WINDOWS`, e.g. `['{week_start}', '{week_end}']`. - **`before` / `after`** offer today, yesterday and tomorrow beside `Custom…`. A chosen point is stored as the wrapped token, e.g. `'{today}'`. - **Read back:** a stored pair shows its preset's label after folding the `{current_*}` aliases (`DATE_MACRO_ALIAS_TOKENS`), so `['{current_week_start}', '{current_week_end}']` shows "This week". A placeholder value no preset or point matches (`['{7_days_ago}', '{tomorrow}']`) is kept, shown as its own text, and still filters. A fixed date shows as `Custom…` with its date, as before. - **Switches:** an operator change carries a relative value only to an operator offering the same kind (`before` today → `after` today); otherwise the row starts empty, so half a window never becomes a point and no token lands in a date input that cannot show it. A field switch between two date columns keeps the value (`convertScalarToFamily` holds a date macro in the `date` / `datetime` families). - **Labels** reuse keys every pack already has: `dashboard.filters.range.*` (the dashboard filter bar's 13 preset labels), `dashboard.filters.custom` and `fields.datePicker.tomorrow`. No i18n key is added; each is copied into the builder's defaults table verbatim from the `en` pack. The reverse lookup lives in a new module beside the builder, `filterRelativeDates.ts`. It is not re-exported from the package entry (`custom/index.ts` lists files by name), so nothing is added to `@object-ui/components`' published surface. It reads `DATE_RANGE_PRESETS`, `DATE_RANGE_PRESET_MACRO_WINDOWS`, `DATE_MACRO_ALIAS_TOKENS`, `DATE_MACRO_WRAPPED_RE` and `isDateMacroToken` from `@objectstack/spec/data` and keeps no copy; `packages/spec` is not edited. Not in this PR, per the card: a "last N days" input, relative values on `equals`, future-facing presets, a week-start setting, the record form's shortcuts, migrating stored absolute dates, the author `date-range` chip, the dashboard's bounds table (#29116) and the browser-versus-server clock (#29117). ## Tests New `filter-builder-relative-dates-29115.test.tsx`, 49 tests: - the 13 presets in spec order plus `Custom…`; each preset sends its spec window (and never a preset name), on `date` and on `datetime`; `This week` sends `['{week_start}', '{week_end}']` and the rule passes `ViewFilterRuleSchema`; - `before` → Today sends `'{today}'`; `after` → Tomorrow on a datetime row sends `'{tomorrow}'`; the three points are spec instant tokens; - a stored `{current_week_*}` pair shows "This week" without an emit; a stored `['{7_days_ago}', '{tomorrow}']` shows as text, keeps no date inputs, and is re-emitted unchanged; the zh pack shows 本周; - `Custom…` keeps the date inputs and they still write dates; choosing `Custom…` from a preset clears to `[]`; - operator and field switches as above; - controls: `equals` on a date row, text and number rows draw no relative choice; every label key exists in all ten packs. Ablation (committed fix first, `scripts/ablation-replace.mjs`, test imports `src`, no dist in the path): the window leg was changed to store today's resolved date pair instead of the macro window. Result: 16 failed / 33 passed of 49, then restored (`blob == HEAD`, `git diff HEAD` empty). <details><summary>Suite readings</summary> - the 23 existing `filter-builder*` files in `packages/components`: 23/23 files, 397/397 tests green with the change (locked, `--maxWorkers=2`). - the new file: 49/49 green. - `@object-ui/components` `type-check` (`tsc --noEmit && tsc -p tsconfig.test.json`): exit 0. - the full `packages/components` suite: 471 files passed, 1 skipped (4530 tests passed, 24 skipped), in four locked batches. </details> ## Acceptance notes - **URL, stored preference and save-as-view** were measured with a throwaway probe (not committed) on `userFilterUrlState` and `foldFilterGroupToSpecRules`: for `['{week_start}', '{week_end}']`, `['{current_week_start}', '{current_week_end}']`, `'{today}'` on `before` and `['{7_days_ago}', '{tomorrow}']` the `uf__filter` write → read round trip and the fold return the value unchanged, and each folded rule passes `ViewFilterRuleSchema`. The live query AST is `['close_date', 'between', ['{week_start}', '{week_end}']]`, lowered by the spec to `{ close_date: { $between: [...] } }`; `before` today lowers to `$lt: '{today}'`. "Reset view" was not separately measured; it clears the panel through the existing path, which is value-agnostic. - **Kanban and calendar hosts** were measured in jsdom with a throwaway `ListView` probe (not committed), seeding the panel with `['{current_week_start}', '{current_week_end}']`: on grid, kanban and calendar the panel shows "This week" and the data source `find` carries the macro pair unchanged (kanban also hands it to the lane component). The calendar ANDs its own visible-window node computed from browser dates beside it, which is existing behaviour and the subject of #29117. A real Console run against a server (REST row counts, datetime last-day coverage) is NOT MEASURED here; the card's own REST readings show the server resolves these tokens, including a `datetime` column's last day. - **Other builder surfaces:** the builder is shared, so Studio's view filter, the dataset filter inspector and sharing-rule criteria get the same choices. Each stores the same spec tokens, and the server resolves them on every ObjectQL read and write path and in the analytics executor (`resolveFilterTokens`), which a sharing rule's `engine.find` goes through. - No docs page documents the builder's value editors (`content/docs/frontend/renderers.mdx` lists the renderer only), so no docs edit. ## Verification The 34 derived gates (`dispatch-gates --commands`) ran at `35916c61` (after merging `origin/main`): 34/34 exit 0, `--ran` reconciliation 34 run, 0 NOT-MEASURED. `pnpm --dir ui exec vitest run scripts/` at the same head: 169 files passed, 2 skipped, exit 0. The full `packages/components` suite at `007ea328` (before that merge): 471 files passed, 1 skipped, 4530 tests, in four locked batches. `origin/main` was merged again before opening (head `64a3459f`; incoming commits touch none of this PR's files, and leave the reused i18n keys unchanged). Re-run there: the 24 `filter-builder*` files (446 tests) green, `@object-ui/components` type-check exit 0, `check-changeset-no-major`, `check-sdui-manifest`, `check-empty-changeset` and `check:nul-bytes` exit 0. Every family CI runs is read from this PR's check-runs. --- _Generated by [Claude Code](https://claude.ai/code/session_01QsR2jSjVXJnFT3sLMzwrKq)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent fa5e863 commit 2771575

5 files changed

Lines changed: 602 additions & 8 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
'@object-ui/components': patch
3+
---
4+
5+
feat(components): the filter panel offers relative dates on date rows, stored as date-macro tokens
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
A `date` or `datetime` row of the filter builder (the list filter panel, and the other surfaces that share the builder) now offers relative dates beside a fixed date:
11+
12+
- **`between`** offers the 13 date-range presets of `@objectstack/spec` (`DATE_RANGE_PRESETS`, in that order: today, yesterday, this week, … last 90 days) beside `Custom…`, which keeps the two date inputs. A chosen preset is stored as the spec's macro window from `DATE_RANGE_PRESET_MACRO_WINDOWS`, for example `['{week_start}', '{week_end}']`.
13+
- **`before` / `after`** offer today, yesterday and tomorrow beside `Custom…`. A chosen point is stored as the wrapped token, for example `'{today}'`.
14+
15+
The stored rule stays an ordinary `ViewFilterRule`: no operator, key or value kind is added, a preset name is never stored, and the query resolves the tokens when it runs, so a filter saved as "this week" still means this week next Monday. A stored pair reads back as its preset (the `{current_*}` aliases fold first: `['{current_week_start}', '{current_week_end}']` shows "This week"); a placeholder value no preset matches, such as `['{7_days_ago}', '{tomorrow}']`, is kept, shown as its text, and still filters. A stored fixed date shows as `Custom…` with its date, as before, and still means that day.
16+
17+
The labels reuse the keys the dashboard filter bar and the date picker already translate (`dashboard.filters.range.*`, `dashboard.filters.custom`, `fields.datePicker.tomorrow`). Relative values on `equals` are not offered.
Lines changed: 322 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,322 @@
1+
/**
2+
* ObjectUI
3+
* Copyright (c) 2024-present ObjectStack Inc.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
/**
10+
* The filter panel offers relative dates on a `date` / `datetime` row
11+
* (objectstack#29115): the spec's 13 date-range presets on `between`, and
12+
* today / yesterday / tomorrow on `before` / `after`.
13+
*
14+
* What is pinned is what gets STORED: a preset writes the spec's macro window
15+
* (`['{week_start}', '{week_end}']`), a point writes the wrapped token
16+
* (`'{today}'`), never a resolved date and never a preset name. A resolved date
17+
* is the defect the card names: "this week" saved today means last week on
18+
* Monday, with no hint.
19+
*
20+
* The reverse reading is pinned too: a stored window shows its preset's label
21+
* (the `{current_*}` aliases folded first), and a placeholder value no preset
22+
* matches is kept, shown as its own text, and still sent.
23+
*/
24+
import { describe, it, expect, vi, afterEach } from 'vitest';
25+
import React from 'react';
26+
import { render, screen, fireEvent, waitFor, cleanup } from '@testing-library/react';
27+
import '@testing-library/jest-dom';
28+
import {
29+
DATE_MACRO_INSTANT_TOKENS,
30+
DATE_RANGE_PRESETS,
31+
DATE_RANGE_PRESET_MACRO_WINDOWS,
32+
} from '@objectstack/spec/data';
33+
import { ViewFilterRuleSchema } from '@objectstack/spec/ui';
34+
import { I18nProvider } from '@object-ui/i18n';
35+
import { builtInLocales } from '@object-ui/i18n/locales';
36+
37+
import { FilterBuilder } from '../custom/filter-builder';
38+
import {
39+
RELATIVE_DATE_POINTS,
40+
dateMacroName,
41+
dateRangePresetOf,
42+
dateRangePresetValue,
43+
relativeDatePointOf,
44+
} from '../custom/filterRelativeDates';
45+
46+
afterEach(cleanup);
47+
48+
const FIELDS = [
49+
{ value: 'close_date', label: 'Close date', type: 'date' },
50+
{ value: 'created_at', label: 'Created at', type: 'datetime' },
51+
{ value: 'due_date', label: 'Due date', type: 'date' },
52+
{ value: 'name', label: 'Name', type: 'text' },
53+
{ value: 'amount', label: 'Amount', type: 'number' },
54+
];
55+
56+
const EN_PRESET_LABELS: Record<string, string> = {
57+
today: 'Today',
58+
yesterday: 'Yesterday',
59+
this_week: 'This week',
60+
last_week: 'Last week',
61+
this_month: 'This month',
62+
last_month: 'Last month',
63+
this_quarter: 'This quarter',
64+
last_quarter: 'Last quarter',
65+
this_year: 'This year',
66+
last_year: 'Last year',
67+
last_7_days: 'Last 7 days',
68+
last_30_days: 'Last 30 days',
69+
last_90_days: 'Last 90 days',
70+
};
71+
72+
function renderRow(condition: Record<string, unknown>, wrap?: (node: React.ReactNode) => React.ReactNode) {
73+
const onChange = vi.fn();
74+
// Hoisted out of the JSX: the sync effect re-seeds on a new `value` identity.
75+
const value = { id: 'root', logic: 'and', conditions: [{ id: 'c1', ...condition }] };
76+
const node = <FilterBuilder fields={FIELDS as any} value={value as any} onChange={onChange} />;
77+
const utils = render(<>{wrap ? wrap(node) : node}</>);
78+
return { ...utils, onChange };
79+
}
80+
81+
/** The row the component handed back on its most recent `onChange`. */
82+
function lastRow(onChange: ReturnType<typeof vi.fn>) {
83+
const calls = onChange.mock.calls;
84+
expect(calls.length, 'the builder never called onChange').toBeGreaterThan(0);
85+
return calls[calls.length - 1][0].conditions[0];
86+
}
87+
88+
const relativeTrigger = (field: string) => screen.queryByTestId(`filter-relative-date-${field}`);
89+
90+
/** Open a combobox and return the option labels it mounts, in order. */
91+
async function openOptions(trigger: HTMLElement): Promise<HTMLElement[]> {
92+
fireEvent.keyDown(trigger, { key: 'ArrowDown' });
93+
return waitFor(() => {
94+
const options = screen.getAllByRole('option');
95+
expect(options.length).toBeGreaterThan(0);
96+
return options;
97+
});
98+
}
99+
100+
async function choose(trigger: HTMLElement, label: string) {
101+
const options = await openOptions(trigger);
102+
const option = options.find((o) => o.textContent === label);
103+
expect(option, `no "${label}" option`).toBeTruthy();
104+
fireEvent.click(option!);
105+
}
106+
107+
async function pickOperator(label: string) {
108+
await choose(screen.getAllByRole('combobox')[1], label);
109+
}
110+
111+
async function pickField(label: string) {
112+
await choose(screen.getAllByRole('combobox')[0], label);
113+
}
114+
115+
describe('the reverse lookup reads the spec table', () => {
116+
it('every relative point is one of the spec instant tokens', () => {
117+
for (const point of RELATIVE_DATE_POINTS) {
118+
expect(DATE_MACRO_INSTANT_TOKENS as readonly string[]).toContain(point);
119+
}
120+
});
121+
122+
it.each(DATE_RANGE_PRESETS)('%s: the stored window reads back as the preset', (preset) => {
123+
const stored = dateRangePresetValue(preset);
124+
expect(stored).toEqual([...DATE_RANGE_PRESET_MACRO_WINDOWS[preset]]);
125+
expect(dateRangePresetOf(stored)).toBe(preset);
126+
});
127+
128+
it('folds the current_ aliases and the dollar spelling', () => {
129+
expect(dateRangePresetOf(['{current_week_start}', '{current_week_end}'])).toBe('this_week');
130+
expect(dateRangePresetOf(['{current_month_start}', '{month_end}'])).toBe('this_month');
131+
expect(dateRangePresetOf(['${quarter_start}', '${current_quarter_end}'])).toBe('this_quarter');
132+
expect(dateMacroName('{current_year_end}')).toBe('year_end');
133+
expect(relativeDatePointOf('${today}')).toBe('today');
134+
});
135+
136+
it('a pair no window matches, a date, a preset name and an unknown token read as nothing', () => {
137+
expect(dateRangePresetOf(['{7_days_ago}', '{tomorrow}'])).toBeUndefined();
138+
expect(dateRangePresetOf(['2026-11-02', '2026-11-08'])).toBeUndefined();
139+
expect(dateRangePresetOf(['{week_start}'])).toBeUndefined();
140+
expect(dateMacroName('this_week')).toBeUndefined();
141+
expect(dateMacroName('{this_week}')).toBeUndefined();
142+
expect(relativeDatePointOf('{7_days_ago}')).toBeUndefined();
143+
expect(relativeDatePointOf('2026-11-02')).toBeUndefined();
144+
});
145+
});
146+
147+
describe('between on a date row offers the spec presets and stores the macro window', () => {
148+
it('lists the 13 presets in spec order, then Custom…', async () => {
149+
renderRow({ field: 'close_date', operator: 'between', value: [] });
150+
const options = await openOptions(relativeTrigger('close_date')!);
151+
expect(options.map((o) => o.textContent)).toEqual([
152+
...DATE_RANGE_PRESETS.map((p) => EN_PRESET_LABELS[p]),
153+
'Custom…',
154+
]);
155+
});
156+
157+
it('This week sends the week window, not a date and not the preset name', async () => {
158+
const { onChange } = renderRow({ field: 'close_date', operator: 'between', value: [] });
159+
await choose(relativeTrigger('close_date')!, 'This week');
160+
const row = lastRow(onChange);
161+
expect(row.value).toEqual(['{week_start}', '{week_end}']);
162+
expect(ViewFilterRuleSchema.safeParse({ field: row.field, operator: row.operator, value: row.value }).success).toBe(true);
163+
});
164+
165+
it.each(DATE_RANGE_PRESETS)('%s sends its window from the spec table', async (preset) => {
166+
const { onChange } = renderRow({ field: 'close_date', operator: 'between', value: [] });
167+
await choose(relativeTrigger('close_date')!, EN_PRESET_LABELS[preset]);
168+
const sent = lastRow(onChange).value;
169+
expect(sent).toEqual([...DATE_RANGE_PRESET_MACRO_WINDOWS[preset]]);
170+
expect(DATE_RANGE_PRESETS as readonly string[]).not.toContain(sent[0]);
171+
});
172+
173+
it('the same on a datetime row', async () => {
174+
const { onChange } = renderRow({ field: 'created_at', operator: 'between', value: [] });
175+
await choose(relativeTrigger('created_at')!, 'Last 30 days');
176+
expect(lastRow(onChange).value).toEqual(['{30_days_ago}', '{today}']);
177+
});
178+
179+
it('a chosen preset hides the two date inputs; Custom… brings them back empty', async () => {
180+
const { onChange, rerender } = renderRow({ field: 'close_date', operator: 'between', value: [] });
181+
expect(screen.getByLabelText('From')).toBeInTheDocument();
182+
await choose(relativeTrigger('close_date')!, 'This month');
183+
const chosen = lastRow(onChange);
184+
rerender(
185+
<FilterBuilder fields={FIELDS as any} value={{ id: 'root', logic: 'and', conditions: [chosen] } as any} onChange={onChange} />,
186+
);
187+
expect(screen.queryByLabelText('From')).toBeNull();
188+
expect(relativeTrigger('close_date')).toHaveTextContent('This month');
189+
190+
await choose(relativeTrigger('close_date')!, 'Custom…');
191+
expect(lastRow(onChange).value).toEqual([]);
192+
});
193+
194+
it('Custom… keeps the two date inputs and they still write dates', () => {
195+
const { onChange } = renderRow({ field: 'close_date', operator: 'between', value: [] });
196+
expect(relativeTrigger('close_date')).toHaveTextContent('Custom…');
197+
fireEvent.change(screen.getByLabelText('From'), { target: { value: '2026-11-01' } });
198+
expect(lastRow(onChange).value).toEqual(['2026-11-01', '']);
199+
});
200+
});
201+
202+
describe('before / after offer today, yesterday and tomorrow', () => {
203+
it('lists the three points, then Custom…', async () => {
204+
renderRow({ field: 'close_date', operator: 'before', value: '' });
205+
const options = await openOptions(relativeTrigger('close_date')!);
206+
expect(options.map((o) => o.textContent)).toEqual(['Today', 'Yesterday', 'Tomorrow', 'Custom…']);
207+
});
208+
209+
it('Today on before sends the wrapped token', async () => {
210+
const { onChange } = renderRow({ field: 'close_date', operator: 'before', value: '' });
211+
await choose(relativeTrigger('close_date')!, 'Today');
212+
expect(lastRow(onChange).value).toBe('{today}');
213+
});
214+
215+
it('Tomorrow on after, on a datetime row', async () => {
216+
const { onChange } = renderRow({ field: 'created_at', operator: 'after', value: '' });
217+
await choose(relativeTrigger('created_at')!, 'Tomorrow');
218+
expect(lastRow(onChange).value).toBe('{tomorrow}');
219+
});
220+
221+
it('a stored point shows its label and no date input', () => {
222+
renderRow({ field: 'close_date', operator: 'before', value: '{yesterday}' });
223+
expect(relativeTrigger('close_date')).toHaveTextContent('Yesterday');
224+
expect(screen.queryByPlaceholderText('Value')).toBeNull();
225+
});
226+
227+
it('a stored fixed date stays Custom… with its date input', () => {
228+
renderRow({ field: 'close_date', operator: 'before', value: '2026-11-02' });
229+
expect(relativeTrigger('close_date')).toHaveTextContent('Custom…');
230+
expect(screen.getByPlaceholderText('Value')).toHaveValue('2026-11-02');
231+
});
232+
});
233+
234+
describe('a stored value reads back', () => {
235+
it('the current_ alias pair shows This week and is not rewritten', () => {
236+
const { onChange } = renderRow({
237+
field: 'close_date',
238+
operator: 'between',
239+
value: ['{current_week_start}', '{current_week_end}'],
240+
});
241+
expect(relativeTrigger('close_date')).toHaveTextContent('This week');
242+
expect(onChange).not.toHaveBeenCalled();
243+
});
244+
245+
it('a pair no preset matches is shown as text, kept, and still sent', async () => {
246+
const { onChange } = renderRow({
247+
field: 'close_date',
248+
operator: 'between',
249+
value: ['{7_days_ago}', '{tomorrow}'],
250+
});
251+
expect(relativeTrigger('close_date')).toHaveTextContent('{7_days_ago} – {tomorrow}');
252+
expect(screen.queryByLabelText('From')).toBeNull();
253+
expect(onChange).not.toHaveBeenCalled();
254+
// Still part of the group: the next edit re-emits the row unchanged.
255+
fireEvent.click(screen.getByText('Add filter'));
256+
expect(onChange.mock.calls.at(-1)![0].conditions[0].value).toEqual(['{7_days_ago}', '{tomorrow}']);
257+
});
258+
259+
it('shows the zh label for a stored week window', async () => {
260+
renderRow({ field: 'close_date', operator: 'between', value: ['{week_start}', '{week_end}'] }, (node) => (
261+
<I18nProvider config={{ defaultLanguage: 'zh', detectBrowserLanguage: false }} persistLanguage={false}>
262+
{node}
263+
</I18nProvider>
264+
));
265+
await waitFor(() => expect(relativeTrigger('close_date')).toHaveTextContent('本周'));
266+
});
267+
});
268+
269+
describe('operator and field switches', () => {
270+
it('before -> after keeps the point', async () => {
271+
const { onChange } = renderRow({ field: 'close_date', operator: 'before', value: '{today}' });
272+
await pickOperator('After');
273+
expect(lastRow(onChange)).toMatchObject({ operator: 'after', value: '{today}' });
274+
});
275+
276+
it('before -> between starts the range empty instead of carrying half a window', async () => {
277+
const { onChange } = renderRow({ field: 'close_date', operator: 'before', value: '{today}' });
278+
await pickOperator('Between');
279+
expect(lastRow(onChange)).toMatchObject({ operator: 'between', value: [] });
280+
});
281+
282+
it('a window -> equals starts empty instead of a token the date input cannot show', async () => {
283+
const { onChange } = renderRow({ field: 'close_date', operator: 'between', value: ['{week_start}', '{week_end}'] });
284+
await pickOperator('Equals');
285+
expect(lastRow(onChange)).toMatchObject({ operator: 'equals', value: '' });
286+
});
287+
288+
it('a field switch between two date columns keeps the window', async () => {
289+
const { onChange } = renderRow({ field: 'close_date', operator: 'between', value: ['{week_start}', '{week_end}'] });
290+
await pickField('Due date');
291+
expect(lastRow(onChange)).toMatchObject({ field: 'due_date', value: ['{week_start}', '{week_end}'] });
292+
});
293+
});
294+
295+
describe('CONTROL: rows without relative dates are unchanged', () => {
296+
it('equals on a date row has no relative choice', () => {
297+
renderRow({ field: 'close_date', operator: 'equals', value: '' });
298+
expect(relativeTrigger('close_date')).toBeNull();
299+
});
300+
301+
it('text and number rows have no relative choice', () => {
302+
renderRow({ field: 'name', operator: 'equals', value: 'acme' });
303+
expect(relativeTrigger('name')).toBeNull();
304+
cleanup();
305+
renderRow({ field: 'amount', operator: 'equals', value: 5 });
306+
expect(relativeTrigger('amount')).toBeNull();
307+
});
308+
309+
it('every label key is present in all ten packs', () => {
310+
const keys = [
311+
'dashboard.filters.custom',
312+
'fields.datePicker.tomorrow',
313+
...DATE_RANGE_PRESETS.map((p) => `dashboard.filters.range.${p}`),
314+
];
315+
const read = (node: unknown, path: string) =>
316+
path.split('.').reduce<unknown>((acc, seg) => (acc && typeof acc === 'object' ? (acc as any)[seg] : undefined), node);
317+
const missing = Object.entries(builtInLocales).flatMap(([code, pack]) =>
318+
keys.filter((key) => typeof read(pack, key) !== 'string').map((key) => `${code}:${key}`),
319+
);
320+
expect(missing).toEqual([]);
321+
});
322+
});

0 commit comments

Comments
 (0)