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

Implemented view filter group CRUD hooks and utils #10551

Merged
merged 4 commits into from
Feb 28, 2025

Conversation

lucasbordeau
Copy link
Contributor

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

…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
@lucasbordeau lucasbordeau enabled auto-merge (squash) February 27, 2025 14:44
.getValue();

if (isDefined(currentView)) {
setCurrentRecordFilterGroups(
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll implement it

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

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, and getViewFilterGroupsToUpdate 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 and UpdateViewButtonGroup components to properly handle unsaved changes

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

Comment on lines 19 to 21
if (!isDefined(currentView)) {
return undefined;
}
Copy link
Contributor

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.

Comment on lines 23 to 26
const shouldUpdateBecauseViewFilterIsDifferent = !areViewFilterGroupsEqual(
newViewFilterGroup,
correspondingViewFilterGroup,
);
Copy link
Contributor

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(() => {
Copy link
Member

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

Copy link
Contributor Author

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

@charlesBochet charlesBochet merged commit ea1ac37 into main Feb 28, 2025
50 checks passed
@charlesBochet charlesBochet deleted the refactor/record-filter-group-crud-utils branch February 28, 2025 12:32
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.

2 participants