Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introduce config parameter to auto open the slideover when at least one comment is attached #52

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 25 additions & 20 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 7 additions & 2 deletions config/filament-comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
*/
'prune_after_days' => 30,


/*
* Options: 'rich', 'markdown'
*/
Expand Down Expand Up @@ -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,
];
20 changes: 19 additions & 1 deletion src/Actions/CommentsAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 => <<<JS
<script>
window.addEventListener("load", (event) => {
document.getElementById("toggle-comments").click()
});
</script>
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')));
}
}