Skip to content

Fixed relative date filter initalization #12811

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

Merged
merged 1 commit into from
Jun 24, 2025

Conversation

lucasbordeau
Copy link
Contributor

This PR fixes problems with date filter :

  • Filter chip shows the label with plural, ex : This weeks
  • Using a relative filter now initializes to This day
  • Switching between the different relative sub-operands (This, Past, Next) now initializes with a value so we're never in an "empty" state.

@lucasbordeau lucasbordeau requested a review from bosiraphael June 24, 2025 10:07
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

Fixed date filter initialization and display issues, focusing on relative date handling and proper pluralization.

  • Modified getRelativeDateDisplayValue in packages/twenty-front/src/modules/object-record/object-filter-dropdown/utils/getRelativeDateDisplayValue.ts to ensure 'THIS' direction uses singular form (e.g., 'This week' instead of 'This weeks')
  • Updated computeVariableDateViewFilterValue in packages/twenty-front/src/modules/views/view-filter-value/utils/computeVariableDateViewFilterValue.ts to enforce amount=1 for 'THIS' direction and validate positive amounts
  • Enhanced useApplyObjectFilterDropdownOperand in packages/twenty-front/src/modules/object-record/object-filter-dropdown/hooks/useApplyObjectFilterDropdownOperand.ts to initialize relative filters with 'This day' by default

3 files reviewed, 3 comments
Edit PR Review Bot Settings | Greptile

Comment on lines +13 to +17
} else if (amount === undefined || amount <= 0) {
throw new Error(
'Amount must be defined and greater than 0 for relative date filters',
);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Good validation, but error message could be more user-friendly. Consider extracting to a constant and making it less technical.

);
}

return `${direction}_${amount.toString()}_${unit}`;
Copy link
Contributor

Choose a reason for hiding this comment

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

style: toString() call unnecessary since template literals automatically convert to string. Remove for cleaner code.

Suggested change
return `${direction}_${amount.toString()}_${unit}`;
return `${direction}_${amount}_${unit}`;

Comment on lines +97 to +101
const defaultRelativeDate = {
direction: 'THIS' as VariableDateViewFilterValueDirection,
amount: 1,
unit: 'DAY' as VariableDateViewFilterValueUnit,
};
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 extracting defaultRelativeDate as a constant since it represents default configuration values

Copy link
Contributor

🚀 Preview Environment Ready!

Your preview environment is available at: http://bore.pub:60504

This environment will automatically shut down when the PR is closed or after 5 hours.

@charlesBochet charlesBochet merged commit 81d70e6 into main Jun 24, 2025
54 checks passed
@charlesBochet charlesBochet deleted the fix/relative-date-filter-bugs branch June 24, 2025 11:57
abdulrahmancodes pushed a commit to abdulrahmancodes/twenty that referenced this pull request Jun 26, 2025
This PR fixes problems with date filter : 
- Filter chip shows the label with plural, ex : `This weeks` 
- Using a relative filter now initializes to `This day`
- Switching between the different relative sub-operands (This, Past,
Next) now initializes with a value so we're never in an "empty" state.
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