Skip to content

Commit

Permalink
Merge pull request #1456 from moonshine-software/in-dropdown
Browse files Browse the repository at this point in the history
feat: IndexButtons/QueryTags in dropdown
  • Loading branch information
lee-to authored Jan 9, 2025
2 parents e75cb3e + 72bf8a6 commit e9d9160
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/Contracts/src/UI/ActionButtonContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace MoonShine\Contracts\UI;

use Closure;
use Illuminate\Support\Traits\Conditionable;
use MoonShine\Contracts\Core\PageContract;
use MoonShine\Contracts\Core\ResourceContract;
use MoonShine\Contracts\Core\TypeCasts\DataWrapperContract;
Expand All @@ -17,6 +18,8 @@
*
* @extends HasModalContract<TModal>
* @extends HasOffCanvasContract<TOffCanvas>
*
* @mixin Conditionable
*/
interface ActionButtonContract extends
ComponentContract,
Expand Down
6 changes: 5 additions & 1 deletion src/Laravel/src/Pages/Crud/IndexPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace MoonShine\Laravel\Pages\Crud;

use MoonShine\Contracts\UI\ActionButtonContract;
use MoonShine\Contracts\UI\ComponentContract;
use MoonShine\Contracts\UI\TableBuilderContract;
use MoonShine\Core\Exceptions\ResourceException;
Expand Down Expand Up @@ -176,7 +177,10 @@ protected function getQueryTags(): array
static function (ActionGroup $group) use ($resource): ActionGroup {
foreach ($resource->getQueryTags() as $tag) {
$group->add(
QueryTagButton::for($resource, $tag)
QueryTagButton::for($resource, $tag)->when(
$resource->isQueryTagsInDropdown(),
fn (ActionButtonContract $btn): ActionButtonContract => $btn->showInDropdown()
)
);
}

Expand Down
17 changes: 17 additions & 0 deletions src/Laravel/src/Traits/Resource/ResourceWithButtons.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@

trait ResourceWithButtons
{
protected bool $queryTagsInDropdown = false;

protected bool $indexButtonsInDropdown = false;

public function isQueryTagsInDropdown(): bool
{
return $this->queryTagsInDropdown;
}

public function isIndexButtonsInDropdown(): bool
{
return $this->indexButtonsInDropdown;
}

/**
* @return ListOf<ActionButtonContract>
*/
Expand Down Expand Up @@ -101,6 +115,9 @@ public function getIndexButtons(): ActionButtonsContract
{
return ActionButtons::make(
$this->indexButtons()->toArray(),
)->when(
$this->isIndexButtonsInDropdown(),
fn (ActionButtonsContract $buttons) => $buttons->map(fn (ActionButtonContract $button): ActionButtonContract => $button->showInDropdown())
);
}

Expand Down

0 comments on commit e9d9160

Please sign in to comment.