dubinc / dub

Open-source link management infrastructure. Loved by modern marketing teams like Vercel, Raycast, and Perplexity.
https://dub.co
GNU Affero General Public License v3.0
18.97k stars 2.05k forks source link

Implement dynamic pluralization for click counter label #1632

Closed nabarvn closed 4 weeks ago

nabarvn commented 1 month ago

Current Behavior

The AnalyticsBadge component in link-details-column.tsx shows "clicks" as the label regardless of the count value. For example, when there is only 1 click, it still displays "1 clicks" which is grammatically incorrect.

Expected Behavior

The label should dynamically change based on the count:

Proposed Solution

Replace the current label rendering:

{label && (
  <span className="hidden md:inline-block">&nbsp;{label}</span>
)}

with:

{label && (
  <span className="hidden md:inline-block">
    &nbsp;{label.slice(0, -1)}{value !== 1 && 's'}
  </span>
)}

Contribution

I would like to work on this issue and submit a pull request with the potential fix. Please let me know if this approach sounds reasonable or if you have any suggestions for improvement.

linear[bot] commented 1 month ago

ENG-876 Implement dynamic pluralization for click counter label

unrenamed commented 1 month ago

@nabarvn Good catch! This should ideally be encapsulated in a utility function like pluralize. The function can also accept an optional plural?: string parameter to accommodate words that have custom plural forms without the standard s.

cc @steven-tey

steven-tey commented 1 month ago

Great idea, let's move this into a reusable function 👍

nabarvn commented 1 month ago

@unrenamed Thanks for the valuable suggestion!

nabarvn commented 1 month ago

Great idea, let's move this into a reusable function 👍

Roger that - is it okay if I add the reusable function in apps/web/lib/analytics/utils.ts?

steven-tey commented 1 month ago

sure thing!

nabarvn commented 4 weeks ago

@steven-tey Appreciate you. 🤝