Skip to content

fix(OneDataCollection): reset Sort by and Group by on "Reset to default"#3973

Draft
miriam-mr90 wants to merge 4 commits intomainfrom
fix/data-collection-reset-to-default
Draft

fix(OneDataCollection): reset Sort by and Group by on "Reset to default"#3973
miriam-mr90 wants to merge 4 commits intomainfrom
fix/data-collection-reset-to-default

Conversation

@miriam-mr90
Copy link
Copy Markdown
Contributor

🚪 Why?

The "Reset to default" button in the OneDataCollection Settings 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:

  • Visualization-level settings (e.g. table column visibility/order) — already worked.
  • Sort by → returns to defaultSortings (or cleared if none).
  • Group by → returns to 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's onResetSettings handler only iterated the collectionVisualizations registry and called each visualization's resetHandler. It never invoked onSortingsChange / onGroupingChange, even though both setters were already received as props and used elsewhere in the same component. The visualization-registry abstraction has a resetHandler slot; sort/grouping controls were added to the popover later without being wired into reset.

🔑 What?

  • OneDatacollection.tsx: capture initial sort/grouping via useRef (same pattern already in place for defaultSortings) and pass them down to <Settings>.
  • Settings.tsx: accept new optional props defaultSortings and defaultGrouping; extend onResetSettings to additionally call onSortingsChange(defaultSortings ?? null) and onGroupingChange(defaultGrouping) after running visualization reset handlers.
  • Added test in __tests__/index.spec.tsx covering: 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

Copilot AI review requested due to automatic review settings April 20, 2026 12:42
@github-actions github-actions Bot added fix react Changes affect packages/react labels Apr 20, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 20, 2026

✅ No New Circular Dependencies

No new circular dependencies detected. Current count: 0

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Settings reset 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.

Comment thread packages/react/src/patterns/OneDataCollection/__tests__/index.spec.tsx Outdated
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 20, 2026

🔍 Visual review for your branch is published 🔍

Here are the links to:

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 20, 2026

Coverage Report for packages/react

Status Category Percentage Covered / Total
🔵 Lines 47.49% 12380 / 26065
🔵 Statements 46.69% 12779 / 27365
🔵 Functions 38.61% 2745 / 7108
🔵 Branches 39.21% 8235 / 20999
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
packages/react/src/hooks/datasource/useDataSource.ts 86.04% 69.44% 84.61% 84.21% 51, 119-125, 131, 201-203
packages/react/src/patterns/OneDataCollection/OneDatacollection.tsx 69.78% 45.6% 70.27% 69.11% 240-244, 325, 376-392, 401-409, 424-427, 444, 469-478, 485-491, 509-515, 547-550, 696, 703, 777-879
packages/react/src/patterns/OneDataCollection/Settings/Settings.tsx 87.5% 82.14% 81.81% 90.32% 105-106, 112, 142
Generated in workflow #12991 for commit d5ae851 by the Vitest Coverage Report Action

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 20, 2026

📦 Alpha Package Version Published

Use pnpm i github:factorialco/f0#npm/alpha-pr-3973 to install the package

Use pnpm i github:factorialco/f0#ee5f8b98556ea5ca3b812808d035e28d8bb5b005 to install this specific commit

@miriam-mr90 miriam-mr90 force-pushed the fix/data-collection-reset-to-default branch from 1d8a42d to 366fc61 Compare April 20, 2026 15:35
Copilot AI review requested due to automatic review settings April 20, 2026 15:35
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Comment on lines +252 to +253
const defaultSortings = useRef(currentSortings)
const defaultGrouping = useRef(currentGrouping)
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
const defaultSortings = useRef(currentSortings)
const defaultGrouping = useRef(currentGrouping)
const defaultSortings = useRef(source.defaultSortings ?? currentSortings)
const defaultGrouping = useRef(source.defaultGrouping ?? currentGrouping)

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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): add defaultSortings and defaultGrouping: externalDefaultGrouping ?? defaultGrouping to 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.

Comment on lines +1287 to +1292
test("Reset to default restores defaultSortings and defaultGrouping", async () => {
type Person = {
id: number
name: string
department: string
}
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot generated this review using guidance from repository custom instructions.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

@miriam-mr90 miriam-mr90 self-assigned this Apr 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix react Changes affect packages/react

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants