Skip to content

Conversation

@lucasbordeau
Copy link
Contributor

@lucasbordeau lucasbordeau commented Dec 3, 2025

This PR adds relative date filter operand to dashboard filters :

image

It also refactors the logic to add timezone and first day of the week taking users preferences.

It has been tested on workflows and regular advanced filters also.

For step filters, which use a JSON format to store relative date filters, I kept the current way to handle it.

There are a few workspaces that use a relative date filter in step filter, so we want to avoid a migration, and instead handle both code paths, and refactor everything to JSON later.

@lucasbordeau lucasbordeau requested a review from thomtrp December 3, 2025 16:45
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Dec 3, 2025

Greptile Overview

Greptile Summary

This PR adds relative date filter support to dashboard filters and refactors date filtering to include user timezone and first day of week preferences.

Key Changes:

  • Removed filter that excluded IS_RELATIVE operand from advanced filters
  • Added FormRelativeDatePicker component integration for relative date input
  • Created new useGetRelativeDateFilterWithUserTimezone hook to centralize timezone/calendar logic
  • Refactored to use resolveRelativeDateFilterStringified instead of deprecated JSON parsing

Critical Issue Found:

  • The new useGetRelativeDateFilterWithUserTimezone hook contains a logic error in enum handling (lines 16-26). It incorrectly manipulates CalendarStartDay numeric enum with string keys from detectCalendarStartDay(), then tries to cast to FirstDayOfTheWeek string enum. This will break when user has SYSTEM calendar setting.
  • The existing getCalendarStartDayFromWorkspaceMember utility already handles this correctly and should be used instead.

Confidence Score: 1/5

  • This PR contains a critical logic error that will cause runtime failures for users with SYSTEM calendar setting
  • Score reflects critical logic error in useGetRelativeDateFilterWithUserTimezone hook that incorrectly handles enum conversions between CalendarStartDay and FirstDayOfTheWeek. The bug will cause the calendar start day resolution to fail when users have SYSTEM preference. Fix requires using existing getCalendarStartDayFromWorkspaceMember utility instead of reimplementing the logic incorrectly.
  • Pay close attention to useGetRelativeDateFilterWithUserTimezone.ts - it contains critical enum handling logic error

Important Files Changed

File Analysis

Filename Score Overview
packages/twenty-front/src/modules/object-record/record-filter/hooks/useGetRelativeDateFilterWithUserTimezone.ts 1/5 New hook with critical logic error in enum handling that breaks calendar start day resolution
packages/twenty-front/src/modules/object-record/record-field/ui/form-types/components/FormRelativeDatePicker.tsx 4/5 Properly integrates new hook and uses correct parsing utilities for relative date filters

Sequence Diagram

sequenceDiagram
    participant User
    participant AdvancedFilterMenu
    participant FormRelativeDatePicker
    participant useGetRelativeDateFilterHook
    participant WorkspaceMember
    participant stringifyUtil

    User->>AdvancedFilterMenu: Select IS_RELATIVE operand
    AdvancedFilterMenu->>useGetRelativeDateFilterHook: Get default relative date with timezone
    useGetRelativeDateFilterHook->>WorkspaceMember: Read calendarStartDay preference
    useGetRelativeDateFilterHook->>useGetRelativeDateFilterHook: ⚠️ Logic error in enum handling
    useGetRelativeDateFilterHook-->>AdvancedFilterMenu: Return filter with timezone & firstDayOfWeek
    AdvancedFilterMenu->>stringifyUtil: Stringify relative date filter
    stringifyUtil-->>AdvancedFilterMenu: Serialized filter string
    AdvancedFilterMenu->>FormRelativeDatePicker: Render with defaultValue
    User->>FormRelativeDatePicker: Change relative date value
    FormRelativeDatePicker->>useGetRelativeDateFilterHook: Apply timezone to new value
    FormRelativeDatePicker->>stringifyUtil: Stringify updated filter
    FormRelativeDatePicker-->>AdvancedFilterMenu: Update filter value
Loading

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.

6 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

Comment on lines +16 to +26
const userDefinedCalendarStartDay =
CalendarStartDay[
currentWorkspaceMember?.calendarStartDay ?? CalendarStartDay.SYSTEM
];
const defaultSystemCalendarStartDay = detectCalendarStartDay();

const resolvedCalendarStartDay = (
userDefinedCalendarStartDay === CalendarStartDay[CalendarStartDay.SYSTEM]
? defaultSystemCalendarStartDay
: userDefinedCalendarStartDay
) as FirstDayOfTheWeek;
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: logic error in enum handling - CalendarStartDay is a numeric enum (SYSTEM=7, SUNDAY=0, MONDAY=1, SATURDAY=6) but detectCalendarStartDay() returns string keys like 'MONDAY'. line 16-18 does CalendarStartDay[currentWorkspaceMember?.calendarStartDay] which works (numeric to string key), but line 23 compares it with CalendarStartDay[CalendarStartDay.SYSTEM] which equals 'SYSTEM' string, not a CalendarStartDay value. then line 26 casts to FirstDayOfTheWeek which expects 'MONDAY'/'SUNDAY'/'SATURDAY' strings. this will fail when calendarStartDay is SYSTEM (7).

should use existing getCalendarStartDayFromWorkspaceMember utility instead, which properly handles this:

Suggested change
const userDefinedCalendarStartDay =
CalendarStartDay[
currentWorkspaceMember?.calendarStartDay ?? CalendarStartDay.SYSTEM
];
const defaultSystemCalendarStartDay = detectCalendarStartDay();
const resolvedCalendarStartDay = (
userDefinedCalendarStartDay === CalendarStartDay[CalendarStartDay.SYSTEM]
? defaultSystemCalendarStartDay
: userDefinedCalendarStartDay
) as FirstDayOfTheWeek;
const calendarStartDay = getCalendarStartDayFromWorkspaceMember(
currentWorkspaceMember,
);
const firstDayOfTheWeek =
calendarStartDay === CalendarStartDay.SYSTEM
? detectCalendarStartDay()
: CalendarStartDay[calendarStartDay];
return {
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/twenty-front/src/modules/object-record/record-filter/hooks/useGetRelativeDateFilterWithUserTimezone.ts
Line: 16:26

Comment:
**logic:** logic error in enum handling - `CalendarStartDay` is a numeric enum (SYSTEM=7, SUNDAY=0, MONDAY=1, SATURDAY=6) but `detectCalendarStartDay()` returns string keys like 'MONDAY'. line 16-18 does `CalendarStartDay[currentWorkspaceMember?.calendarStartDay]` which works (numeric to string key), but line 23 compares it with `CalendarStartDay[CalendarStartDay.SYSTEM]` which equals 'SYSTEM' string, not a `CalendarStartDay` value. then line 26 casts to `FirstDayOfTheWeek` which expects 'MONDAY'/'SUNDAY'/'SATURDAY' strings. this will fail when `calendarStartDay` is SYSTEM (7).

should use existing `getCalendarStartDayFromWorkspaceMember` utility instead, which properly handles this:

```suggestion
    const calendarStartDay = getCalendarStartDayFromWorkspaceMember(
      currentWorkspaceMember,
    );

    const firstDayOfTheWeek =
      calendarStartDay === CalendarStartDay.SYSTEM
        ? detectCalendarStartDay()
        : CalendarStartDay[calendarStartDay];

    return {
```

How can I resolve this? If you propose a fix, please make it concise.

@@ -0,0 +1,38 @@
import { currentWorkspaceMemberState } from '@/auth/states/currentWorkspaceMemberState';
Copy link
Contributor

Choose a reason for hiding this comment

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

syntax: missing import for getCalendarStartDayFromWorkspaceMember utility which should be used instead of reimplementing the logic

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/twenty-front/src/modules/object-record/record-filter/hooks/useGetRelativeDateFilterWithUserTimezone.ts
Line: 1:1

Comment:
**syntax:** missing import for `getCalendarStartDayFromWorkspaceMember` utility which should be used instead of reimplementing the logic

How can I resolve this? If you propose a fix, please make it concise.

@github-actions
Copy link
Contributor

github-actions bot commented Dec 3, 2025

🚀 Preview Environment Ready!

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

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

@lucasbordeau lucasbordeau force-pushed the feat/add-relative-date-filter-on-dashboard branch from e6aec2e to 2422513 Compare December 9, 2025 17:43
@charlesBochet charlesBochet merged commit e8fd5fa into main Dec 15, 2025
67 checks passed
@charlesBochet charlesBochet deleted the feat/add-relative-date-filter-on-dashboard branch December 15, 2025 17:52
@twenty-eng-sync
Copy link

Hey @lucasbordeau! After you've done the QA of your Pull Request, you can mark it as done here. Thank you!

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.

3 participants