Repository navigation
Commit 2771575
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
- .changeset
- ui/packages
- components/src
- __tests__
- custom
- fields/src/widgets/__tests__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
0 commit comments