Skip to content
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

fix(Stats.js): display correct monthly measurements after changing language #886

Merged
merged 2 commits into from
Jan 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions components/landing/Stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ const swrOptions = {
const getLastMonthData = (collection) => {
const cc = collection.filter(d => {
const dt = new Date(Date.parse(d.date))
dt.setUTCMonth(dt.getUTCMonth()+1)
const today = new Date()
return (dt.getUTCFullYear() === today.getUTCFullYear()) && (today.getUTCMonth() - dt.getUTCMonth() === 1)
return (dt.getUTCFullYear() === today.getUTCFullYear()) && (today.getUTCMonth() === dt.getUTCMonth())
})
return cc.length === 0 ? 0 : cc[0]?.value ?? 0
}
Expand All @@ -56,20 +57,15 @@ const CoverageChart = () => {
const intl = useIntl()

if (data) {
const {
countries_by_month: countryCoverage,
networks_by_month: networkCoverage,
measurements_by_month: measurementsByMonth
} = data
countryCoverage.pop()
networkCoverage.pop()
measurementsByMonth.pop()
const countryCoverage = data.countries_by_month.slice(0, -1),
networkCoverage = data.networks_by_month.slice(0, -1),
measurementsByMonth = data.measurements_by_month.slice(0, -1)

// API responses are ordered by date, with most recent month at the end
const lastMonth = {
countryCount: getLastMonthData(countryCoverage),
networkCount: getLastMonthData(networkCoverage),
measurementCount: getLastMonthData(measurementsByMonth)
countryCount: getLastMonthData(data.countries_by_month),
networkCount: getLastMonthData(data.networks_by_month),
measurementCount: getLastMonthData(data.measurements_by_month)
}

// Determine the maximum value for each data set
Expand Down