FIX: Sum pageviews with number instead of string (#28596)

When the tooltip items are tooltipItem = [{parsed: {y:12} }, {parsed: {y:10} } ], reducing without a initial value as a number would result in Javascript thinking it is a string. Thanks, Javascript!

There are no tests here yet since this makes use of an external library Chart.js.
This commit is contained in:
Natalie Tay 2024-08-28 19:24:57 +08:00 committed by GitHub
parent 480f26a2c2
commit 3a04443632
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -42,7 +42,8 @@ export default class AdminReportStackedChart extends Component {
callbacks: {
beforeFooter: (tooltipItem) => {
const total = tooltipItem.reduce(
(sum, item) => sum + parseInt(item.parsed.y || 0, 10)
(sum, item) => sum + parseInt(item.parsed.y || 0, 10),
0
);
return `= ${total}`;
},