Skip to content

Commit

Permalink
Render small or zero rate estimates as <1 alert per week
Browse files Browse the repository at this point in the history
Fixes #1857.
  • Loading branch information
lpsinger committed Jun 8, 2024
1 parent c95516e commit 40a352b
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions app/components/NoticeTypeCheckboxes/NoticeTypeCheckboxes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,20 @@ import type { NoticeFormat } from '../NoticeFormat'
import { NestedCheckboxes } from '../nested-checkboxes/NestedCheckboxes'
import { triggerRate } from './rates'

const minRate = 1 / 7

function humanizedCount(count: number, singular: string, plural?: string) {
const noun = count === 1 ? singular : plural ?? `${singular}s`
return `${count} ${noun}`
}

function humanizedRate(rate: number, singular: string, plural?: string) {
let isUpperBound
if (rate < minRate) {
isUpperBound = true
rate = minRate
}

let unit = 'day'
if (rate) {
for (const { factor, unit: proposedUnit } of [
Expand All @@ -30,7 +38,7 @@ function humanizedRate(rate: number, singular: string, plural?: string) {
if (rate > 0.5) break
}
}
return `${humanizedCount(Math.round(rate), singular, plural)} per ${unit}`
return `${isUpperBound ? '< ' : ''}${humanizedCount(Math.round(rate), singular, plural)} per ${unit}`
}

const NoticeTypes = {
Expand Down Expand Up @@ -280,7 +288,7 @@ export function NoticeTypeCheckboxes({
childoncheckhandler={counterfunction}
/>
<div className="text-bold text-ink">
{humanizedCount(selectedCounter, 'notice type')} selected for about{' '}
{humanizedCount(selectedCounter, 'notice type')} selected for{' '}
{humanizedRate(alertEstimate, 'alert')}
</div>
</>
Expand Down

0 comments on commit 40a352b

Please sign in to comment.