Skip to content

Issue 33523 granularity fix#34867

Open
erickgonzalez wants to merge 5 commits intoissue-34397-task-update-date-filter-options-in-analytics-dashbfrom
issue-33523-granularity-fix
Open

Issue 33523 granularity fix#34867
erickgonzalez wants to merge 5 commits intoissue-34397-task-update-date-filter-options-in-analytics-dashbfrom
issue-33523-granularity-fix

Conversation

@erickgonzalez
Copy link
Member

@erickgonzalez erickgonzalez commented Mar 4, 2026

This PR fixes: #33523

@erickgonzalez
Copy link
Member Author

@claude generate a description for this PR

@erickgonzalez
Copy link
Member Author

@claude code review this pull request

@claude
Copy link
Contributor

claude bot commented Mar 4, 2026

Claude finished @erickgonzalez's task —— View job


Code Review Complete

Reviewing PR #34867 for issue #33523 granularity fix.

Todo List:

  • Read repository CLAUDE.md files for context
  • Analyze changed files to understand scope of removals
  • Review functional changes in store features
  • Examine removed constants, utilities, and tests
  • Check for potential breaking changes or edge cases
  • Provide comprehensive review feedback

Code Review Findings

This PR is clean and well-executed. It removes unsupported time ranges and unused granularity logic from the analytics portlet. The changes are safe and improve code maintainability.

What was removed:

  • 4 unsupported time range options: today, yesterday
  • 71 lines of unused determineGranularityForTimeRange() function and related logic
  • Associated test coverage (120+ lines) for the removed functionality
  • Dead code paths in filters that excluded removed time ranges

Technical Assessment:

  • No breaking changes: Only removes unused constants and dead code
  • Consistent cleanup: All imports of removed date utilities (isSameMonth) properly cleaned up
  • Safe store changes: Hardcoded 'day' granularity usage in store features is appropriate since all remaining time ranges (last7days, last30days, custom) use daily granularity
  • Test coverage maintained: Removed tests only covered the deleted functionality

Positive aspects:

  • Reduces code complexity by 258 lines
  • Eliminates dead/unused code paths
  • Maintains all supported functionality intact
  • Clean commit history with logical separation of changes

@claude
Copy link
Contributor

claude bot commented Mar 4, 2026

Claude finished @erickgonzalez's task —— View job


PR Description Generated ✅

I've analyzed the changes in this PR and generated a comprehensive description.

Tasks:

  • Read and analyze changed files to understand the scope of changes
  • Identify what functionality was removed or simplified
  • Generate a clear PR description explaining the changes
  • Update comment with final description

Summary

This PR removes unsupported time range options (today and yesterday) and simplifies granularity logic in the analytics portlet, addressing issue #33523. The changes primarily involve cleanup of unused functionality and removal of associated test coverage.

What Changed

🗑️ Removed Unsupported Time Range Options

  • Removed today and yesterday from TIME_RANGE_OPTIONS constants
  • Removed corresponding CubeJS mappings for these time ranges
  • Updated filter utilities to no longer handle these excluded time ranges

🔧 Simplified Granularity Logic

  • Removed determineGranularityForTimeRange() function - This complex function determined granularity (hour/day/month) based on time ranges
  • Hardcoded granularity to 'day' in all analytics queries:
    • Page view timeline queries
    • Conversion trend queries
    • Traffic vs conversions queries
  • Simplified the date filling logic by removing dynamic granularity determination

🧪 Removed Associated Tests

  • Deleted 120 test cases from analytics-data.utils.spec.ts (primarily testing the removed granularity function)
  • Removed 11 test cases from filters.utils.spec.ts (testing excluded time ranges)
  • Removed 9 test cases from dot-analytics-filters.component.spec.ts
  • Removed 8 test cases from dot-analytics.utils.spec.ts
  • Total: 148 deleted test lines

Impact

Positive Changes

  • Simplified codebase: Removed complex granularity determination logic that may have been causing issues
  • Consistent behavior: All analytics queries now use consistent daily granularity
  • Reduced maintenance overhead: Fewer time range options to support and test

⚠️ Breaking Changes

  • Users can no longer select today or yesterday time ranges (functionality was likely already problematic)
  • Analytics queries are now limited to daily granularity (no more hourly or monthly aggregations)

Files Modified

  • Constants: Updated time range options and mappings
  • Store Features: Simplified granularity logic in conversions and pageview features
  • Utils: Removed granularity determination function and updated filter logic
  • Tests: Removed test coverage for deleted functionality

Job run

@claude
Copy link
Contributor

claude bot commented Mar 4, 2026

Claude finished @erickgonzalez's task —— View job


Code Review Complete

Reviewing PR #34867 for issue #33523 granularity fix.

Todo List:

  • Read repository CLAUDE.md files for context
  • Analyze changed files to understand scope of removals
  • Review functional changes in store features
  • Examine removed constants, utilities, and tests
  • Check for potential breaking changes or edge cases
  • Provide comprehensive review feedback

Code Review Findings

This PR is clean and well-executed. It removes unsupported time ranges and unused granularity logic from the analytics portlet. The changes are safe and improve code maintainability.

What was removed:

  • 4 unsupported time range options: today, yesterday
  • 71 lines of unused determineGranularityForTimeRange() function and related logic
  • Associated test coverage (120+ lines) for the removed functionality
  • Dead code paths in filters that excluded removed time ranges

Technical Assessment:

  • No breaking changes: Only removes unused constants and dead code
  • Consistent cleanup: All imports of removed date utilities (isSameMonth) properly cleaned up
  • Safe store changes: Hardcoded 'day' granularity usage in store features is appropriate since all remaining time ranges (last7days, last30days, custom) use daily granularity
  • Test coverage maintained: Removed tests only covered the deleted functionality

Positive aspects:

  • Reduces code complexity by 258 lines
  • Eliminates dead/unused code paths
  • Maintains all supported functionality intact
  • Clean commit history with logical separation of changes

Job run

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the dot-analytics dashboard time range utilities and data-access layer by removing unsupported today/yesterday time range handling and by eliminating the existing “auto granularity” helper in favor of forcing daily granularity in timeline queries.

Changes:

  • Removed today/yesterday from analytics TIME_RANGE_OPTIONS and related URL-param/test handling.
  • Deleted determineGranularityForTimeRange and updated timeline queries to use a fixed 'day' granularity.
  • Updated/removed unit tests that depended on the old time range and granularity behavior.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
core-web/libs/portlets/dot-analytics/portlet/src/lib/dot-analytics-dashboard/shared/utils/dot-analytics.utils.ts Simplifies URL time-range validation; removes special-casing of unsupported ranges.
core-web/libs/portlets/dot-analytics/portlet/src/lib/dot-analytics-dashboard/shared/utils/dot-analytics.utils.spec.ts Removes tests asserting today/yesterday are invalid URL ranges.
core-web/libs/portlets/dot-analytics/portlet/src/lib/dot-analytics-dashboard/shared/components/dot-analytics-filters/dot-analytics-filters.component.spec.ts Removes tests that ensured today/yesterday weren’t in the UI options list.
core-web/libs/portlets/dot-analytics/data-access/src/lib/utils/filters.utils.ts Removes now-redundant exclusion list for unsupported time_range values.
core-web/libs/portlets/dot-analytics/data-access/src/lib/utils/filters.utils.spec.ts Removes tests covering fallback behavior for today/yesterday query params.
core-web/libs/portlets/dot-analytics/data-access/src/lib/utils/data/analytics-data.utils.ts Removes granularity auto-selection utility and today/yesterday date-range handling.
core-web/libs/portlets/dot-analytics/data-access/src/lib/utils/data/analytics-data.utils.spec.ts Removes tests for removed granularity helper and removed date-range cases.
core-web/libs/portlets/dot-analytics/data-access/src/lib/store/features/with-pageview.feature.ts Forces 'day' granularity for pageview timeline query + date filling.
core-web/libs/portlets/dot-analytics/data-access/src/lib/store/features/with-conversions.feature.ts Forces 'day' granularity for conversion timeline queries + date filling.
core-web/libs/portlets/dot-analytics/data-access/src/lib/constants/dot-analytics.constants.ts Removes today/yesterday from supported time-range constants and CubeJS mapping.

You can also share your feedback on Copilot code review. Take the survey.

@claude
Copy link
Contributor

claude bot commented Mar 5, 2026

Claude finished @erickgonzalez's task —— View job


Code Review Complete

Todo List:

  • Read repository CLAUDE.md files for context
  • Analyze changed files to understand modifications
  • Check if previous reviewer feedback was addressed (granularity constants)
  • Look for potential issues: security, edge cases, design problems
  • Provide comprehensive review feedback

Review Findings

🚨 Critical Issue: Previous Reviewer Feedback NOT Addressed

The reviewers (nicobytes) specifically requested creating an enum/const for granularity in 3 separate comments, but this has not been implemented. Instead, Granularity.DAY is still hardcoded throughout the features:

  • with-conversions.feature.ts:120, 180, 244, 301, 369, 431
  • with-pageview.feature.ts:101, 154, 212, 269, 277, 333, 390
  • with-engagement.feature.ts: similar pattern

The author marked all 3 reviewer comments as "done" but did not actually implement the requested changes.

Other Issues Found

1. URL Validation Logic Flaw (dot-analytics.utils.ts:43)

return Object.keys(TIME_RANGE_OPTIONS).includes(urlValue) ? (urlValue as TimeRange) : null;

This validates against the keys of TIME_RANGE_OPTIONS but TimeRange type comes from the values. This works currently because keys and values are identical, but creates a hidden dependency that could break if the constant structure changes. Should use Object.values(TIME_RANGE_OPTIONS) as suggested by copilot-pull-request-reviewer.

2. Inconsistent Granularity Usage
The PR forces all analytics to daily granularity, but some queries use different patterns:

  • Most use: Granularity.DAY, toTimeRangeCubeJS(timeRange), Granularity.DAY
  • Some use: Granularity.DAY, toTimeRangeCubeJS(timeRange) (missing 3rd parameter)
  • One query uses: 'createdAt', toTimeRangeCubeJS(timeRange) (string instead of constant)

This inconsistency suggests the refactoring was done hastily without a consistent pattern.

Design Concerns

3. Loss of Flexibility
The PR removes all granularity determination logic and forces everything to daily. While this may solve the immediate issue, it eliminates the ability to show hourly data for short time ranges or weekly/monthly for longer ranges. This could hurt UX for certain use cases.

4. Missing Constants (Primary Issue)
The core request from reviewers to create granularity constants was ignored. This should be something like:

export const DEFAULT_GRANULARITY = Granularity.DAY;

Positive Aspects

  • Clean removal of unused today/yesterday options
  • Consistent removal of associated test coverage
  • Simplified codebase with less complexity
  • No breaking changes to existing functionality

Recommendation

Request changes - The granularity constants must be implemented as requested by reviewers before merge. The URL validation issue should also be fixed.


@claude
Copy link
Contributor

claude bot commented Mar 5, 2026

Claude finished @erickgonzalez's task —— View job


🚨 Request Changes - Critical Issues Found

Todo List:

  • Read repository CLAUDE.md files for context and standards
  • Analyze changed files to understand scope of modifications
  • Check if previous reviewer feedback was properly addressed
  • Look for potential issues: security, edge cases, design problems
  • Provide comprehensive review feedback

🚨 CRITICAL: Previous Reviewer Feedback NOT Addressed

nicobytes specifically requested creating an enum/const for granularity in 3 separate comments, but this has NOT been implemented:

"We should create an enum/const for the granularity to keep the same string in one place."

The author marked all 3 reviewer comments as "done" but did not actually implement the requested changes.

Instead, Granularity.DAY is still hardcoded throughout the features:

  • with-conversions.feature.ts: Lines 120, 180, 244, 301, 369, 431
  • with-pageview.feature.ts: Lines 101, 154, 212, 269, 277, 333, 390
  • with-engagement.feature.ts: Similar pattern

This creates maintenance debt when granularity logic needs to change.


Additional Issues Found

1. URL Validation Logic Flaw (dot-analytics.utils.ts:43)

return (Object.values(TIME_RANGE_OPTIONS) as string[]).includes(urlValue)
    ? (urlValue as TimeRange)
    : null;

Fixed correctly - The author already implemented the copilot suggestion to use Object.values() instead of Object.keys(). This was previously a potential issue but has been resolved.

2. Inconsistent Granularity Usage Patterns

The PR forces all analytics to daily granularity, but queries use different patterns:

  • Most use: Granularity.DAY, toTimeRangeCubeJS(timeRange), Granularity.DAY (3 parameters)
  • Some use: Granularity.DAY, toTimeRangeCubeJS(timeRange) (2 parameters missing 3rd)
  • One query uses: 'createdAt', toTimeRangeCubeJS(timeRange) (string instead of constant)

This inconsistency suggests the refactoring was done hastily without a consistent pattern.

3. Loss of Flexibility (Design Concern)

The PR removes all granularity determination logic and forces everything to daily. While this may solve the immediate issue, it eliminates the ability to show:

  • Hourly data for short time ranges (today/yesterday)
  • Weekly/monthly aggregations for longer ranges

This could hurt UX for certain analytics use cases.


Positive Aspects

  • ✅ Clean removal of unused today/yesterday options
  • ✅ Consistent removal of associated test coverage
  • ✅ Simplified codebase with reduced complexity
  • ✅ URL validation bug was properly fixed
  • ✅ No breaking changes to existing supported functionality

Recommendation

REQUEST CHANGES - The granularity constants must be implemented as requested by reviewers before merge.

Required Fix:
Create a constant for the default granularity, such as:

export const DEFAULT_GRANULARITY = Granularity.DAY;

Then replace all hardcoded Granularity.DAY references with DEFAULT_GRANULARITY throughout the store features.


Job run

This centralizes granularity logic by introducing and referencing a default constant across multiple features, ensuring consistency.

Ref: #33523
@claude
Copy link
Contributor

claude bot commented Mar 5, 2026

Claude finished @erickgonzalez's task —— View job


✅ Clean Code Review

Todo List:

  • Read repository CLAUDE.md files for context and standards
  • Analyze changed files to understand scope of modifications
  • Check if previous reviewer feedback was properly addressed (granularity constants)
  • Look for potential issues: security, edge cases, design problems
  • Provide comprehensive review feedback

Review Summary

This PR is clean and well-executed. The code changes are focused, safe, and properly implement reviewer feedback.

✅ Reviewer Feedback Properly Addressed

Contrary to my initial concern, the author DID implement the granularity constants as requested by nicobytes:

  • Implemented: DEFAULT_GRANULARITY = Granularity.DAY constant in cubequery.types.ts:47
  • Used consistently: All hardcoded Granularity.DAY references replaced with DEFAULT_GRANULARITY throughout store features
  • Proper imports: Constant is imported and used in all affected files (with-conversions.feature.ts, with-pageview.feature.ts, with-engagement.feature.ts)

✅ URL Validation Fix Applied

The copilot suggestion was correctly implemented in dot-analytics.utils.ts:43:

return (Object.values(TIME_RANGE_OPTIONS) as string[]).includes(urlValue)
    ? (urlValue as TimeRange)
    : null;

✅ Clean Code Removals

What was removed:

  • 2 unsupported time range options (today, yesterday) from constants
  • 71 lines of unused determineGranularityForTimeRange() function
  • 148+ lines of associated test coverage for removed functionality
  • Dead code paths that handled excluded time ranges

Technical assessment:

  • No breaking changes: Only removes unused constants and dead code
  • Maintains functionality: All supported time ranges (last7days, last30days, custom) work unchanged
  • Consistent implementation: All queries now use daily granularity consistently
  • Clean test removals: Only tests for removed functionality were deleted

✅ Code Quality

  • Type safety: Proper TypeScript patterns with const assertions
  • Angular standards: Modern NgRx signals patterns throughout
  • Error handling: Comprehensive error handling with proper logging
  • Consistent naming: All constants and types follow established conventions

Minor Technical Notes

  1. Granularity approach: The PR forces all analytics to daily granularity, which removes flexibility for hourly/weekly aggregations but solves the original issue ([FEATURE] Add granularity selector for Analytics dashboard custom date ranges #33523)
  2. Query patterns: Some queries use 3-parameter timeRange calls, others use 2-parameter - this is intentional based on whether date filling is needed
  3. One exception: Line 333 in with-pageview.feature.ts uses string 'createdAt' instead of constant - but this appears to be for a different cube type

Job run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

[FEATURE] Add granularity selector for Analytics dashboard custom date ranges

4 participants