You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 7f4970a
Browse filesBrowse the repository at this point in the historyBrowse files
fix(plugin-dashboard): a compare widget dated on a related record's field is served through the declared date dimension over that path (#36103)
<!-- claude-projects-attribution: {"github_login":"os-tesla"} -->
_Requested by **Tesla** · [project
thread](https://claude.ai/code/project/chan_01AXsQkLFKRdQCqQ3RTr6Jao?thread=cmsg_01AXsQkLFKRdQCqQ3RTr6JaoH1SLb7yGpZj1NnaFvhbT6W)_Fixes#34350
Clause-②: no
Metadata-protocol: none
## 维护者速读
-
仪表板作者:按关联记录的日期(例如客户的签约日期)做同期对比的比较型小组件,以前被数据集查询直接拒绝;现在只要数据集在那条关联路径上声明了一个日期维度,对比就能正常算出并显示。
- 属于仪表板数据集组件的同期对比,补上数据集只认已声明成员之后留下的缺口(替仪表板作者解决)。
-
出错时:没有覆盖该路径的日期维度,或有两个以上时,小组件照旧显示数据集查询的拒绝信息,不会显示猜出来的数字;拒绝信息现在会告诉作者在该关联字段上声明一个日期维度。本改动可直接撤回,撤回后回到原来的拒绝。
- 无
## What changes
Seat ruling 6911721875 on #34005 keeps the dataset door's refusal of an
undeclared member and leaves one thing open: the renderer mapping a
dotted date key to a declared dimension over that path. This PR is that
mapping, in the dashboard renderer, plus the one door refusal sentence
the mapping makes false (L1 REWORK R1). Nothing under `packages/spec`
and nothing in the door's or the executor's behaviour changes.
- `DatasetWidget` (dataset-bound widget with `compareTo`): when a closed
date window in the widget's resolved filter is keyed on a field that
cannot be a dimension name (judged by the spec's own
`SnakeCaseIdentifierSchema`, so a dotted `relationship.field`), the
widget reads the dataset definition (`GET /api/v1/meta/dataset/NAME`,
through the host's `apiFetch`, with `callerPackage` when the dashboard
has a served package, the same read the dataset chart and the report
date range make) and sends that window under the declared dimension's
name. The query waits for the read.
- `mapCompareWindowKeys` decides the rename:
- mapped: exactly one declared dimension with `type: 'date'` whose
`field` equals the key, spelled exactly;
- left as authored (so the door's existing `400 INVALID_FIELD` answers):
zero such dimensions; two or more (no guess between two declarations); a
dimension over the path without `type: 'date'`; a declared name another
window already uses or two keys would share; a failed definition read.
- A key that can be a dimension name (`close_date`) is never renamed,
and a widget with no such key reads nothing; its query is byte-identical
to before.
- `compareTo.dimension` naming the window by the path or by the declared
name is sent as the declared name, so the executor's dimension
resolution sees the same name the window carries.
- `@objectstack/service-analytics`, `compareWindowRemedy` (message text
only): the sentence for a comparison-window key that cannot be a
dimension name keeps "cannot be a dimension name (... no dot ...)" and
now names the remedy that exists, one date dimension declared over that
field (`type: 'date'`, `field` set to it, any snake_case name, the
relationship in `include`) named in `timeDimensions` (and in
`compareTo.dimension`, if set), which a dashboard compare widget does
itself. It replaces "this comparison cannot run on a dataset query
unless ... a field of the dataset's own object ...". The refusal's code,
status, member, param and when it fires are unchanged; the
identifier-key sentence and the intro are unchanged. Pins quoting it are
updated and two test titles that became false are retitled.
- `content/docs/ui/dashboards.mdx`, "The Date Key of a Compare Widget":
its paragraph said declaring a dimension over the path "does not help";
that became false with this change, so it now states the declaration
that serves the window and when the key is still refused. This file is
outside the claim's file surface and is declared here.
### Keys the mapping serves (for the compare-widget date-key save gate,
#34308)
A compare window's date key reaches the dataset query as a declared name
when either holds:
1. the key is itself a declared dimension name (unchanged; no read, no
rename); or
2. the key cannot be a dimension name and the dataset declares exactly
one dimension with `type: 'date'` and `field` equal to the key.
Every other key goes out as authored and is refused by the door. A save
gate that accepts exactly these two cases accepts exactly what the
renderer can serve.
## Tests
New pin
`ui/packages/plugin-dashboard/src/__tests__/DatasetWidget.compareWindowPathKey-34350.test.tsx`
(13 tests), against a stand-in for the door's declared-member rule:
- the dotted window served through the one declared date dimension over
the path (definition read once, as the reader, before the only query;
window moved out of `runtimeFilter`; tile renders the value);
- `compareTo.dimension` written as the path or as the declared name both
go out as the declared name;
- the refusal when no declared date dimension covers the path: key sent
as authored, `code` `INVALID_FIELD` and `status` 400, refusal shown on
the tile; the same for two covering dimensions and for a failed
definition read;
- no definition read for an own-object key or a widget without
`compareTo`;
- `mapCompareWindowKeys` unit cases for every branch above.
<details><summary>Readings (head ffebb0e)</summary>
- `vitest run` on the new pin plus `DatasetWidget.compareTo.test.tsx`
and `DashboardRenderer.compareToAllTime-25970.test.tsx`: Test Files 3
passed, Tests 52 passed, lock VERDICT command-exit 0.
- `vitest run packages/plugin-dashboard/` (whole package): Test Files
207 passed (207), Tests 2023 passed, 6 skipped, lock VERDICT
command-exit 0.
- `pnpm --filter @object-ui/plugin-dashboard run type-check` (`tsc
--noEmit && tsc -p tsconfig.test.json`): exit 0; the test project's file
list includes the new pin (1 hit).
- Ablation 1, mapping disabled (`over.length === 1` to `over.length ===
-1`, via `scripts/ablation-replace.mjs`, anchor 1 to 0, blob c40bc3e to
986c24cc): 3 failed (the unit map case, the served window, the
`compareTo.dimension` rename), 10 passed; restored, blob equals HEAD,
`git diff HEAD` empty.
- Ablation 2, ambiguity guessed (`over.length >= 1`): 2 failed (both
two-declarations cases), 11 passed; restored, blob equals HEAD.
- The test imports the widget from source, not through a package `dist`,
so no rebuild leg applies.
</details>
<details><summary>R1 readings (head 3f41ce4)</summary>
- service-analytics pins `dataset-query-declared-members.test.ts` +
`dotted-path-preview-parity.test.ts`: Test Files 2 passed (2), Tests 49
passed (49), lock VERDICT command-exit 0.
- `pnpm --filter @objectstack/service-analytics test`: Test Files 221
passed (221), Tests 5651 passed, 345 skipped; `typecheck` (`tsc
--noEmit`, both pin files in its file list) exit 0.
- plugin-dashboard compare pins again: Test Files 3 passed, Tests 52
passed.
- Ablation, the old sentence restored through
`scripts/ablation-replace.mjs` (anchor 1 to 0, blob f49134b to
8f1b94d5): 8 failed, 41 passed (both refusal pins, the five table cases
with an unnameable key, the preview-parity CONTROL); restored, blob
equals HEAD f49134b, `git diff HEAD` empty. The pins import the source
module, so no rebuild leg applies.
</details>
## Acceptance notes
- Dimensions over the path that omit `type` are not mapped: the rule
reads only what the dataset declares, as the card asks for the declared
date dimension.
- An identifier key that is a field of the base object but not a
declared dimension name (for example `close_date` under a dimension
named `closed_on`) stays as authored. That case has a declare-it remedy
at the door and is outside this card.
- The definition read is one extra request per widget only for a compare
widget whose window is keyed on a path. It is not cached across widgets;
the dataset chart and the report make the same uncached read.
- The door's refusal wording for a key no dimension can be named used to
say the comparison needs a date field of the dataset's own object; this
mapping made that false, so the sentence is corrected here (L1 REWORK
R1, claim amendment 2). The ADR-0087 markers and shipped changesets that
quote the old "no in-dataset remedy" wording are history and are not
edited.
## Verification
Read first, by risk:
1. `DatasetWidget.tsx`, the compare-window block in the component
(`pathWindowKeys`, `useCompareWindowKeyMap`, `comparedKey`, the
signature and the early return in the fetch effect): the query must not
go out while the read is pending, and must not refetch in a loop.
2. `DatasetWidget.tsx`, `mapCompareWindowKeys`: the zero / two-or-more /
collision branches.
3.
`packages/services/service-analytics/src/dataset-declared-members.ts`,
`compareWindowRemedy`: the unnameable-key sentence, singular and plural.
Two-minute check: `cd ui && pnpm exec vitest run
packages/plugin-dashboard/src/__tests__/DatasetWidget.compareWindowPathKey-34350.test.tsx`,
expect 13 passed.
---
_Generated by [Claude
Code](https://claude.ai/code/session_01L9qibxWPiQYXSf1jxGbN3W)_
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01L9qibxWPiQYXSf1jxGbN3W
<!-- signed: repo:objectstack#7 · os-tesla ·
session_01L9qibxWPiQYXSf1jxGbN3W -->
---------
Co-authored-by: Claude <noreply@anthropic.com>
fix(plugin-dashboard): a compare widget dated on a related record's field is served through the dataset's declared date dimension over that path
7
+
8
+
Clause-②: no
9
+
Metadata-protocol: none
10
+
11
+
A dataset-bound compare widget (`compareTo`) sends its date window to the dataset query under the filtered field's name. The dataset query answers only declared dimensions, and a dimension name has no dot, so a window on a related record's field, such as `account.founded_at`, was refused with `400 INVALID_FIELD`.
12
+
13
+
When such a key is in the window, the widget now reads the dataset definition and sends the window under the one declared dimension with `type: 'date'` and `field` equal to that path (for example `{ name: 'account_founded', field: 'account.founded_at', type: 'date' }`). A `compareTo.dimension` that names the window by the path or by that declared name is sent as the declared name. When no declared date dimension covers the path, or two or more do, the key is sent as authored and the dataset query still refuses it. Keys that can be dimension names, such as `close_date`, are never renamed, and widgets whose window has no such key read nothing extra.
14
+
15
+
To serve a compare widget dated on a related record's field, declare one date dimension over that path on the dataset.
16
+
17
+
The dataset query's `400 INVALID_FIELD` refusal for a comparison-window date key that cannot be a dimension name no longer says the comparison cannot run unless the date field is a field of the dataset's own object; it names the remedy that exists: declare one date dimension over that field (`type: 'date'`, `field` set to it, any snake_case name, the relationship in the dataset's `include`) and name it in `timeDimensions`, which a dashboard compare widget then does itself. The refusal's code, status and when it fires are unchanged.
Copy file name to clipboardExpand all lines: packages/services/service-analytics/src/__tests__/dataset-query-declared-members.test.ts
+20-13Lines changed: 20 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -291,9 +291,10 @@ describe('queryDataset refuses a selection member the dataset does not declare',
291
291
expect(reads).toEqual([]);
292
292
});
293
293
294
-
it('mixed comparison date keys: a related record\'s field gets the own-object requirement, a nameable key keeps its declare-it remedy',async()=>{
294
+
it('mixed comparison date keys: a related record\'s field gets the declare-over-it remedy, a nameable key keeps its declare-it remedy',async()=>{
295
295
// Seat ruling (option A): a dotted key cannot be a dimension name, so no
296
-
// sentence tells the author to declare a dimension named after it.
296
+
// sentence tells the author to declare a dimension named after it; the
297
+
// remedy is a date dimension declared over it (objectstack#34350).
297
298
const{ service, reads }=awaitboot();
298
299
conste=awaitservice
299
300
.queryDataset(
@@ -315,7 +316,9 @@ describe('queryDataset refuses a selection member the dataset does not declare',
315
316
);
316
317
expect(messageOf(e)).toContain('"account.signed_at" cannot be a dimension name');
317
318
expect(messageOf(e)).toContain(
318
-
'this comparison cannot run on a dataset query unless that date field is a field of the dataset\'s own object that a declared date dimension names.',
319
+
'so no date dimension can be declared under it. Declare one date dimension over it instead, with `type: \'date\'` and `field` set to that field, '
320
+
+'under any snake_case name (a related record\'s field needs its relationship in the dataset\'s `include`), and name that dimension in '
321
+
+'`timeDimensions` (and in `compareTo.dimension`, if set): a dashboard compare widget sends its window under that declared name itself.',
319
322
);
320
323
expect(messageOf(e)).toContain(
321
324
'For the key that can be a dimension name, declare a date dimension named "closed_on" on the dataset (over that field).',
@@ -328,11 +331,12 @@ describe('queryDataset refuses a selection member the dataset does not declare',
328
331
expect(reads).toEqual([]);
329
332
});
330
333
331
-
it('a related record\'s field as the only undeclared member: the refusal tells the author to declare nothing',async()=>{
334
+
it('a related record\'s field as the only undeclared member: the refusal names no member to declare under the key, only a date dimension over it',async()=>{
332
335
// Seat ruling (option A): the message must be true for that class. The
333
336
// select-or-declare sentence would name the dotted key, which no
334
337
// declaration can carry, so it is left out; the compare-window sentence is
335
-
// the whole remedy.
338
+
// the whole remedy, a date dimension declared over the field
339
+
// (objectstack#34350).
336
340
const{ service, reads }=awaitboot();
337
341
conste=awaitservice
338
342
.queryDataset(
@@ -351,8 +355,9 @@ describe('queryDataset refuses a selection member the dataset does not declare',
351
355
expect(messageOf(e)).not.toContain('Use one of these');
352
356
expect(messageOf(e)).toContain(
353
357
'"account.signed_at" cannot be a dimension name (a dimension name is a snake_case identifier, with no dot, so a related record\'s field is never one), '
354
-
+'so no date dimension can be declared under it: this comparison cannot run on a dataset query unless the dashboard\'s date field '
355
-
+'is a field of the dataset\'s own object that a declared date dimension names.',
358
+
+'so no date dimension can be declared under it. Declare one date dimension over it instead, with `type: \'date\'` and `field` set to that field, '
359
+
+'under any snake_case name (a related record\'s field needs its relationship in the dataset\'s `include`), and name that dimension in '
360
+
+'`timeDimensions` (and in `compareTo.dimension`, if set): a dashboard compare widget sends its window under that declared name itself.',
356
361
);
357
362
expect(reads).toEqual([]);
358
363
});
@@ -484,17 +489,19 @@ describe('the source-field gates word their remedy for the door that asked', ()
484
489
describe('compareWindowRemedy — a true sentence for every key, in every mix',()=>{
constownObject='is a field of the dataset\'s own object that a declared date dimension names.';
492
+
constinclude='under any snake_case name (a related record\'s field needs its relationship in the dataset\'s `include`)';
493
+
constoverIt=`so no date dimension can be declared under it. Declare one date dimension over it instead, with \`type: 'date'\` and \`field\` set to that field, ${include}, and name that dimension in \`timeDimensions\` (and in \`compareTo.dimension\`, if set): a dashboard compare widget sends its window under that declared name itself.`;
494
+
constoverEach=`so no date dimension can be declared under them. Declare one date dimension over each instead, with \`type: 'date'\` and \`field\` set to that field, ${include}, and name those dimensions in \`timeDimensions\` (and in \`compareTo.dimension\`, if set): a dashboard compare widget sends each window under its declared name itself.`;
488
495
489
496
// [nameable keys, unnameable keys, the sentences after the intro]
490
497
for(const[nameable,unnameable,tail]of[
491
498
[['closed_on'],[],'Declare a date dimension named "closed_on" on the dataset (over that field).'],
492
499
[['closed_on','created_at'],[],'Declare a date dimension for each on the dataset, named "closed_on" and "created_at", each over the field of the same name.'],
493
-
[[],['account.founded_at'],`"account.founded_at" cannot be a dimension name (a dimension name is a snake_case identifier, with no dot, so a related record's field is never one), so no date dimension can be declared under it: this comparison cannot run on a dataset query unless the dashboard's date field ${ownObject}`],
494
-
[[],['CloseDate'],`"CloseDate" cannot be a dimension name (a dimension name is a snake_case identifier, with no dot, so a related record's field is never one), so no date dimension can be declared under it: this comparison cannot run on a dataset query unless the dashboard's date field ${ownObject}`],
495
-
[[],['account.founded_at','owner.hired_at'],`"account.founded_at" and "owner.hired_at" cannot be dimension names (a dimension name is a snake_case identifier, with no dot, so a related record's field is never one), so no date dimension can be declared under them: this comparison cannot run on a dataset query unless each of those date fields ${ownObject}`],
496
-
[['closed_on'],['account.founded_at','owner.hired_at'],`"account.founded_at" and "owner.hired_at" cannot be dimension names (a dimension name is a snake_case identifier, with no dot, so a related record's field is never one), so no date dimension can be declared under them: this comparison cannot run on a dataset query unless each of those date fields ${ownObject} For the key that can be a dimension name, declare a date dimension named "closed_on" on the dataset (over that field).`],
497
-
[['closed_on','created_at'],['account.founded_at'],`"account.founded_at" cannot be a dimension name (a dimension name is a snake_case identifier, with no dot, so a related record's field is never one), so no date dimension can be declared under it: this comparison cannot run on a dataset query unless that date field ${ownObject} For the keys that can be dimension names, declare a date dimension for each on the dataset, named "closed_on" and "created_at", each over the field of the same name.`],
500
+
[[],['account.founded_at'],`"account.founded_at" cannot be a dimension name (a dimension name is a snake_case identifier, with no dot, so a related record's field is never one), ${overIt}`],
501
+
[[],['CloseDate'],`"CloseDate" cannot be a dimension name (a dimension name is a snake_case identifier, with no dot, so a related record's field is never one), ${overIt}`],
502
+
[[],['account.founded_at','owner.hired_at'],`"account.founded_at" and "owner.hired_at" cannot be dimension names (a dimension name is a snake_case identifier, with no dot, so a related record's field is never one), ${overEach}`],
503
+
[['closed_on'],['account.founded_at','owner.hired_at'],`"account.founded_at" and "owner.hired_at" cannot be dimension names (a dimension name is a snake_case identifier, with no dot, so a related record's field is never one), ${overEach} For the key that can be a dimension name, declare a date dimension named "closed_on" on the dataset (over that field).`],
504
+
[['closed_on','created_at'],['account.founded_at'],`"account.founded_at" cannot be a dimension name (a dimension name is a snake_case identifier, with no dot, so a related record's field is never one), ${overIt} For the keys that can be dimension names, declare a date dimension for each on the dataset, named "closed_on" and "created_at", each over the field of the same name.`],
Copy file name to clipboardExpand all lines: packages/services/service-analytics/src/__tests__/dotted-path-preview-parity.test.ts
+8-5Lines changed: 8 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -240,11 +240,12 @@ describe('[#28555–#28558] members read through a relationship path, on the nat
240
240
);
241
241
});
242
242
243
-
it('CONTROL, in place of the served windowed key: a compare window over the backed \'account.founded_at\' is refused on every face, naming no declare-it remedy',async()=>{
243
+
it('CONTROL, in place of the served windowed key: a compare window over the backed \'account.founded_at\' is refused on every face, naming a date dimension over it, never one named after it',async()=>{
244
244
// A dashboard compare widget lowers a dotted date filter into this very
245
-
// key. No dimension can be named `account.founded_at` (the dimension
246
-
// name grammar has no dot), so the refusal states what the comparison
247
-
// needs instead: a date field of the dataset's own object.
245
+
// key when the dataset declares no date dimension over it. No dimension
246
+
// can be named `account.founded_at` (the dimension name grammar has no
247
+
// dot), so the refusal names the remedy that exists: a date dimension
248
+
// declared over the field, under another name (objectstack#34350).
248
249
consterr=awaitundeclaredAlike(
249
250
BACKED,
250
251
{
@@ -261,7 +262,9 @@ describe('[#28555–#28558] members read through a relationship path, on the nat
261
262
expect(err.message).not.toContain('declare the member on the dataset');
262
263
expect(err.message).toContain('"account.founded_at" cannot be a dimension name');
263
264
expect(err.message).toContain(
264
-
'this comparison cannot run on a dataset query unless the dashboard\'s date field is a field of the dataset\'s own object that a declared date dimension names.',
265
+
'so no date dimension can be declared under it. Declare one date dimension over it instead, with `type: \'date\'` and `field` set to that field, '
266
+
+'under any snake_case name (a related record\'s field needs its relationship in the dataset\'s `include`), and name that dimension in '
267
+
+'`timeDimensions` (and in `compareTo.dimension`, if set): a dashboard compare widget sends its window under that declared name itself.',
0 commit comments