Skip to content

fix incorrect date formatting being applied to non-date fields in graph widgets#16254

Merged
charlesBochet merged 3 commits intomainfrom
fix-non-date-relation-fields
Dec 2, 2025
Merged

fix incorrect date formatting being applied to non-date fields in graph widgets#16254
charlesBochet merged 3 commits intomainfrom
fix-non-date-relation-fields

Conversation

@ehconitin
Copy link
Copy Markdown
Contributor

@ehconitin ehconitin commented Dec 2, 2025

before -

CleanShot.2025-12-02.at.19.21.40.mp4

after -

CleanShot.2025-12-02.at.19.20.08.mp4

@ehconitin ehconitin requested a review from bosiraphael December 2, 2025 13:53
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Dec 2, 2025

Greptile Overview

Greptile Summary

Fixes incorrect date formatting being applied to non-date fields in graph widgets by replacing flawed detection logic with proper metadata lookup.

Key Changes:

  • Added isNestedFieldDateType utility that correctly checks if a relation subfield is a date type by examining the target object's metadata
  • Replaced the buggy logic !isDateField && isDefined(configuration.primaryAxisDateGranularity) which incorrectly treated ANY non-date field with a date granularity setting as a date field
  • Introduced configuration sanitization that removes date granularity settings from non-date fields before passing to formatting functions
  • Applied fix consistently across bar chart, line chart, and pie chart widgets
  • Enhanced formatDimensionValue to validate dates before applying date formatting

Confidence Score: 5/5

  • Safe to merge - well-tested fix that addresses a clear bug with proper metadata-based validation
  • The PR correctly fixes a logical bug where non-date fields were incorrectly formatted as dates. The solution is well-architected with a reusable utility function, includes proper tests, and handles edge cases like invalid dates. The change is applied consistently across all chart types.
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
packages/twenty-front/src/modules/page-layout/widgets/graph/utils/isNestedFieldDateType.ts 5/5 New utility function correctly checks if a relation subfield is a date type by examining target object metadata
packages/twenty-front/src/modules/page-layout/widgets/graph/utils/formatDimensionValue.ts 5/5 Improved date validation by checking for invalid dates and only applying granularity when dateGranularity is defined
packages/twenty-front/src/modules/page-layout/widgets/graph/graphWidgetBarChart/utils/transformGroupByDataToBarChartData.ts 5/5 Replaced flawed nested date detection logic with proper metadata lookup, sanitizes configuration to remove granularity from non-date fields

Sequence Diagram

sequenceDiagram
    participant Hook as useGraphBarChartWidgetData
    participant Transform as transformGroupByDataToBarChartData
    participant Utility as isNestedFieldDateType
    participant Metadata as objectMetadataItems
    participant Format as formatDimensionValue
    
    Hook->>Hook: useObjectMetadataItems()
    Hook->>Transform: Pass objectMetadataItems
    
    Transform->>Transform: Check if field is date (isFieldMetadataDateKind)
    Transform->>Utility: isNestedFieldDateType(field, subFieldName, items)
    Utility->>Utility: Check if field is relation
    Utility->>Metadata: Find target object by nameSingular
    Utility->>Metadata: Find nested field in target object
    Utility->>Utility: Check if nested field type is date
    Utility-->>Transform: Return true/false
    
    Transform->>Transform: Set primaryAxisDateGranularity only if date field
    Transform->>Transform: Create sanitizedConfiguration
    Transform->>Format: formatDimensionValue(value, field, granularity)
    Format->>Format: Only apply date formatting if granularity is defined
    Format-->>Transform: Formatted value
Loading

Copy link
Copy Markdown
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.

9 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Dec 2, 2025

🚀 Preview Environment Ready!

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

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

@charlesBochet charlesBochet merged commit 0158c6f into main Dec 2, 2025
64 checks passed
@charlesBochet charlesBochet deleted the fix-non-date-relation-fields branch December 2, 2025 14:26
@twenty-eng-sync
Copy link
Copy Markdown

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

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Dec 2, 2025

Thanks @ehconitin for your contribution!
This marks your 264th 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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants