Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit d1d4ebf

Browse files
committed
proper fix for notification's plural text
1 parent a551663 commit d1d4ebf

File tree

2 files changed

+20
-30
lines changed

2 files changed

+20
-30
lines changed

src/constants/notifications.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,14 +1291,7 @@ export const NOTIFICATIONS = [
12911291
type: NOTIFICATION_TYPE.TAAS,
12921292
rules: [
12931293
{
1294-
textIsPlural: true,
1295-
text: "{{numOfExpiringResourceBookings}} resource bookings are expiring in the team <strong>{{teamName}}</strong>",
1296-
shouldBundle: false,
1297-
goTo: GOTO.TAAS_PROJECT,
1298-
},
1299-
{
1300-
textIsPlural: false,
1301-
text: "{{numOfExpiringResourceBookings}} resource booking is expiring in the team <strong>{{teamName}}</strong>",
1294+
text: "{{numOfExpiringResourceBookings}} resource booking{{pluralize numOfExpiringResourceBookings '' 's'}} {{pluralize numOfExpiringResourceBookings 'is' 'are'}} expiring in the team <strong>{{teamName}}</strong>",
13021295
shouldBundle: false,
13031296
goTo: GOTO.TAAS_PROJECT,
13041297
},

src/utils/notifications.js

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,27 @@ const handlebarsFallbackHelper = (value, fallbackValue) => {
5959
return new Handlebars.SafeString(out);
6060
};
6161

62+
/**
63+
* Handlebars helper which displays single or plural noun
64+
*
65+
* Example:
66+
* ```
67+
* {{pluralize count resource resources}}
68+
* ```
69+
* Will output `resource` if `count` equals or less than 1; otherwise `resources`
70+
*
71+
* @param {Number} count quantity
72+
* @param {String} single noun
73+
* @param {String} plural nouns
74+
*/
75+
const handlebarsPluralizeHelper = (number, single, plural) => {
76+
return number > 1 ? plural : single;
77+
};
78+
6279
// register handlebars helpers
6380
Handlebars.registerHelper("showMore", handlebarsShowMoreHelper);
6481
Handlebars.registerHelper("fallback", handlebarsFallbackHelper);
82+
Handlebars.registerHelper("pluralize", handlebarsPluralizeHelper);
6583

6684
export const renderGoTo = (goTo, contents) => {
6785
let goToHandlebars = "";
@@ -319,12 +337,6 @@ const getNotificationRule = (notification) => {
319337
);
320338
}
321339

322-
if (notification.contents.textIsPlural != null) {
323-
match =
324-
match &&
325-
notification.contents.textIsPlural === _notificationRule.textIsPlural;
326-
}
327-
328340
return match;
329341
});
330342

@@ -352,7 +364,6 @@ const isNotificationRuleEqual = (rule1, rule2) => {
352364
"projectRole",
353365
"topcoderRole",
354366
"originator",
355-
"textIsPlural",
356367
];
357368
const essentialRule1 = _.pick(rule1, ESSENTIAL_RULE_PROPERTIES);
358369
const essentialRule2 = _.pick(rule2, ESSENTIAL_RULE_PROPERTIES);
@@ -579,17 +590,6 @@ export const preRenderNotifications = (notifications) => {
579590

580591
// --- TaaS --- //
581592

582-
const prepareTaaSNotificationContents = (eventType, contents) => {
583-
if (eventType === EVENT_TYPE.TAAS.RESOURCE_BOOKING_EXPIRATION) {
584-
return {
585-
...contents,
586-
textIsPlural: contents.numOfExpiringResourceBookings > 1,
587-
};
588-
}
589-
590-
return contents;
591-
};
592-
593593
export const prepareTaaSNotifications = (rawNotifications) => {
594594
const notifications = rawNotifications.map((rawNotification) => ({
595595
id: `${rawNotification.id}`,
@@ -603,10 +603,7 @@ export const prepareTaaSNotifications = (rawNotifications) => {
603603
date: rawNotification.createdAt,
604604
isRead: rawNotification.read,
605605
seen: rawNotification.seen,
606-
contents: prepareTaaSNotificationContents(
607-
rawNotification.type,
608-
rawNotification.contents
609-
),
606+
contents: rawNotification.contents,
610607
version: rawNotification.version,
611608
}));
612609

0 commit comments

Comments
 (0)