From 40351a508b151feb69c1c5c4cbfcf165d78c24f9 Mon Sep 17 00:00:00 2001 From: LT Date: Sun, 5 Jan 2025 19:17:44 +0300 Subject: [PATCH 1/3] feat: IndexButtons/QueryTags in dropdown --- src/Contracts/src/UI/ActionButtonContract.php | 3 +++ src/Laravel/src/Pages/Crud/IndexPage.php | 7 ++++++- .../src/Traits/Resource/ResourceWithButtons.php | 17 +++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/Contracts/src/UI/ActionButtonContract.php b/src/Contracts/src/UI/ActionButtonContract.php index d5ba335aa..9becd20aa 100644 --- a/src/Contracts/src/UI/ActionButtonContract.php +++ b/src/Contracts/src/UI/ActionButtonContract.php @@ -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; @@ -17,6 +18,8 @@ * * @extends HasModalContract * @extends HasOffCanvasContract + * + * @mixin Conditionable */ interface ActionButtonContract extends ComponentContract, diff --git a/src/Laravel/src/Pages/Crud/IndexPage.php b/src/Laravel/src/Pages/Crud/IndexPage.php index 8fcd9897d..184f0769f 100644 --- a/src/Laravel/src/Pages/Crud/IndexPage.php +++ b/src/Laravel/src/Pages/Crud/IndexPage.php @@ -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; @@ -14,6 +15,7 @@ use MoonShine\Laravel\Enums\Ability; use MoonShine\Support\Enums\JsEvent; use MoonShine\Support\Enums\PageType; +use MoonShine\UI\Components\ActionButton; use MoonShine\UI\Components\ActionGroup; use MoonShine\UI\Components\Layout\Div; use MoonShine\UI\Components\Layout\Flex; @@ -176,7 +178,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) => $btn->showInDropdown() + ) ); } diff --git a/src/Laravel/src/Traits/Resource/ResourceWithButtons.php b/src/Laravel/src/Traits/Resource/ResourceWithButtons.php index 39e58a11a..2cc004f51 100644 --- a/src/Laravel/src/Traits/Resource/ResourceWithButtons.php +++ b/src/Laravel/src/Traits/Resource/ResourceWithButtons.php @@ -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 */ @@ -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) => $button->showInDropdown()) ); } From 851dc06d52d3fc83b93a7ebb4518e500fbc2536e Mon Sep 17 00:00:00 2001 From: lee-to Date: Sun, 5 Jan 2025 16:18:47 +0000 Subject: [PATCH 2/3] [rector] Rector fixes --- src/Laravel/src/Pages/Crud/IndexPage.php | 3 +-- src/Laravel/src/Traits/Resource/ResourceWithButtons.php | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Laravel/src/Pages/Crud/IndexPage.php b/src/Laravel/src/Pages/Crud/IndexPage.php index 184f0769f..a22e62f35 100644 --- a/src/Laravel/src/Pages/Crud/IndexPage.php +++ b/src/Laravel/src/Pages/Crud/IndexPage.php @@ -15,7 +15,6 @@ use MoonShine\Laravel\Enums\Ability; use MoonShine\Support\Enums\JsEvent; use MoonShine\Support\Enums\PageType; -use MoonShine\UI\Components\ActionButton; use MoonShine\UI\Components\ActionGroup; use MoonShine\UI\Components\Layout\Div; use MoonShine\UI\Components\Layout\Flex; @@ -180,7 +179,7 @@ static function (ActionGroup $group) use ($resource): ActionGroup { $group->add( QueryTagButton::for($resource, $tag)->when( $resource->isQueryTagsInDropdown(), - fn(ActionButtonContract $btn) => $btn->showInDropdown() + fn(ActionButtonContract $btn): ActionButtonContract => $btn->showInDropdown() ) ); } diff --git a/src/Laravel/src/Traits/Resource/ResourceWithButtons.php b/src/Laravel/src/Traits/Resource/ResourceWithButtons.php index 2cc004f51..c3316bec4 100644 --- a/src/Laravel/src/Traits/Resource/ResourceWithButtons.php +++ b/src/Laravel/src/Traits/Resource/ResourceWithButtons.php @@ -117,7 +117,7 @@ public function getIndexButtons(): ActionButtonsContract $this->indexButtons()->toArray(), )->when( $this->isIndexButtonsInDropdown(), - fn(ActionButtonsContract $buttons) => $buttons->map(fn(ActionButtonContract $button) => $button->showInDropdown()) + fn(ActionButtonsContract $buttons) => $buttons->map(fn(ActionButtonContract $button): ActionButtonContract => $button->showInDropdown()) ); } From 72bf8a603b7c969a0e57f5ae92fb4b5475ebdf23 Mon Sep 17 00:00:00 2001 From: lee-to Date: Sun, 5 Jan 2025 16:19:11 +0000 Subject: [PATCH 3/3] Fix styling --- src/Laravel/src/Pages/Crud/IndexPage.php | 2 +- src/Laravel/src/Traits/Resource/ResourceWithButtons.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Laravel/src/Pages/Crud/IndexPage.php b/src/Laravel/src/Pages/Crud/IndexPage.php index a22e62f35..c546a3445 100644 --- a/src/Laravel/src/Pages/Crud/IndexPage.php +++ b/src/Laravel/src/Pages/Crud/IndexPage.php @@ -179,7 +179,7 @@ static function (ActionGroup $group) use ($resource): ActionGroup { $group->add( QueryTagButton::for($resource, $tag)->when( $resource->isQueryTagsInDropdown(), - fn(ActionButtonContract $btn): ActionButtonContract => $btn->showInDropdown() + fn (ActionButtonContract $btn): ActionButtonContract => $btn->showInDropdown() ) ); } diff --git a/src/Laravel/src/Traits/Resource/ResourceWithButtons.php b/src/Laravel/src/Traits/Resource/ResourceWithButtons.php index c3316bec4..048818052 100644 --- a/src/Laravel/src/Traits/Resource/ResourceWithButtons.php +++ b/src/Laravel/src/Traits/Resource/ResourceWithButtons.php @@ -117,7 +117,7 @@ public function getIndexButtons(): ActionButtonsContract $this->indexButtons()->toArray(), )->when( $this->isIndexButtonsInDropdown(), - fn(ActionButtonsContract $buttons) => $buttons->map(fn(ActionButtonContract $button): ActionButtonContract => $button->showInDropdown()) + fn (ActionButtonsContract $buttons) => $buttons->map(fn (ActionButtonContract $button): ActionButtonContract => $button->showInDropdown()) ); }