-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Added relative date filter to dashboards #16292
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
Added relative date filter to dashboards #16292
Conversation
Greptile OverviewGreptile SummaryThis 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:
Critical Issue Found:
Confidence Score: 1/5
Important Files ChangedFile Analysis
Sequence DiagramsequenceDiagram
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
|
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.
6 files reviewed, 2 comments
| const userDefinedCalendarStartDay = | ||
| CalendarStartDay[ | ||
| currentWorkspaceMember?.calendarStartDay ?? CalendarStartDay.SYSTEM | ||
| ]; | ||
| const defaultSystemCalendarStartDay = detectCalendarStartDay(); | ||
|
|
||
| const resolvedCalendarStartDay = ( | ||
| userDefinedCalendarStartDay === CalendarStartDay[CalendarStartDay.SYSTEM] | ||
| ? defaultSystemCalendarStartDay | ||
| : userDefinedCalendarStartDay | ||
| ) as FirstDayOfTheWeek; |
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.
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:
| 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'; | |||
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.
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.|
🚀 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. |
4fb0c3d to
e6aec2e
Compare
e6aec2e to
2422513
Compare
|
Hey @lucasbordeau! After you've done the QA of your Pull Request, you can mark it as done here. Thank you! |
This PR adds relative date filter operand to dashboard filters :
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.