You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
32884 analytics dashboard refactor state (dotCMS#33030)
### Proposed Changes
This pull request refactors and standardizes how time ranges are handled
throughout the Dot Analytics data access layer. The main improvements
include centralizing time range constants, updating types and services
to use these new constants, and enhancing granularity calculation for
custom date ranges. It also updates UI components and tests to align
with these changes.
**Time Range Standardization and Refactoring**
- Introduced `TIME_RANGE_OPTIONS` and `TIME_RANGE_CUBEJS_MAPPING`
constants for consistent time range handling across the codebase,
replacing hardcoded strings and scattered definitions.
[[1]](diffhunk://#diff-0d3fae337a838afd84911fc8b3587e656c3c8ddc1e2b3f96bcd4113d9782aa89R1-R15)
[[2]](diffhunk://#diff-9a6d064319b5b88cf3f0a012b5ca60b259eb4ee29e6c26ba78139a9a05a0f346R1)
[[3]](diffhunk://#diff-adb26a280c70da63050345af049168a8480129fb4d4e8d72796fcf6e8590b519R10-R12)
- Updated types (`TimeRange`, `TimeRangeCubeJS`, etc.) and removed
legacy time range constants, ensuring all type definitions rely on the
new centralized constants.
**Service and Store Updates**
- Refactored `DotAnalyticsService` methods to use
`TIME_RANGE_OPTIONS.last7days` as the default and to map time ranges via
a new private `#getTimeRange` method, ensuring proper Cube.js query
formatting.
[[1]](diffhunk://#diff-c0a594cb6bf35693b60035c742263700865b55e180715509ac6b9377ddaeb95bL11-R20)
[[2]](diffhunk://#diff-c0a594cb6bf35693b60035c742263700865b55e180715509ac6b9377ddaeb95bL34-R42)
[[3]](diffhunk://#diff-c0a594cb6bf35693b60035c742263700865b55e180715509ac6b9377ddaeb95bL54-R62)
[[4]](diffhunk://#diff-c0a594cb6bf35693b60035c742263700865b55e180715509ac6b9377ddaeb95bL74-R75)
[[5]](diffhunk://#diff-c0a594cb6bf35693b60035c742263700865b55e180715509ac6b9377ddaeb95bL83-R84)
[[6]](diffhunk://#diff-c0a594cb6bf35693b60035c742263700865b55e180715509ac6b9377ddaeb95bL97-R108)
[[7]](diffhunk://#diff-c0a594cb6bf35693b60035c742263700865b55e180715509ac6b9377ddaeb95bL122-R121)
[[8]](diffhunk://#diff-c0a594cb6bf35693b60035c742263700865b55e180715509ac6b9377ddaeb95bL131-R130)
[[9]](diffhunk://#diff-c0a594cb6bf35693b60035c742263700865b55e180715509ac6b9377ddaeb95bL145-R144)
[[10]](diffhunk://#diff-c0a594cb6bf35693b60035c742263700865b55e180715509ac6b9377ddaeb95bL155-R154)
[[11]](diffhunk://#diff-c0a594cb6bf35693b60035c742263700865b55e180715509ac6b9377ddaeb95bR163-R172)
- Updated the analytics dashboard store to use the new time range
constants for initial state.
[[1]](diffhunk://#diff-e3042fd9ba0c764b3ca7c9bcb6dfc598a9ffe7a1d69f7b6696b67b6bfd4e8e0aR25)
[[2]](diffhunk://#diff-e3042fd9ba0c764b3ca7c9bcb6dfc598a9ffe7a1d69f7b6696b67b6bfd4e8e0aL46-R47)
**Granularity Calculation Enhancements**
- Improved `determineGranularityForTimeRange` utility to handle custom
date ranges more accurately, using `date-fns` to determine if the range
is within the same day, month, or spans multiple months, and returning
the appropriate granularity (`hour`, `day`, or `month`).
[[1]](diffhunk://#diff-3ca44ed41a4fb83cc93df2c0268f2f4a0d620b4a0794673bb62a5242aa26d841R1-R10)
[[2]](diffhunk://#diff-3ca44ed41a4fb83cc93df2c0268f2f4a0d620b4a0794673bb62a5242aa26d841L28-R56)
- Added comprehensive tests for custom date range granularity logic.
**UI and Testing Updates**
- Updated UI components to trigger handlers on dropdown and calendar
changes, and to use the new date format and event bindings for custom
date selection.
[[1]](diffhunk://#diff-bc8d103344262ac3136ad2bbc9dd3042b062cbb008e7fdf9eb839bf46fe7e37bR17)
[[2]](diffhunk://#diff-bc8d103344262ac3136ad2bbc9dd3042b062cbb008e7fdf9eb839bf46fe7e37bL27-R32)
- Refactored component tests to use `queryParamMap` instead of
`queryParams`, matching the updated Angular ActivatedRoute API and
aligning with new time range handling.
[[1]](diffhunk://#diff-e08307bf30a07105f6cca75ae1d9b863dc15b363e60cf35aed799ca8cfd7685dL18-R18)
[[2]](diffhunk://#diff-e08307bf30a07105f6cca75ae1d9b863dc15b363e60cf35aed799ca8cfd7685dL227-R239)
[[3]](diffhunk://#diff-e08307bf30a07105f6cca75ae1d9b863dc15b363e60cf35aed799ca8cfd7685dL253-R251)
### Checklist
- [x] Tests
- [x] Translations
- [x] Security Implications Contemplated (add notes if applicable)
### Additional Info
** any additional useful context or info **
0 commit comments