From 98867afb49387a12fe5b87e704c41a559bed0487 Mon Sep 17 00:00:00 2001 From: Herbert Maschke Date: Mon, 10 Jun 2024 10:04:06 +0200 Subject: [PATCH] introduce auto_open --- CHANGELOG.md | 45 +++++++++++++++++++--------------- config/filament-comments.php | 9 +++++-- src/Actions/CommentsAction.php | 20 ++++++++++++++- 3 files changed, 51 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d6880a2..9e16e76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,46 +2,51 @@ All notable changes to `filament-comments` will be documented in this file. +# 1.4.0 - to be released + +- introduce an "auto_open" config parameter to automatically open the comments slide-over when + at least one comment is attached to the model (Credit thyseus@shopauskunft) + # 1.3.1 - June 6, 2024 -- Fixes missing closing bracket +- Fixes missing closing bracket # 1.3.0 - June 6, 2024 -- Adds Persian translations 🇮🇷 (Credit [@amiralidev](https://github.com/amiralidev)) -- Adds ability to define custom comment model class (Credit [@ziming](https://github.com/ziming)) -- Adds markdown editor support (Credit [@ziming](https://github.com/ziming)) -- Eager loads comment user (Credit [@ziming](https://github.com/ziming)) +- Adds Persian translations 🇮🇷 (Credit [@amiralidev](https://github.com/amiralidev)) +- Adds ability to define custom comment model class (Credit [@ziming](https://github.com/ziming)) +- Adds markdown editor support (Credit [@ziming](https://github.com/ziming)) +- Eager loads comment user (Credit [@ziming](https://github.com/ziming)) # 1.2.0 - Mar 15, 2024 -- Adds German transations 🇩🇪 (Credit [@dissto](https://github.com/dissto)) -- Adds Norwegian translations 🇳🇴 (Credit [@Jonas-johansen](https://github.com/Jonas-johansen)) -- Database table name can now be set in the config file (Credit [@pelmered](https://github.com/pelmered)) -- Adds Laravel 11 support (Credit [@ConnorHowell](https://github.com/ConnorHowell)) +- Adds German transations 🇩🇪 (Credit [@dissto](https://github.com/dissto)) +- Adds Norwegian translations 🇳🇴 (Credit [@Jonas-johansen](https://github.com/Jonas-johansen)) +- Database table name can now be set in the config file (Credit [@pelmered](https://github.com/pelmered)) +- Adds Laravel 11 support (Credit [@ConnorHowell](https://github.com/ConnorHowell)) ## 1.1.0 - Feb 13, 2024 -- Adds Brazilian Portuguese translations 🇧🇷 (Credit [@patriciomartinns](https://github.com/patriciomartinns)) -- Adds Italian translations 🇮🇹 (Credit [@Askancy](https://github.com/Askancy)) -- Adds Russian translations 🇷🇺 (Credit [@PetroZaburko](https://github.com/PetroZaburko)) -- Adds Ukrainian translations 🇺🇦 (Credit [@PetroZaburko](https://github.com/PetroZaburko)) -- Adds authenticatable model class in config file (Credit [@PetroZaburko](https://github.com/PetroZaburko)) -- Adds support for morph maps (Credit [@pelmered](https://github.com/pelmered)) +- Adds Brazilian Portuguese translations 🇧🇷 (Credit [@patriciomartinns](https://github.com/patriciomartinns)) +- Adds Italian translations 🇮🇹 (Credit [@Askancy](https://github.com/Askancy)) +- Adds Russian translations 🇷🇺 (Credit [@PetroZaburko](https://github.com/PetroZaburko)) +- Adds Ukrainian translations 🇺🇦 (Credit [@PetroZaburko](https://github.com/PetroZaburko)) +- Adds authenticatable model class in config file (Credit [@PetroZaburko](https://github.com/PetroZaburko)) +- Adds support for morph maps (Credit [@pelmered](https://github.com/pelmered)) ## 1.0.3 - Jan 31, 2024 -- Adds Dutch translations 🇳🇱 (Credit [@CodeWithDennis](https://github.com/CodeWithDennis)) +- Adds Dutch translations 🇳🇱 (Credit [@CodeWithDennis](https://github.com/CodeWithDennis)) ## 1.0.2 - Jan 31, 2024 -- Adds default action icon value to the configuration file -- Adds comment pruning section to the documentation +- Adds default action icon value to the configuration file +- Adds comment pruning section to the documentation ## 1.0.1 - Jan 30, 2024 -- Removes redundant stubs call during installation +- Removes redundant stubs call during installation ## 1.0.0 - Jan 30, 2024 -- Initial release +- Initial release diff --git a/config/filament-comments.php b/config/filament-comments.php index 286b622..9a3d96d 100644 --- a/config/filament-comments.php +++ b/config/filament-comments.php @@ -33,7 +33,6 @@ */ 'prune_after_days' => 30, - /* * Options: 'rich', 'markdown' */ @@ -66,9 +65,15 @@ */ 'authenticatable' => \App\Models\User::class, - /* * The name of the table where the comments are stored. */ 'table_name' => 'filament_comments', + + /* + * Automatically open the comment slideover when at least + * one comment is attached. Useful if you dont want comments + * to be overlooked accidetally: + */ + 'auto_open' => false, ]; diff --git a/src/Actions/CommentsAction.php b/src/Actions/CommentsAction.php index 5112c20..5cbe825 100644 --- a/src/Actions/CommentsAction.php +++ b/src/Actions/CommentsAction.php @@ -4,6 +4,8 @@ use Filament\Actions\Action; use Filament\Support\Enums\MaxWidth; +use Filament\Support\Facades\FilamentView; +use Filament\View\PanelsRenderHook; use Illuminate\Contracts\View\View; use Parallax\FilamentComments\Models\FilamentComment; @@ -18,17 +20,33 @@ protected function setUp(): void { parent::setUp(); + $count = $this->record->filamentComments()->count(); + + if (config('filament-comments.auto_open') && $count > 0) { + FilamentView::registerRenderHook( + PanelsRenderHook::BODY_END, + fn (): string => << + window.addEventListener("load", (event) => { + document.getElementById("toggle-comments").click() + }); + + JS + ); + } + $this ->hiddenLabel() ->icon(config('filament-comments.icons.action')) ->color('gray') - ->badge($this->record->filamentComments()->count()) + ->badge($count) ->slideOver() ->modalContentFooter(fn (): View => view('filament-comments::component')) ->modalHeading(__('filament-comments::filament-comments.modal.heading')) ->modalWidth(MaxWidth::Medium) ->modalSubmitAction(false) ->modalCancelAction(false) + ->extraAttributes(['id' => 'toggle-comments']) ->visible(fn (): bool => auth()->user()->can('viewAny', config('filament-comments.comment_model'))); } }