Menu Item withBadgeIf Issues #5949
Unanswered
tylernathanreed
asked this question in
Ideas & Feature Requests
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Description
Context
I was trying to add a badge to a menu item that used a count as a badge. In my specific case, I have a "Support Ticket" resource, and the badge indicates the number of unassigned tickets (prompting an admin to go in and assign them).
This worked just fine, until I received a request from the business to only show the count when it was non-zero.
This sounds like a simple request, but doing it with the existing Nova technology was awkward.
Option 1: Duplicate the Query
At first, I tried this:
It gets the job done, but it looks weird, and requires making a query call twice.
Option 2: Separate the Calculation & Definition
I also considered doing this:
But I don't like this approach, as I have tons of menu items, and moving the calculation far away from the definition isn't ideal.
Additionally, this didn't actually apply the badge. Apparently, when a non-closure value is passed in, it must be string. This wasn't documented anywhere, and I wasted a lot of time figuring this out. This is due to the
withBadgefunction declaration, which looks like this:I get that the badge's value is expected to be a string, but more effort on the framework's part to actually accept non-string values (namely numbers and stringables) would be greatly appreciated.
Option 3: Bring in Conditionable
Menu Item's aren't normally conditionable, but I extended the class and added the trait. Doing so allowed me to do this:
This is the optional that I ultimately went with, but I felt like I had to jump through too many hoops to do something so simple.
Recommendation
A non-breaking solution to my problem would be to have the badge callback accept the result from the condition, similar to how the conditionable trait does it. Additionally, an attempt should be made to accept integer values as valid badges.
Ideally, I should be able to do this:
Yet another option is to allow the badge callback to return null (this currently throws an exception), and have null disable the badge. That tweak would allow me to do this:
Beta Was this translation helpful? Give feedback.
All reactions