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 filtered INDEX view not loading #7501

Merged
merged 2 commits into from
Oct 8, 2024
Merged

Conversation

charlesBochet
Copy link
Member

Context

We have recently merged a refactoring of our view module. However, one case was forgotten which is to test our dynamic filtering logic.

It is currently possible to pass unsaved filters through the URL and these filters will be applied to the currentView through QueryParamsFiltersEffect. This component was saving filters but also listening to them through useGetCurrentView hook.

How

  1. I'm removing this infinite loop by directly loading currentViewId through the right recoil atom.

Bonus: I'm also removing the unmounting logic which seems wrong to me as unsaved filters are mounted on a specific view, there is no need to remove them while switching views in my opinion.

const setUnsavedViewFilter = useSetRecoilComponentFamilyStateV2(
unsavedToUpsertViewFiltersComponentFamilyState,
{ viewId: viewIdQueryParam },
{ viewId: viewIdQueryParam ?? currentViewId },
Copy link
Member Author

Choose a reason for hiding this comment

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

also, viewIdQueryParam is not always defined. If viewId is in the URL, we use this view as our support, if not we will take the key=INDEX view

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

This pull request addresses an issue with filtered INDEX views not loading correctly in the Twenty application. The main changes focus on the QueryParamsFiltersEffect component, resolving an infinite loop problem and simplifying the component's logic.

Key points:

  • Removed dependency on useGetCurrentView hook in QueryParamsFiltersEffect.tsx
  • Directly loaded currentViewId using Recoil atom to prevent infinite loop
  • Eliminated unmounting logic for unsaved filters, deemed unnecessary
  • Simplified component logic to fix filtered INDEX view loading issues
  • Removed potential redundant state updates, improving performance

1 file(s) reviewed, 2 comment(s)
Edit PR Review Bot Settings

const setUnsavedViewFilter = useSetRecoilComponentFamilyStateV2(
unsavedToUpsertViewFiltersComponentFamilyState,
{ viewId: viewIdQueryParam },
{ viewId: viewIdQueryParam ?? currentViewId },
);

const { resetUnsavedViewStates } = useResetUnsavedViewStates();
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: resetUnsavedViewStates is imported but never used

if (isDefined(currentViewId)) {
resetUnsavedViewStates(currentViewId);
}
};
}, [
getFiltersFromQueryParams,
hasFiltersQueryParams,
resetUnsavedViewStates,
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: resetUnsavedViewStates is in the dependency array but not used in the effect

@charlesBochet charlesBochet merged commit fcd60be into main Oct 8, 2024
11 of 12 checks passed
@charlesBochet charlesBochet deleted the fix-dynamic-view-issue branch October 8, 2024 14:52
harshit078 pushed a commit to harshit078/twenty that referenced this pull request Oct 14, 2024
## Context

We have recently merged a refactoring of our view module. However, one
case was forgotten which is to test our dynamic filtering logic.

It is currently possible to pass unsaved filters through the URL and
these filters will be applied to the currentView through
`QueryParamsFiltersEffect`. This component was saving filters but also
listening to them through useGetCurrentView hook.

## How

1) I'm removing this infinite loop by directly loading currentViewId
through the right recoil atom.

Bonus: I'm also removing the unmounting logic which seems wrong to me as
unsaved filters are mounted on a specific view, there is no need to
remove them while switching views in my opinion.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants