fix(core): 未知的 date filter 值改为跳过并警告,不再降级成永不命中的等值 (#3151) - #3196
Merged
Conversation
A `date`/`dateRange` dashboard filter value that is neither a known preset
name nor a parseable date fell through to the "a bare string date means
equality on that day" branch, so a misspelled default ('last_7_dayz')
reached the query as `WHERE created_at = 'last_7_dayz'` — 200 OK, widget
renders, count 0, indistinguishable from a range with no data.
`buildFilterCondition` now accepts exactly three spellings for a date value:
a known preset (→ range bounds), an ISO date or date-macro token (→ equality
on that day), and nothing else — an unrecognised value is skipped with a
console.warn naming the filter, the value and the accepted spellings. The
`{ preset: '<unknown>' }` object form already dropped the filter silently;
that drop is now announced too.
This is the same strictness `buildWidgetScopedFilter` already applies to a
default binding on a field the object lacks: never emit a query the backend
can only empty-match. The macro-token check asks `resolveDateMacros` itself
rather than restating its grammar, so there is no second token dialect.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PRJtkgUAaVG11FsJQbvZWA
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
…ellings The guide never documented what a `date` filter's `defaultValue` may be — which is how a misspelled preset reached a query in the first place. Now lists the three accepted spellings (preset name / ISO date / date macro) and says plainly that anything else is skipped with a warning, and why it is not compared as-is. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PRJtkgUAaVG11FsJQbvZWA
Contributor
✅ Console Performance Budget
📦 Bundle Size Report
Size Limits
|
1 similar comment
Contributor
✅ Console Performance Budget
📦 Bundle Size Report
Size Limits
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3151
问题
date/dateRange型 dashboard filter 拿到一个既不是已知预设名、也不是可解析日期的字符串时,会掉进buildFilterCondition的「裸字符串 = 当天等值」分支。于是一个拼错的默认值defaultValue: 'last_7_dayz'原样成为比较值,widget 发出runtimeFilter: { created_at: 'last_7_dayz' },后端如实编译成WHERE created_at = $1——200 OK、widget 正常渲染、数字是 0,和「这个区间确实没有数据」完全无法区分。这是 objectstack#4475(已由 objectui#3150 修掉预设名那一半)旁边更隐蔽的姐妹情形:0 看起来像一个合法答案,没有 4xx、没有警告、没有任何 UI 信号。改动
buildFilterCondition现在只认三种日期值写法,按分诊裁决实现期望第 3 条(跳过 + console.warn 点名 filter 与那个值):2026-01-15、2026-01-15T08:30:00Z)或日期宏 token({today}、{7_days_ago})→ 当天等值(现有文档化行为,不变);{ preset: 某个未知预设 }这种对象形式一并补上警告:它原先就会丢弃该 filter,但是静默丢弃;现在这次丢弃会被说出来。如果对象里同时带了显式from/to,边界仍然生效,警告会说明是哪一边胜出。第 3 条刻意与
buildWidgetScopedFilter对未知字段名的默认绑定采用同一种严格度(跳过 + 警告),理由也是它自己写下的那一条:不要发一个后端只会空匹配或直接拒绝的查询。字段名早就有这道闸,字段值一直没有。日期宏 token 的识别直接问
resolveDateMacros本人(「它认不认这个字符串」),而不是在这里把 token 语法再抄一遍 —— 一套词汇表,不产生会漂移的第二种方言;而它认不出来的 token({last_7_dayz})恰好就是这道闸要抓的拼写错误。顺带一个自洽:未知值被跳过后,
DateRangeFilter显示的 "All time" 与实际发出的查询终于一致(#4475 里两者是矛盾的 —— 控件说 All time,查询却发了一个永不命中的等值)。测试
packages/core/src/utils/__tests__/dashboard-filters.test.ts新增[#3151] unrecognised date values一组(8 例):拼错的预设字符串被跳过并警告(断言警告文本含 filter 名与该值)、合法 ISO 日期仍为等值且不警告、日期宏 token 仍为等值且不警告、只是「长得像」日期/宏的字符串({last_7_dayz}/15/01/2026/2026-13-45)被拒、合法预设名仍产生区间且不警告(#3150 回归)、未知对象预设被跳过并警告、未知预设 + 显式边界时保留边界并说明,以及端到端经buildWidgetScopedFilter确认没有runtimeFilter到达 widget 查询。范围
.changeset/dashboard-date-filter-unknown-value.md(@object-ui/core: minor,与 fix(dashboard): date 型 globalFilter 的预设名默认值应提升为区间 (objectstack#4475) #3150 同级 —— 发出的查询形状变了)。content/docs/guide/dashboard-filters.md补上datefilter 的defaultValue到底能写什么 —— 三种拼法 + 其余一律跳过并警告。此前这份指南根本没写过defaultValue,拼错的预设能一路走到查询,也有这一半原因。GlobalFilterSchema.defaultValue)」属于 objectstack 侧的作者时收紧,按分诊裁决另行立项,不在本 PR 扩大范围。本次实现确认它确有价值(运行时跳过 + 警告是放宽方向,只有作者时拒绝才能在发布前挡住),已按越界发现另立 unassigned issue:spec: dashboard date filter 的 defaultValue 没有作者时校验 —— 拼错的预设名要到浏览器控制台才被发现 objectstack#4614(A/B/C 三个选项 + 倾向 A,交维护者定夺)。🤖 Generated with Claude Code
https://claude.ai/code/session_01PRJtkgUAaVG11FsJQbvZWA