-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Implemented view filter group CRUD hooks and utils #10551
Conversation
…ups and its unit test - ViewBar CRUD buttons are now taking view filter groups into account - Implemented getViewFilterGroupsToCreate and its unit test - Implemented getViewFilterGroupsToDelete and its unit test - Implemented getViewFilterGroupsToUpdate and its unit test - Implemented compareStrictlyExceptForNullAndUndefined and its unit test - Refactored nullish comparisons with compareStrictlyExceptForNullAndUndefined
.getValue(); | ||
|
||
if (isDefined(currentView)) { | ||
setCurrentRecordFilterGroups( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to avoid re-render, I would encourage to check (by deepEqual) if new != old
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll implement it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Summary
Implemented view filter group CRUD hooks and utilities for managing filter groups in the Twenty application.
- Added
useAreViewFilterGroupsDifferentFromRecordFilterGroups
hook in/packages/twenty-front/src/modules/views/hooks/useAreViewFilterGroupsDifferentFromRecordFilterGroups.ts
to detect differences between view filter groups and record filter groups - Created utility functions
getViewFilterGroupsToCreate
,getViewFilterGroupsToDelete
, andgetViewFilterGroupsToUpdate
to handle CRUD operations for filter groups - Implemented
compareStrictlyExceptForNullAndUndefined
utility in/packages/twenty-front/src/utils/compareStrictlyExceptForNullAndUndefined.ts
to safely compare values that might be null or undefined - Added
useApplyCurrentViewFilterGroupsToCurrentRecordFilterGroups
hook to synchronize view filter groups with record filter groups - Integrated filter group comparison in
ViewBarDetails
andUpdateViewButtonGroup
components to properly handle unsaved changes
13 file(s) reviewed, 2 comment(s)
Edit PR Review Bot Settings | Greptile
if (!isDefined(currentView)) { | ||
return undefined; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Consider returning false
instead of undefined
when currentView is not defined. This would make the return type consistent (boolean) and avoid potential issues with boolean checks elsewhere in the codebase.
const shouldUpdateBecauseViewFilterIsDifferent = !areViewFilterGroupsEqual( | ||
newViewFilterGroup, | ||
correspondingViewFilterGroup, | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: The variable name suggests this is checking if a filter is different, but it's actually checking if a filter group is different.
currentRecordFilterGroupsComponentState, | ||
); | ||
|
||
const viewFilterGroupsAreDifferentFromRecordFilterGroups = useMemo(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this useMemo useful?
This hook is taking dependecy on currentView (prefetchViewFromViewIdFamilySelector behind the scene) + currentRecordFilterGroups which seems to be perfect
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can remove it yes
This PR implements hooks and utils logic for handling CRUD and view filter group comparison.
The main hook is useAreViewFilterGroupsDifferentFromRecordFilterGroups, like view filters and view sorts.
Inside this hook we implement getViewFilterGroupsToCreate, getViewFilterGroupsToDelete and getViewFilterGroupsToUpdate.
All of those come with their unit tests.
In this PR we also introduce a new util to prevent nasty bugs happening when we compare undefined === null,
This util is called compareStrictlyExceptForNullAndUndefined and it should replace every strict equality comparison between values that can be null or undefined (which we have a lot)
This could be enforced by a custom ESLint rule, the autofix may also be implemented (maybe the util should be put in twenty-shared ?)