fix(OneDataCollection): reset Sort by and Group by on "Reset to default"#3973
fix(OneDataCollection): reset Sort by and Group by on "Reset to default"#3973miriam-mr90 wants to merge 4 commits intomainfrom
Conversation
✅ No New Circular DependenciesNo new circular dependencies detected. Current count: 0 |
There was a problem hiding this comment.
Pull request overview
Fixes the “Reset to default” behavior in OneDataCollection Settings popover so it also resets Sort by and Group by back to the consumer-declared defaults.
Changes:
- Capture initial grouping state (similar to existing default sortings capture) and pass both defaults down to
<Settings />. - Extend
Settingsreset handler to reset sortings and grouping in addition to per-visualization settings. - Add a regression test covering “change sort + grouping → reset → restores defaults”.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
packages/react/src/patterns/OneDataCollection/OneDatacollection.tsx |
Captures initial grouping via useRef and passes default sort/group values to Settings. |
packages/react/src/patterns/OneDataCollection/Settings/Settings.tsx |
Adds defaultSortings/defaultGrouping props and resets sortings/grouping in onResetSettings. |
packages/react/src/patterns/OneDataCollection/__tests__/index.spec.tsx |
Adds a test asserting reset restores default sortings and grouping. |
🔍 Visual review for your branch is published 🔍Here are the links to: |
Coverage Report for packages/react
File Coverage
|
||||||||||||||||||||||||||||||||||||||||||||||||||
📦 Alpha Package Version PublishedUse Use |
1d8a42d to
366fc61
Compare
| const defaultSortings = useRef(currentSortings) | ||
| const defaultGrouping = useRef(currentGrouping) |
There was a problem hiding this comment.
defaultSortings / defaultGrouping are captured from currentSortings / currentGrouping on first render. If a consumer provides a controlled currentSortings/currentGrouping that differs from the declared defaults (or if storage/initialization sets a non-default state before first render), clicking “Reset to default” will reset back to that initial current state rather than the consumer’s defaultSortings/defaultGrouping.
Consider sourcing these values from the data source defaults (e.g. source.defaultSortings / source.defaultGrouping) or explicitly passing the declared defaults into OneDataCollection/Settings, falling back to the initial current state only when defaults are not available.
| const defaultSortings = useRef(currentSortings) | |
| const defaultGrouping = useRef(currentGrouping) | |
| const defaultSortings = useRef(source.defaultSortings ?? currentSortings) | |
| const defaultGrouping = useRef(source.defaultGrouping ?? currentGrouping) |
There was a problem hiding this comment.
Addressed in f24a67c (hook change) and d5ae851 (consumer fix).
Valid concern: captured-current-state approach was wrong under controlled mode / persisted UI state. Note though that the literal suggestion (source.defaultSortings ?? currentSortings) type-checks but wouldn't work at runtime — useDataSource destructured defaultSortings / defaultGrouping out of the input and never re-emitted them in the return object, so source.defaultSortings was undefined at runtime despite being declared on the DataSource type.
Proper fix:
- f24a67c (
useDataSource.ts): adddefaultSortingsanddefaultGrouping: externalDefaultGrouping ?? defaultGroupingto the returned object — makes runtime match the type. - d5ae851 (
OneDatacollection.tsx):useRef(source.defaultSortings ?? currentSortings)and same for grouping — falls back to captured state only when no declared default exists.
Added a controlled-mode regression test in Settings.test.tsx that mounts with currentSortings different from defaultSortings and asserts Reset lands on the declared default.
| test("Reset to default restores defaultSortings and defaultGrouping", async () => { | ||
| type Person = { | ||
| id: number | ||
| name: string | ||
| department: string | ||
| } |
There was a problem hiding this comment.
This new test is being added to index.spec.tsx, but the repo convention in packages/react/AGENTS.md is “Test files: .test.tsx / .test.ts — never .spec.ts” (AGENTS.md:142-145). Please move/rename this test into a .test.tsx file (e.g. rename this file to index.test.tsx or extract this case into a new .test.tsx), to keep tooling/CI conventions consistent.
There was a problem hiding this comment.
Addressed in d5ae851. Moved the new test into a dedicated __tests__/Settings.test.tsx per the convention in AGENTS.md:144. Left the legacy index.spec.tsx filename as-is (renaming it would be out of scope and inflate the diff with churn for unrelated tests).
🚪 Why?
The "Reset to default" button in the
OneDataCollectionSettings popover is broken: it does not reset Sort by or Group by, even though both controls live inside the same popover and the button label promises a full reset.Expected behaviour
Clicking Reset to default restores every setting in the popover to the state the consumer declared as default:
defaultSortings(or cleared if none).defaultGrouping(or cleared if none / mandatory default).Current (broken) behaviour
Only visualization-level settings are reset. Sort and grouping are left untouched, so the user has to manually undo their changes — making the button misleading.
Root cause
Settings.tsx'sonResetSettingshandler only iterated thecollectionVisualizationsregistry and called each visualization'sresetHandler. It never invokedonSortingsChange/onGroupingChange, even though both setters were already received as props and used elsewhere in the same component. The visualization-registry abstraction has aresetHandlerslot; sort/grouping controls were added to the popover later without being wired into reset.🔑 What?
OneDatacollection.tsx: capture initial sort/grouping viauseRef(same pattern already in place fordefaultSortings) and pass them down to<Settings>.Settings.tsx: accept new optional propsdefaultSortingsanddefaultGrouping; extendonResetSettingsto additionally callonSortingsChange(defaultSortings ?? null)andonGroupingChange(defaultGrouping)after running visualization reset handlers.__tests__/index.spec.tsxcovering: change sort + grouping → click Settings → Reset → assert both snap back to defaults.No public API breakage — both new props are optional and existing visualization reset behaviour is preserved.
🏡 Context