From bbd2a5079f7c8846f84d939b5f7bf6a1f0cb500d Mon Sep 17 00:00:00 2001 From: Harmit Goswami Date: Fri, 29 Nov 2024 14:31:38 -0500 Subject: [PATCH] Addressed review comments --- pontoon/base/forms.py | 10 +++---- .../widgets/notifications_menu.html | 2 ++ pontoon/teams/static/js/permissions.js | 28 ++++++++----------- .../templates/teams/includes/permissions.html | 9 +++--- pontoon/teams/views.py | 6 ++-- pontoon/translations/views.py | 6 ++-- translate/public/translate.html | 2 -- .../user/components/UserNotification.tsx | 5 ++-- 8 files changed, 32 insertions(+), 36 deletions(-) diff --git a/pontoon/base/forms.py b/pontoon/base/forms.py index 181cb26864..217d79c2b0 100644 --- a/pontoon/base/forms.py +++ b/pontoon/base/forms.py @@ -93,7 +93,7 @@ def __init__(self, *args, **kwargs): self.user = kwargs.pop("user") super().__init__(*args, **kwargs) # Track if user reached new level for Community Builder Badge - self.community_builder_level = 0 + self.community_builder_level_reached = 0 def assign_users_to_groups(self, group_name, users): """ @@ -142,7 +142,7 @@ def save(self, *args, **kwargs): after_count > before_count and after_count in settings.BADGES_PROMOTION_THRESHOLDS ): - self.community_builder_level = ( + self.community_builder_level_reached = ( settings.BADGES_PROMOTION_THRESHOLDS.index(after_count) + 1 ) desc = """ @@ -152,7 +152,7 @@ def save(self, *args, **kwargs):
You can view this badge on your profile page . """.format( - level=self.community_builder_level, + level=self.community_builder_level_reached, profile_href=reverse( "pontoon.contributors.contributor.username", kwargs={ @@ -163,11 +163,11 @@ def save(self, *args, **kwargs): notify.send( sender=self.user, recipient=self.user, - verb="", # Triggers render of description only + verb="ignore", # Triggers render of description only description=desc, ) - return self.community_builder_level + return self.community_builder_level_reached class ProjectLocalePermsForm(UserPermissionLogFormMixin, forms.ModelForm): diff --git a/pontoon/contributors/templates/contributors/widgets/notifications_menu.html b/pontoon/contributors/templates/contributors/widgets/notifications_menu.html index 0f528ef5f6..00ee2800d3 100644 --- a/pontoon/contributors/templates/contributors/widgets/notifications_menu.html +++ b/pontoon/contributors/templates/contributors/widgets/notifications_menu.html @@ -76,7 +76,9 @@ + {% if notification.verb != 'ignore' %} {{ notification.verb.replace("has added a comment in", "has added a comment") }} + {% endif %} {% if target %} diff --git a/pontoon/teams/static/js/permissions.js b/pontoon/teams/static/js/permissions.js index e99a3f89fc..2fb1fafc3f 100644 --- a/pontoon/teams/static/js/permissions.js +++ b/pontoon/teams/static/js/permissions.js @@ -46,6 +46,8 @@ $(function () { }); }); + const $tooltip = $('#badge-tooltip-container'); + $.ajax({ url: $('#permissions-form').prop('action'), type: $('#permissions-form').prop('method'), @@ -56,23 +58,12 @@ $(function () { // Check for new badge notification if (badgeLevel > 0) { - const $tooltip = $('#badge-tooltip-container'); - - if ($tooltip.length) { - $tooltip.show(); + $tooltip.show(); - // Force a re-render of the text with the proper badge level - $tooltip - .find('p:nth-of-type(2)') - .text( - `Community Builder Badge level gained: Level ${badgeLevel}`, - ); - - $tooltip.find('button').one('click', function (e) { - e.preventDefault(); - $tooltip.hide(); - }); - } + // Force a re-render of the text with the proper badge level + $tooltip + .find('.badge-tooltip-info') + .text(`Community Builder Badge level gained: Level ${badgeLevel}`); const duration = 2000; const animationEnd = Date.now() + duration; @@ -113,6 +104,11 @@ $(function () { Pontoon.endLoader('Oops, something went wrong.', 'error'); }, }); + + $tooltip.find('button').one('click', function (e) { + e.preventDefault(); + $tooltip.hide(); + }); }); // Switch available users diff --git a/pontoon/teams/templates/teams/includes/permissions.html b/pontoon/teams/templates/teams/includes/permissions.html index 83722307b4..408c0b6c19 100644 --- a/pontoon/teams/templates/teams/includes/permissions.html +++ b/pontoon/teams/templates/teams/includes/permissions.html @@ -3,11 +3,10 @@
- -
-

New badge level gained!

-

-

+ +
+

New badge level gained!

+

You can view your new badge on your profile page.

diff --git a/pontoon/teams/views.py b/pontoon/teams/views.py index 413c97421b..2c14d92484 100644 --- a/pontoon/teams/views.py +++ b/pontoon/teams/views.py @@ -168,7 +168,7 @@ def ajax_permissions(request, locale): locale = get_object_or_404(Locale, code=locale) project_locales = locale.project_locale.visible().visible_for(request.user) - community_builder_level = 0 + community_builder_level_reached = 0 if request.method == "POST": locale_form = forms.LocalePermsForm( request.POST, instance=locale, prefix="general", user=request.user @@ -181,7 +181,7 @@ def ajax_permissions(request, locale): ) if locale_form.is_valid() and project_locale_form.is_valid(): - community_builder_level = locale_form.save() + community_builder_level_reached = locale_form.save() project_locale_form.save() else: @@ -250,7 +250,7 @@ def ajax_permissions(request, locale): "project_locale_form": project_locale_form, "project_locales": project_locales, "hide_project_selector": hide_project_selector, - "community_builder_badge": community_builder_level, + "community_builder_level_reached": community_builder_level_reached, }, ) diff --git a/pontoon/translations/views.py b/pontoon/translations/views.py index 35c1d30080..839e52384a 100644 --- a/pontoon/translations/views.py +++ b/pontoon/translations/views.py @@ -202,7 +202,7 @@ def create_translation(request): notify.send( sender=user, recipient=user, - verb="", # Triggers render of description only + verb="ignore", # Triggers render of description only description=desc, ) @@ -370,7 +370,7 @@ def approve_translation(request): notify.send( sender=user, recipient=user, - verb="", # Triggers render of description only + verb="ignore", # Triggers render of description only description=desc, ) @@ -529,7 +529,7 @@ def reject_translation(request): notify.send( sender=request.user, recipient=request.user, - verb="", # Triggers render of description only + verb="ignore", # Triggers render of description only description=desc, ) diff --git a/translate/public/translate.html b/translate/public/translate.html index 31b0d60eda..ff3fae5a85 100644 --- a/translate/public/translate.html +++ b/translate/public/translate.html @@ -11,8 +11,6 @@ - - Pontoon diff --git a/translate/src/modules/user/components/UserNotification.tsx b/translate/src/modules/user/components/UserNotification.tsx index 00ccd369d6..2d991709e2 100644 --- a/translate/src/modules/user/components/UserNotification.tsx +++ b/translate/src/modules/user/components/UserNotification.tsx @@ -39,7 +39,7 @@ const Comment = ({ {actor.anchor} - {verb} + {verb !== 'ignore' && {verb}} {target.anchor} @@ -79,7 +79,8 @@ const Other = ({ - {verb.replace('has added a comment in', 'has added a comment')} + {verb !== 'ignore' && + verb.replace('has added a comment in', 'has added a comment')} {!target ? null : (