Skip to content

Commit 0416612

Browse files
authored
Merge pull request #888 from IQSS/883-large-download-numbers-should-have-commas
Fix: large download numbers should have commas (or dots, depending on current language)
2 parents 8909e14 + 96a1305 commit 0416612

File tree

3 files changed

+49
-11
lines changed

3 files changed

+49
-11
lines changed

public/locales/en/dataset.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -300,12 +300,12 @@
300300
},
301301
"downloads": {
302302
"count": {
303-
"default_zero": "{{count}} Downloads",
304-
"default_one": "{{count}} Download",
305-
"default_other": "{{count}} Downloads",
306-
"preMDC_zero": "{{count}} Downloads pre-MDC",
307-
"preMDC_one": "{{count}} Download pre-MDC",
308-
"preMDC_other": "{{count}} Downloads pre-MDC"
303+
"default_zero": "{{formattedCount}} Downloads",
304+
"default_one": "{{formattedCount}} Download",
305+
"default_other": "{{formattedCount}} Downloads",
306+
"preMDC_zero": "{{formattedCount}} Downloads pre-MDC",
307+
"preMDC_one": "{{formattedCount}} Download pre-MDC",
308+
"preMDC_other": "{{formattedCount}} Downloads pre-MDC"
309309
},
310310
"defaultTip": "Total aggregated downloads of files in this dataset.",
311311
"preMakeDataCountTip": "Downloads prior to enabling MDC. Counts do not have the same filtering and detail as MDC metrics.",

src/sections/dataset/dataset-metrics/DatasetMetrics.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ interface DatasetMetricsProps {
1111
}
1212

1313
export const DatasetMetrics = ({ datasetRepository, datasetId }: DatasetMetricsProps) => {
14-
const { t } = useTranslation('dataset')
14+
const { t, i18n } = useTranslation('dataset')
1515
const {
1616
downloadCount: downloadCountIncludingMDC,
1717
isLoadingDownloadCount: isLoadingDownloadCountIncludingMDC,
@@ -29,6 +29,10 @@ export const DatasetMetrics = ({ datasetRepository, datasetId }: DatasetMetricsP
2929
}
3030

3131
const isMDCenabled = checkIsMDCenabled(downloadCountIncludingMDC?.MDCStartDate)
32+
const classicCount = downloadCountNotIncludingMDC?.downloadCount ?? 0
33+
const mdcCount = downloadCountIncludingMDC?.downloadCount ?? 0
34+
const formatNumber = (value: number) =>
35+
new Intl.NumberFormat(i18n.languages[0] || undefined).format(value)
3236

3337
if (isLoadingDownloadCountIncludingMDC || isLoadingDownloadCountNotIncludingMDC) {
3438
return <DatasetMetricsSkeleton />
@@ -66,7 +70,8 @@ export const DatasetMetrics = ({ datasetRepository, datasetId }: DatasetMetricsP
6670
{!isMDCenabled && (
6771
<span data-testid="classic-download-count">
6872
{t('metrics.downloads.count.default', {
69-
count: downloadCountNotIncludingMDC?.downloadCount
73+
count: classicCount,
74+
formattedCount: formatNumber(classicCount)
7075
})}{' '}
7176
<QuestionMarkTooltip placement="top" message={t('metrics.downloads.defaultTip')} />
7277
</span>
@@ -77,7 +82,8 @@ export const DatasetMetrics = ({ datasetRepository, datasetId }: DatasetMetricsP
7782
<div className={styles['mdc-count']} data-testid="mdc-download-count">
7883
<span>
7984
{t('metrics.downloads.count.default', {
80-
count: downloadCountIncludingMDC.downloadCount
85+
count: mdcCount,
86+
formattedCount: formatNumber(mdcCount)
8187
})}{' '}
8288
<QuestionMarkTooltip
8389
placement="top"
@@ -86,10 +92,11 @@ export const DatasetMetrics = ({ datasetRepository, datasetId }: DatasetMetricsP
8692
</span>
8793

8894
{/* If we have downloads before MDC was enabled, we show them also. */}
89-
{downloadCountNotIncludingMDC && downloadCountNotIncludingMDC.downloadCount > 0 && (
95+
{classicCount > 0 && (
9096
<small>
9197
{`(+${t('metrics.downloads.count.preMDC', {
92-
count: downloadCountNotIncludingMDC.downloadCount
98+
count: classicCount,
99+
formattedCount: formatNumber(classicCount)
93100
})})`}{' '}
94101
<QuestionMarkTooltip
95102
placement="top"

src/stories/dataset/dataset-metrics/DatasetMetrics.stories.tsx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,34 @@ export const WithoutMakeDataCountEnabled: Story = {
3232
export const WithMakeDataCountEnabled: Story = {
3333
render: () => <DatasetMetrics datasetRepository={new DatasetMockRepository()} datasetId={1} />
3434
}
35+
36+
export const WithBigNumbersMDCEnabled: Story = {
37+
render: () => {
38+
const datasetMockRepoWithBigNumbers = new DatasetMockRepository()
39+
40+
datasetMockRepoWithBigNumbers.getDownloadCount = (
41+
_datasetId: number | string,
42+
includeMDC: boolean
43+
) => {
44+
return new Promise((resolve) => {
45+
setTimeout(() => {
46+
if (includeMDC) {
47+
resolve(
48+
DatasetDownloadCountMother.createWithMDCStartDate({
49+
downloadCount: 1495020
50+
})
51+
)
52+
} else {
53+
resolve(
54+
DatasetDownloadCountMother.createWithoutMDCStartDate({
55+
downloadCount: 365900
56+
})
57+
)
58+
}
59+
}, FakerHelper.loadingTimout())
60+
})
61+
}
62+
63+
return <DatasetMetrics datasetRepository={datasetMockRepoWithBigNumbers} datasetId={1} />
64+
}
65+
}

0 commit comments

Comments
 (0)