From 4d22a8c27126919ae2784e98aec69756148c3c44 Mon Sep 17 00:00:00 2001 From: Lukas Frey Date: Tue, 7 May 2024 13:03:43 +0200 Subject: [PATCH] fix: add option to open documentation in new tab Signed-off-by: Lukas Frey --- resources/views/livewire/help-menu.blade.php | 5 ++++- resources/views/sidebar-footer.blade.php | 3 ++- src/Filament/Panels/KnowledgeBasePanel.php | 1 + src/KnowledgeBasePlugin.php | 15 +++++++++++++++ src/Livewire/HelpMenu.php | 11 ++++++++++- 5 files changed, 32 insertions(+), 3 deletions(-) diff --git a/resources/views/livewire/help-menu.blade.php b/resources/views/livewire/help-menu.blade.php index 16f0f9a..8ac20a3 100644 --- a/resources/views/livewire/help-menu.blade.php +++ b/resources/views/livewire/help-menu.blade.php @@ -1,8 +1,10 @@ @php use Filament\Facades\Filament; + $hasModalPreviews = Filament::getPlugin('guava::filament-knowledge-base')->hasModalPreviews(); $hasSlideOverPreviews = Filament::getPlugin('guava::filament-knowledge-base')->hasSlideOverPreviews(); $hasModalTitleBreadcrumbs = Filament::getPlugin('guava::filament-knowledge-base')->hasModalTitleBreadcrumbs(); + $target = Filament::getPlugin('guava::filament-knowledge-base')->shouldOpenDocumentationInNewTab() ? '_blank' : '_self'; @endphp
getSimpleHtml() !!} + :href="$documentable->getUrl()" + :target="$target"> {{ __('filament-knowledge-base::translations.open-documentation') }} + :url="$url" + :should-open-url-in-new-tab="$shouldOpenDocumentationInNewTab"> view('filament-knowledge-base::sidebar-footer', [ 'active' => Filament::getCurrentPanel()->getId() === config('filament-knowledge-base.panel.id', 'knowledge-base'), 'url' => Filament::getPanel(config('filament-knowledge-base.panel.id', 'knowledge-base'))->getUrl(), + 'shouldOpenDocumentationInNewTab' => false, ]) ) diff --git a/src/KnowledgeBasePlugin.php b/src/KnowledgeBasePlugin.php index 5d6b6e7..3df1ae9 100644 --- a/src/KnowledgeBasePlugin.php +++ b/src/KnowledgeBasePlugin.php @@ -16,6 +16,8 @@ class KnowledgeBasePlugin implements Plugin protected bool $modalTitleBreadcrumbs = false; + protected bool $openDocumentationInNewTab = false; + protected string $helpMenuRenderHook = PanelsRenderHook::TOPBAR_END; public function helpMenuRenderHook(string $renderHook): static @@ -51,6 +53,13 @@ public function modalTitleBreadcrumbs(bool $condition = true): static return $this; } + public function openDocumentationInNewTab(bool $condition = true): static + { + $this->openDocumentationInNewTab = $condition; + + return $this; + } + public function hasModalPreviews(): bool { return $this->modalPreviews; @@ -66,6 +75,11 @@ public function hasModalTitleBreadcrumbs(): bool return $this->modalTitleBreadcrumbs; } + public function shouldOpenDocumentationInNewTab(): bool + { + return $this->openDocumentationInNewTab; + } + public function getId(): string { return 'guava::filament-knowledge-base'; @@ -83,6 +97,7 @@ public function register(Panel $panel): void fn (): string => view('filament-knowledge-base::sidebar-footer', [ 'active' => Filament::getCurrentPanel()->getId() === config('filament-knowledge-base.panel.id', 'knowledge-base'), 'url' => Filament::getPanel(config('filament-knowledge-base.panel.id', 'knowledge-base'))->getUrl(), + 'shouldOpenDocumentationInNewTab' => $this->shouldOpenDocumentationInNewTab(), ]) ) ; diff --git a/src/Livewire/HelpMenu.php b/src/Livewire/HelpMenu.php index e50a681..d5769ee 100644 --- a/src/Livewire/HelpMenu.php +++ b/src/Livewire/HelpMenu.php @@ -6,6 +6,7 @@ use Filament\Actions\ActionGroup; use Filament\Actions\Concerns\InteractsWithActions; use Filament\Actions\Contracts\HasActions; +use Filament\Facades\Filament; use Filament\Forms\Concerns\InteractsWithForms; use Filament\Forms\Contracts\HasForms; use Filament\Resources\Pages\Page; @@ -22,10 +23,14 @@ class HelpMenu extends Component implements HasActions, HasForms public array $documentation; + protected bool $shouldOpenDocumentationInNewTab; + public function mount(): void { $controller = request()->route()->controller; + $this->shouldOpenDocumentationInNewTab = Filament::getPlugin('guava::filament-knowledge-base')->shouldOpenDocumentationInNewTab(); + $this->documentation = Arr::wrap(match (true) { $controller instanceof HasKnowledgeBase => $controller::getDocumentation(), $controller instanceof Page && in_array(HasKnowledgeBase::class, class_implements($controller::getResource())) => $controller::getResource()::getDocumentation(), @@ -46,6 +51,7 @@ public function actions(): array // ->map(fn (string $class) => KnowledgeBasePanel::getDocumentationAction($class)) ->map( fn (Documentable $documentable) => HelpAction::forDocumentable($documentable) + ->openUrlInNewTab($this->shouldOpenDocumentationInNewTab) ) ->toArray() ; @@ -58,7 +64,10 @@ public function shouldShowAsMenu(): bool public function getSingleAction(): HelpAction { - return HelpAction::forDocumentable($this->getDocumentation()->first())->generic(); + return HelpAction::forDocumentable($this->getDocumentation()->first()) + ->generic() + ->openUrlInNewTab($this->shouldOpenDocumentationInNewTab) + ; } public function getMenuAction(): ActionGroup