Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate Widget Permission for Stats Widgets #471

Open
mahdimirhendi opened this issue Dec 19, 2024 · 3 comments
Open

Generate Widget Permission for Stats Widgets #471

mahdimirhendi opened this issue Dec 19, 2024 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@mahdimirhendi
Copy link

The method FilamentShield::getLocalizedWidgetLabel($widget['class']) in HasShieldFormComponents.php is unable to generate the permission label for Counter widgets. This issue occurs because the getHeading() method is inherited from BaseWidget for Counter widgets, which always evaluates as true in the following code:
$widgetInstance = app()->make($widget); return match (true) { $widgetInstance instanceof TableWidget => (string) invade($widgetInstance)->makeTable()->getHeading(), !($widgetInstance instanceof TableWidget) && $widgetInstance instanceof Widget && method_exists($widgetInstance, 'getHeading') => (string) invade($widgetInstance)->getHeading(), default => str($widget)->afterLast('\\')->headline()->toString(), };
Since getHeading() is defined in BaseWidget, the condition always evaluates to true, even when no actual heading is set for the Counter widget. As a result, the widget name is not displayed when no heading is provided for Counter widgets.

To resolve this issue, we should modify the condition on line 313 in filament-shield.php to ensure that a non-null heading is required for Counter widgets. The fix could look like this:
!($widgetInstance instanceof TableWidget) && $widgetInstance instanceof Widget && method_exists($widgetInstance, 'getHeading') && invade($widgetInstance)->getHeading() != null
This will prevent the method from returning a label for Counter widgets when no heading is explicitly set, im not sure if its a clean way to handle this issue or not ,

@mahdimirhendi mahdimirhendi added the bug Something isn't working label Dec 19, 2024
@bezhanSalleh
Copy link
Owner

what are counter widgets?

@mahdimirhendi
Copy link
Author

mahdimirhendi commented Dec 19, 2024

Sorry, it’s called the ‘Stats Widget’ (for displaying counters like user quantities).
https://filamentphp.com/docs/3.x/widgets/stats-overview/

@mahdimirhendi mahdimirhendi changed the title Generate Widget Permission for Counter Widgets Generate Widget Permission for Stats Widgets Dec 19, 2024
@bezhanSalleh
Copy link
Owner

Duplicate of #447. To actually patch, it's gonna take sometime cause I'm swamped atm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants