Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: reset table selection when navigating away from index page #9140

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

samyakpiya
Copy link
Contributor

Fixes #9132

Purpose

Currently, when navigating away from an index page and returning, previously checked selections remain checked. This fix ensures the selection context is properly reset on navigation.

Changes

  • Add RecordIndexResetSelectionEffect component to handle selection cleanup
  • Integrate effect into RecordIndexPage
  • Uses existing useResetTableRowSelection hook to clear selections

Testing

  1. Go to any index page (e.g., Companies)
  2. Select some records using checkboxes
  3. Navigate to a detail page
  4. Return to the index page
  5. Verify that no records are selected

Demo

I've recorded a short video demonstrating how this PR fixes the issue:

Loom Video Link

Before fix: Selections persist after navigation
After fix: Selections are properly reset

- Add RecordIndexResetSelectionEffect component to handle selection cleanup
- Integrate effect into RecordIndexPage
- Ensures checkbox selections are cleared when navigating away
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

Adds a new cleanup effect component to reset table row selections when navigating away from index pages, fixing the issue of persisting selections between page navigations.

  • Added new packages/twenty-front/src/modules/object-record/record-index/components/RecordIndexResetSelectionEffect.tsx to handle selection cleanup on unmount
  • Integrated RecordIndexResetSelectionEffect into RecordIndexPage.tsx within the component hierarchy
  • Uses useResetTableRowSelection hook to clear row selections and close action menu dropdown
  • Leverages React's useEffect cleanup function for proper selection state management

💡 (1/5) You can manually trigger the bot by mentioning @greptileai in a comment!

2 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings | Greptile

Copy link
Member

@charlesBochet charlesBochet left a comment

Choose a reason for hiding this comment

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

LGTM, thank you :)

@charlesBochet
Copy link
Member

@samyakpiya I have approved first but we actually would like to test a different pattern. We are trying to get rid of the useEffects completely on the codebase

The right way to do that is to let the caller synchronously reset the table selection. But how could the link in RecordDetailSectionHeader know that it should reset the table selection: let's introduce a component that will include a <Link to={...} onClick{resetTableSelection} />

Copy link
Member

@charlesBochet charlesBochet left a comment

Choose a reason for hiding this comment

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

see comment above

@samyakpiya
Copy link
Contributor Author

@charlesBochet Thanks for the feedback! I understand we want to move away from useEffect and handle the selection reset synchronously through the Link component's onClick. I'll update the PR to implement this pattern instead.

@samyakpiya
Copy link
Contributor Author

@charlesBochet I've considered the pattern you suggested but have some technical concerns to discuss.

The current suggestion to handle reset via <Link onClick={resetTableSelection}> would only cover the show page → index page navigation path. However, shouldn't the table selection reset whenever we leave the index page, regardless of destination? For instance:

  1. Workspace switches
  2. Direct URL changes (browser back/forward)
  3. Navigation to any other route
  4. External links

Additionally, implementing this through Links would require lifting state management up the component tree to make the reset function available to both index and show pages.

Would it make more sense to handle this at the routing/navigation level instead? This would ensure consistent behavior regardless of how the user leaves the index page. I'm happy to explore alternative patterns that don't use useEffect while still covering all these edge cases.

@lucasbordeau
Copy link
Contributor

@samyakpiya Let's implement an isLeavingIndexPage in PageChangeEffect, we'll refactor when we refactor PageChangeEffect.

@lucasbordeau lucasbordeau self-assigned this Dec 27, 2024
@samyakpiya
Copy link
Contributor Author

Sounds good, thanks!

samyakpiya and others added 2 commits January 7, 2025 23:27
- Add reset table selection functionality when navigating away from record index pages
- Add useParams hook to get objectNamePlural parameter
- Integrate useResetTableRowSelection hook with default to Person object
@@ -38,6 +45,11 @@ export const PageChangeEffect = () => {

const eventTracker = useEventTracker();

const objectNamePlural =
Copy link
Contributor Author

@samyakpiya samyakpiya Jan 8, 2025

Choose a reason for hiding this comment

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

@lucasbordeau useResetTableRowSelection(objectNamePlural) seems to throw whenever objectNamePlural is an empty string because of this.

But if we're setting the reset logic in this PageChangeEffect, since hooks can't be called conditionally, every time the code reaches this point:

const resetTableSelections = useResetTableRowSelection(objectNamePlural);

and the user is not currently in the RecordIndexPage, this is bound to throw. I've currently used CoreObjectNamePlural.Person as a workaround, but don't think this is the right way to do it. How would you handle it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reset Context Selection When Navigating Between Indexes
3 participants