-
Notifications
You must be signed in to change notification settings - Fork 6k
fix(events): pad hourly data for Events → Today chart (fixes #3697) #3710
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
base: master
Are you sure you want to change the base?
Conversation
|
@SamP231004 is attempting to deploy a commit to the umami-software Team on Vercel. A member of the Team first needs to authorize it. |
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.
Greptile Overview
Greptile Summary
This PR fixes the Events → Today chart to display all 24 hourly columns by adding a padTimeSeriesChartData function that fills missing time buckets between minDate and maxDate.
Major changes:
- Added
stepByUnithelper to generate hourly steps using dayjs - Added
padTimeSeriesChartDatato pad missing time buckets with zero values - Supports Chart.js dataset formats with
{x, y}coordinate objects - Applied padding via
useMemowhen rendering timeseries charts
Critical issues found:
- Locale is hardcoded as
'en'on line 91, breaking internationalization for non-English users - The locale parameter needs to be threaded through
padTimeSeriesChartData→BarChartuseMemo chartOptionsuseMemo has incorrect dependency (usespaddedChartDatainstead of the actual dependencies it relies on)
Confidence Score: 2/5
- This PR has critical i18n bugs that will break the feature for non-English locales
- The hardcoded locale on line 91 is a blocker - it will cause chart labels to always appear in English regardless of user's locale setting. The incorrect useMemo dependencies could also cause stale renders. While the core padding logic appears sound, these bugs make it unsafe to merge without fixes.
- src/components/charts/BarChart.tsx requires fixes to locale handling and useMemo dependencies before merging
Important Files Changed
File Analysis
| Filename | Score | Overview |
|---|---|---|
| src/components/charts/BarChart.tsx | 2/5 | Adds hourly padding logic but has critical locale hardcoding bug that breaks i18n, plus incorrect useMemo dependencies |
Sequence Diagram
sequenceDiagram
participant User
participant EventsChart
participant BarChart
participant padTimeSeriesChartData
participant Chart.js
User->>EventsChart: View "Today" events
EventsChart->>EventsChart: Fetch event series data
EventsChart->>EventsChart: useMemo: create chartData with datasets
EventsChart->>BarChart: Pass chartData, minDate, maxDate, unit='hour'
BarChart->>BarChart: useMemo: check if timeseries && unit && minDate && maxDate
BarChart->>padTimeSeriesChartData: Call with chartData, unit, minDate, maxDate
padTimeSeriesChartData->>padTimeSeriesChartData: Generate hourly steps (0-23) using dayjs
padTimeSeriesChartData->>padTimeSeriesChartData: Map existing data to ISO timestamps
padTimeSeriesChartData->>padTimeSeriesChartData: Fill missing hours with {x, y: 0}
padTimeSeriesChartData-->>BarChart: Return paddedChartData with all 24 hours
BarChart->>BarChart: useMemo: build chartOptions with scales
BarChart->>Chart.js: Render with paddedChartData
Chart.js-->>User: Display chart with all hourly columns (0-23)
1 file reviewed, 4 comments
| // Case A: Chart.js style | ||
| if (chartData && chartData.labels && Array.isArray(chartData.datasets)) { | ||
| // Normalize: if dataset.data is array of numbers aligned with labels -> create label->value map | ||
| const newLabels = stepKeys.map(k => formatDate(new Date(k), DATE_FORMATS[unit], 'en')); // labels formatted; locale handled by Chart options |
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: hardcoded 'en' locale will break internationalization - should accept locale as parameter
| const newLabels = stepKeys.map(k => formatDate(new Date(k), DATE_FORMATS[unit], 'en')); // labels formatted; locale handled by Chart options | |
| const newLabels = stepKeys.map(k => formatDate(new Date(k), DATE_FORMATS[unit], locale)); |
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/components/charts/BarChart.tsx
Line: 91:91
Comment:
**logic:** hardcoded `'en'` locale will break internationalization - should accept locale as parameter
```suggestion
const newLabels = stepKeys.map(k => formatDate(new Date(k), DATE_FORMATS[unit], locale));
```
How can I resolve this? If you propose a fix, please make it concise.| function padTimeSeriesChartData( | ||
| chartData: any, | ||
| unit: ManipulateType, | ||
| minDate?: Date, | ||
| maxDate?: Date, | ||
| ) { |
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: missing locale parameter - will break when locale is needed on line 91
| function padTimeSeriesChartData( | |
| chartData: any, | |
| unit: ManipulateType, | |
| minDate?: Date, | |
| maxDate?: Date, | |
| ) { | |
| function padTimeSeriesChartData( | |
| chartData: any, | |
| unit: ManipulateType, | |
| minDate?: Date, | |
| maxDate?: Date, | |
| locale?: string, | |
| ) { |
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/components/charts/BarChart.tsx
Line: 57:62
Comment:
**logic:** missing `locale` parameter - will break when locale is needed on line 91
```suggestion
function padTimeSeriesChartData(
chartData: any,
unit: ManipulateType,
minDate?: Date,
maxDate?: Date,
locale?: string,
) {
```
How can I resolve this? If you propose a fix, please make it concise.| const paddedChartData = useMemo(() => { | ||
| if (XAxisType === 'timeseries' && unit && minDate && maxDate) { | ||
| return padTimeSeriesChartData(chartData, unit as ManipulateType, minDate, maxDate); | ||
| } | ||
| return chartData; | ||
| }, [chartData, unit, XAxisType, minDate?.toString(), maxDate?.toString()]); |
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: needs to pass locale parameter to fix hardcoded locale issue
| const paddedChartData = useMemo(() => { | |
| if (XAxisType === 'timeseries' && unit && minDate && maxDate) { | |
| return padTimeSeriesChartData(chartData, unit as ManipulateType, minDate, maxDate); | |
| } | |
| return chartData; | |
| }, [chartData, unit, XAxisType, minDate?.toString(), maxDate?.toString()]); | |
| const paddedChartData = useMemo(() => { | |
| if (XAxisType === 'timeseries' && unit && minDate && maxDate) { | |
| return padTimeSeriesChartData(chartData, unit as ManipulateType, minDate, maxDate, locale); | |
| } | |
| return chartData; | |
| }, [chartData, unit, XAxisType, minDate?.toString(), maxDate?.toString(), locale]); |
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/components/charts/BarChart.tsx
Line: 174:179
Comment:
**logic:** needs to pass `locale` parameter to fix hardcoded locale issue
```suggestion
const paddedChartData = useMemo(() => {
if (XAxisType === 'timeseries' && unit && minDate && maxDate) {
return padTimeSeriesChartData(chartData, unit as ManipulateType, minDate, maxDate, locale);
}
return chartData;
}, [chartData, unit, XAxisType, minDate?.toString(), maxDate?.toString(), locale]);
```
How can I resolve this? If you propose a fix, please make it concise.| }, | ||
| }; | ||
| }, [chartData, colors, unit, stacked, renderXLabel, renderYLabel]); | ||
| }, [paddedChartData, colors, unit, stacked, renderXLabel, renderYLabel]); |
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: paddedChartData in dependency array but not used in function - should reference other actual dependencies like minDate, maxDate, locale
| }, [paddedChartData, colors, unit, stacked, renderXLabel, renderYLabel]); | |
| }, [chartData, colors, unit, stacked, renderXLabel, renderYLabel, minDate, maxDate, locale]); |
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/components/charts/BarChart.tsx
Line: 225:225
Comment:
**logic:** `paddedChartData` in dependency array but not used in function - should reference other actual dependencies like `minDate`, `maxDate`, `locale`
```suggestion
}, [chartData, colors, unit, stacked, renderXLabel, renderYLabel, minDate, maxDate, locale]);
```
How can I resolve this? If you propose a fix, please make it concise.|
There are issues with locale. Additionally we shouldn't need a new dependency on dayjs as we already use date-fns. |
Fixes: #3697 — Events view for "Today" doesn't show all hourly columns
Summary
This patch ensures that the Events → Today chart displays all hourly buckets (0–23) between the selected
minDateandmaxDate.Previously, the chart only rendered hours that contained data and added a single placeholder bar at 11 PM, which made the graph appear truncated.
Changes
padTimeSeriesChartDatainsrc/components/charts/BarChart.tsx:{ x, y }points.minDateandmaxDatewith zero values.localeparameter for label formatting.DATE_FORMATS.BarChartto passlocaleand apply the padding function when rendering time-series data.Verification
Verified locally using Docker:
After the change, the Events → Today chart correctly renders 24 hourly columns with zero-height bars for empty hours.
Notes
dayjsto generate hourly steps betweenminDateandmaxDate.Screenshot (After Fix)