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

Remove filter definition #10227

Merged
merged 4 commits into from
Feb 14, 2025
Merged

Conversation

lucasbordeau
Copy link
Contributor

This PR removes completely filter definition usage and states, everything is now derived from fieldMetadataItem.

@bosiraphael bosiraphael self-requested a review February 14, 2025 16:37
Copy link
Contributor

@bosiraphael bosiraphael left a comment

Choose a reason for hiding this comment

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

LGTM

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 PR significantly refactors the filtering system by removing filter definitions and deriving filter behavior directly from field metadata items. Here's a concise summary of the key changes:

  • Removes all filter definition states and utilities, transitioning to direct usage of fieldMetadataItem properties
  • Replaces formatFieldMetadataItemAsFilterDefinition with direct usage of getFilterTypeFromFieldType
  • Modifies RecordFilter type to include required 'type' and 'label' fields instead of optional 'definition'
  • Updates filter-related components to derive filter information directly from field metadata
  • Simplifies data flow by removing intermediate filter definition transformation layer

Key points to review:

  • Check error handling for missing field metadata items, particularly in mapViewFiltersToFilters.ts
  • Verify filter behavior consistency across all field types (TEXT, NUMBER, DATE, etc.)
  • Review the fieldId state variable marked as TODO in ObjectFilterDropdownSourceSelect
  • Consider impact on type safety with removal of filter definition layer
  • Test backward compatibility with existing filters and views

50 file(s) reviewed, 16 comment(s)
Edit PR Review Bot Settings | Greptile

Comment on lines 85 to 87
const filterType = getFilterTypeFromFieldType(
defaultFieldMetadataItem.type,
);
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 adding error handling for unsupported field types in getFilterTypeFromFieldType

Comment on lines +92 to +93
type: getFilterTypeFromFieldType(fieldMetadataItemUsedInDropdown.type),
label: fieldMetadataItemUsedInDropdown.label,
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Duplicate code from lines 63-64. Consider extracting type and label into variables to avoid repetition

const filterDefinition = formatFieldMetadataItemAsFilterDefinition({
field: fieldMetadataItemUsedInDropdown,
});

applyRecordFilter({
id: selectedFilter?.id ? selectedFilter.id : v4(),
fieldMetadataId: fieldMetadataItemUsedInDropdown?.id ?? '',
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Optional chaining with nullish coalescing here could be simplified to just fieldMetadataItemUsedInDropdown.id since line 45 ensures it exists

Suggested change
fieldMetadataId: fieldMetadataItemUsedInDropdown?.id ?? '',
fieldMetadataId: fieldMetadataItemUsedInDropdown.id,

@@ -28,13 +21,8 @@ export const SingleEntityObjectFilterDropdownButtonEffect = () => {

const firstFieldMetadataItem = filterableFieldMetadataItems[0];
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: No null check on filterableFieldMetadataItems[0]. Could cause runtime errors if array is empty.

Suggested change
const firstFieldMetadataItem = filterableFieldMetadataItems[0];
const firstFieldMetadataItem = filterableFieldMetadataItems[0];
if (!firstFieldMetadataItem) return null;

@@ -56,19 +56,19 @@ export const useResetFilterDropdown = (componentInstanceId?: string) => {
set(objectFilterDropdownSearchInputCallbackState, '');
set(objectFilterDropdownSelectedRecordIdsCallbackState, []);
set(selectedFilterCallbackState, 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: selectedFilterCallbackState is set to undefined while other states use null. Consider standardizing to either null or undefined across all states.

Comment on lines 234 to 237
displayAsRelativeDate: true,
},
},
position: expect.any(Number),
position: 3,
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Hardcoding position to 3 could make tests brittle. Consider using expect.any(Number) or documenting why 3 is the expected value.

Comment on lines 21 to 23
const setFieldMetadataItemIdUsedInDropdown = useSetRecoilComponentStateV2(
fieldMetadataItemIdUsedInDropdownComponentState,
);
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: setFieldMetadataItemIdUsedInDropdown is missing viewFilterDropdownId parameter, unlike other state setters. This inconsistency could cause state management issues.

Comment on lines +101 to 102
label: mockFieldMetadataItem.label,
type: getFilterTypeFromFieldType(mockFieldMetadataItem.type),
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: label is now derived from fieldMetadataItem.label instead of mockViewFilter.displayValue, which could potentially cause issues if these values differ in production

Comment on lines 28 to 35
if (isDefined(currentView)) {
setCurrentRecordFilters(
mapViewFiltersToFilters(currentView.viewFilters, filterDefinitions),
mapViewFiltersToFilters(
currentView.viewFilters,
filterableFieldMetadataItems,
),
);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: ensure that all field metadata items needed for filtering are available before setting filters, as missing metadata could cause runtime errors

Comment on lines +20 to +24
if (!isDefined(availableFieldMetadataItem)) {
throw new Error(
`Field metadata item not found for view filter ${viewFilter.id} and field metadata id ${viewFilter.fieldMetadataId}`,
);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: Throwing an error here could crash the application if metadata is missing. Consider returning null instead to maintain previous behavior.

- Fixed jest config to remove the many useless console.error
@lucasbordeau lucasbordeau enabled auto-merge (squash) February 14, 2025 17:32
@lucasbordeau lucasbordeau merged commit 70e5cdf into main Feb 14, 2025
46 checks passed
@lucasbordeau lucasbordeau deleted the refactor/removes-filter-definition branch February 14, 2025 17:37
Copy link

sentry-io bot commented Feb 17, 2025

Suspect Issues

This pull request was deployed and Sentry observed the following issues:

  • ‼️ Error: Field metadata item not found for view filter 0c865884-e2f4-452f-95ae-bfcc5eb70875 and field metadata id a33328b0-300d-44ed-8769-2588c9617da5 /objects/people View Issue
  • ‼️ Error: Field metadata item not found for view filter 0c865884-e2f4-452f-95ae-bfcc5eb70875 and field metadata id a33328b0-300d-44ed-8769-2588c9617da5 /objects/people View Issue

Did you find this useful? React with a 👍 or 👎

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