fix(sidebar): hide badge wrapper when callback returns empty string#2009
Open
mezo-dev wants to merge 5 commits into
Open
fix(sidebar): hide badge wrapper when callback returns empty string#2009mezo-dev wants to merge 5 commits into
mezo-dev wants to merge 5 commits into
Conversation
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2008 — Empty red badge renders in sidebar when badge callback returns an empty string
Problem
When a sidebar item's
badgeis configured as a dotted-path string (callback), the red badge wrapper is always rendered — even when the callback returns an empty string. This leaves an empty coloured rectangle in the sidebar.Root cause
In
unfold/sites.py, whenitem["badge"]is a string, the callback is imported and stored asitem["badge_callback"] = lazy(callback)(request), butitem["badge"]is left as the original dotted-path string.In
unfold/templates/unfold/helpers/app_list_badge.html, the wrapper guard is:item.badgehere is the path string (e.g."myapp.badges.unread_count"), which is always truthy — so the<span>always renders. When the callback resolves to"", the inner content is empty but the wrapper stays, producing the empty box.Fix
Resolve the lazy callback to a string first and only render the wrapper when the resolved text is non-empty. Behaviour for literal-string badges (no callback) is unchanged.
Screenshots
Before: empty red box next to the menu item when count = 0.
After: no badge at all when count = 0; badge with text when count > 0.