Repository: internetarchive/openlibrary

Issue:
Add notification bubble on Main Nav for super-librarians # pending MRs
<!-- A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] -->

### Describe the problem that you'd like solved
<!-- A clear and concise description of what you want to happen. -->

Options are to add a bubble to the avatar and then a entry + bubble into the sub-navigation within the hamburger

![testing openlibrary org_merges_mode=closed](https://user-images.githubusercontent.com/978325/182037307-3ba26478-0b2e-4fc3-9676-a63fd4e87dba.png)

Or to add a bubble directly to the black IA topbar which when clicked goes directly to /merges

![testing openlibrary org_merges_mode=closed (1)](https://user-images.githubusercontent.com/978325/182037463-db0a2ca7-45c7-44ad-9238-146a5ea37daa.png)

```
.mr-notifications {
    position: absolute;
    z-index: 4;
    background: #02598b;
    color: white;
    border-radius: 8px;
    padding: 3px 7px;
    font-size: 12px;
    margin-left: 9px;
    margin-top: 35px;
    font-weight: bold;
 }
```

### Proposal & Constraints
<!-- What is the proposed solution / implementation? Is there a precedent of this approach succeeding elsewhere? -->

<!-- Which suggestions or requirements should be considered for how feature needs to appear or be implemented? -->

### Additional context
<!-- Add any other context or screenshots about the feature request here. -->

### Stakeholders
<!-- @ tag stakeholders of this bug -->





Discussion:
Hi @mekarpeles. I have just started contributing to open source and I would like to work on this. Can you please explain "entry + bubble into the sub-navigation within the hamburger"? Thanks
I believe that @mekarpeles is asking for a new link to be added to the navigation drawer that is opened when the avatar is clicked:
![Screenshot from 2022-08-03 21-25-10](https://user-images.githubusercontent.com/28732543/182743071-a0f21457-3bbc-4f80-97db-9a05b53f1acb.png)

The entry can be something like "Pending Requests", and appear in the "My Open Library" section.  A bubble can also be added to the new entry.

The new entry should only appear for members of `/usergroup/admin` and `/usergroup/super-librarians`.

The bubble should contain the number of "Pending" merge requests, and should not appear if there are no such requests.

One can get the pending merge request counts by passing `mode='open'` the this method:
https://github.com/internetarchive/openlibrary/blob/851864fdb37ba789f5170234638c11fe431af9d3/openlibrary/core/edits.py#L74

Both the avatar and navigation drawer are in the same template: https://github.com/internetarchive/openlibrary/blob/master/openlibrary/templates/lib/header_dropdown.html

That template takes a dict defining the drawer's headings and links.  That dict is defined in this file: https://github.com/internetarchive/openlibrary/blob/master/openlibrary/templates/lib/nav_head.html

Lastly, the template for the IA top bar is: https://github.com/internetarchive/openlibrary/blob/master/openlibrary/templates/site/alert.html

The bubble should be added to either the IA top bar or the avatar, but not both.
Hello! I am a new contributor and would like to work on this issue. Does it is still available? If yes, could you assign me, please, @jimchamp?
@SyedMa3, are you still interested in working on this?
@ciannellaleo if there is no response from @SyedMa3 by this time tomorrow, consider yourself assigned. 
@jimchamp Yes, I have been going through the codebase. Can you assign me the issue? Thanks.

Resolving patch:
diff --git a/openlibrary/core/edits.py b/openlibrary/core/edits.py
--- a/openlibrary/core/edits.py
+++ b/openlibrary/core/edits.py
@@ -6,6 +6,8 @@
 from infogami.utils.view import public
 
 from openlibrary.i18n import gettext as _
+from openlibrary.core import cache
+from openlibrary.utils import dateutil
 
 from . import db
 
@@ -325,3 +327,12 @@ def create_comment(cls, username: str, message: str) -> dict[str, str]:
             "message": message,
             # XXX It may be easier to update these comments if they had IDs
         }
+
+
+@public
+def cached_get_counts_by_mode(mode='all', **kwargs):
+    return cache.memcache_memoize(
+        CommunityEditsQueue.get_counts_by_mode,
+        f"librarian_queue_counts_{mode}",
+        timeout=dateutil.MINUTE_SECS,
+    )(mode, **kwargs)


Test patch: