Skip to content

Conversation

@ehconitin
Copy link
Contributor

CleanShot.2025-11-27.at.18.15.45.mp4

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Nov 27, 2025

Greptile Overview

Greptile Summary

Fixed critical bug where week granularity was incrementing by 1 day instead of 7 days, and enhanced week date formatting to display proper date ranges (e.g., "May 6 - 12, 2024")

Key Changes:

  • Fixed generateDateGroupsInRange.ts to increment by 7 days for week granularity
  • Enhanced formatDateByGranularity.ts to show week ranges with smart month/year boundary handling
  • Added weekStartDay support to respect user's calendar start day preference (Sunday/Monday)
  • Threaded firstDayOfTheWeek parameter through the query generation pipeline
  • Added comprehensive test coverage for week formatting edge cases

Issue Found:

  • Date aliasing bug in formatDateByGranularity.ts:21 that could cause unexpected mutations

Confidence Score: 4/5

  • Safe to merge after fixing the date aliasing bug
  • The PR fixes a critical bug and adds good test coverage, but contains a date mutation issue that needs to be resolved
  • Pay attention to packages/twenty-front/src/modules/page-layout/widgets/graph/utils/formatDateByGranularity.ts for the date aliasing fix

Important Files Changed

File Analysis

Filename Score Overview
packages/twenty-front/src/modules/page-layout/widgets/graph/graphWidgetBarChart/utils/generateDateGroupsInRange.ts 5/5 Fixed week granularity bug by incrementing by 7 days instead of 1 day (line 48)
packages/twenty-front/src/modules/page-layout/widgets/graph/hooks/useGraphWidgetGroupByQuery.ts 5/5 Added calendarStartDay from user preferences and passed it through to query generation functions
packages/twenty-front/src/modules/page-layout/widgets/graph/utils/buildGroupByFieldObject.ts 5/5 Added logic to include weekStartDay field when grouping by week with user-configured calendar start day
packages/twenty-front/src/modules/page-layout/widgets/graph/utils/formatDateByGranularity.ts 4/5 Enhanced week formatting to show date ranges with proper handling of month/year boundaries

Sequence Diagram

sequenceDiagram
    participant Component as Graph Widget Component
    participant Hook as useGraphWidgetGroupByQuery
    participant DateTime as useDateTimeFormat
    participant GenBar as generateGroupByQueryVariablesFromBarOrLineChartConfiguration
    participant GenPie as generateGroupByQueryVariablesFromPieChartConfiguration
    participant Build as buildGroupByFieldObject
    participant Apollo as Apollo Client
    participant Format as formatDateByGranularity
    
    Component->>Hook: Request graph data
    Hook->>DateTime: Get user preferences
    DateTime-->>Hook: Return calendarStartDay
    
    alt Pie Chart
        Hook->>GenPie: Generate query variables(firstDayOfTheWeek)
        GenPie->>Build: buildGroupByFieldObject(field, dateGranularity, firstDayOfTheWeek)
    else Bar/Line Chart
        Hook->>GenBar: Generate query variables(firstDayOfTheWeek)
        GenBar->>Build: buildGroupByFieldObject(field, dateGranularity, firstDayOfTheWeek)
    end
    
    alt Week Granularity & Not SYSTEM
        Build-->>GenBar: Return {field: {granularity: WEEK, weekStartDay: MONDAY/SUNDAY}}
    else Other Cases
        Build-->>GenBar: Return {field: {granularity: granularity}}
    end
    
    GenBar-->>Hook: Return groupBy variables with weekStartDay
    Hook->>Apollo: Execute GraphQL query
    Apollo-->>Hook: Return aggregated data
    
    Hook-->>Component: Return query results
    Component->>Format: formatDateByGranularity(date, WEEK)
    Format-->>Component: Return formatted week range (e.g., "May 6 - 12, 2024")
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.

8 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@github-actions
Copy link
Contributor

github-actions bot commented Nov 27, 2025

🚀 Preview Environment Ready!

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

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

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

@bosiraphael bosiraphael merged commit 26ec672 into main Nov 27, 2025
61 checks passed
@bosiraphael bosiraphael deleted the week-granuality-polish branch November 27, 2025 14:04
@github-actions
Copy link
Contributor

Thanks @ehconitin for your contribution!
This marks your 259th PR on the repo. You're top 1% of all our contributors 🎉
See contributor page - Share on LinkedIn - Share on Twitter

Contributions

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