moonshine-software / moonshine

Laravel Admin panel and more. Simple for beginners and powerful for experts. Using Blade, Alpine.js and Tailwind CSS.
https://moonshine-laravel.com
MIT License
714 stars 94 forks source link

Tag set to default not deselectable #1167

Closed anxgstadler closed 1 month ago

anxgstadler commented 1 month ago

MoonShine Version

2.21.1

Laravel Version

11.20.0

PHP Version

8.3

Database Driver & Version

PostgreSQL

Description

I have a resource page that shows entities that have an is_active flag. I added a single Tag called "Show active only" that filters for entities where is_active = true. Since the list should only show active entries by default, I set this Tag to be active by default.

But now I can't deselect the tag in order to show all entities regardless of their state: When I click the tag button, the same page shows again, with the tag still being active.

How can I deselect a tag that is active by default?

(If I don't set it as default, the tag button behaves correctly, I can set and unset it by clicking on it.)

Steps To Reproduce

public function queryTags(): array
{
    return [
        QueryTag::make(
            'Show active only',
            fn(Builder $query) => $query->where('is_active', true)
        )->alias('show_active_only')
        ->default()
    ];
}
DissNik commented 1 month ago

There are several ways:

  1. Add another tag that will show all or only inactive
  2. Remove the default and add the query-tag=is_active get parameter to the menu url
anxgstadler commented 1 month ago

Thanks for your reply!

As far as I understand it, tags can be selected or deselcted by themselves, so there should be no need for a second tag to disable the first one. (Or if in fact there is, the documentation should say so.) Currently the documentation only says that if you want to make a tag selected from the beginning, call the default() method.

Thanks for the workaround with the parameter in the url. :-)

anxgstadler commented 1 month ago

I tried the first approach, adding a second tag. - And indeed, when I select the second tag, the first (default) one is automatically disabled.

This would be very important to mention in the documentation. Nowhere does it say currently that tags are mutually exclusive and only one can be activated at any time. From reading the documentation I thought that I could have one tag that filters for the users' active state and a second or third tag that (additionally) filters for something else, but this seems to not be possible.

DissNik commented 1 month ago

The default tag is the one that is applied if none of the tags is selected, the query-tag parameter is missing

The main use of the default tag is: all->default | active | inactive

It really needs to be added to the documentation that the default tag cannot be the only one. Thank you