Skip to content

Render comment edit/delete as Filament actions & allow custom actions#107

Open
ItsMalikJones wants to merge 2 commits into
mainfrom
feat/25-comment-filament-actions
Open

Render comment edit/delete as Filament actions & allow custom actions#107
ItsMalikJones wants to merge 2 commits into
mainfrom
feat/25-comment-filament-actions

Conversation

@ItsMalikJones
Copy link
Copy Markdown
Contributor

Closes #25

Summary

This PR replaces the hand-rolled comment controls (an edit icon-button wired to wire:click="edit" and a bespoke delete confirmation modal) with first-class Filament Action objects on the Comment Livewire component. It also adds an extension point so host applications can attach their own actions to each comment.

Changes

  • Filament actions for edit/delete. Introduces a HasCommentActions concern providing editAction() and deleteAction(). The delete action uses Filament's requiresConfirmation() instead of a custom modal. Visibility is gated by the existing update/delete policy checks, preserving current permission behavior.
  • Comment component now implements HasActions/HasSchemas, pulling in InteractsWithActions, InteractsWithSchemas, and ResolvesDynamicLivewireProperties.
  • Custom actions extension point. Host apps can register additional actions via Config::registerCommentActions(fn (Comment $comment) => ...), returning a single Action or an array. These render after the built-in edit/delete controls. Registered actions are cached through Filament's cacheTraitActions() hook (cacheHasCommentActions()) so that modal-opening actions stay resolvable across Livewire requests.
  • Backward compatibility. The legacy delete() and edit() Livewire methods are retained; the new actions delegate to them.
  • i18n. Adds an edit translation key across all bundled locales (ar, en, es, fr, nl, ro).

Usage

use Kirschbaum\Commentions\Config;
use Filament\Actions\Action;

Config::registerCommentActions(fn ($comment) => Action::make('activityLogs')
    ->icon('heroicon-s-clock')
    ->iconButton()
    ->modalContent(/* ... */)
);

Tests

  • Adds tests/Filament/CommentCustomActionsTest.php covering custom action registration, rendering, and the modal-caching behavior.
  • Extends tests/Livewire/CommentTest.php to exercise the new edit/delete actions and their permission gating.
  • tests/TestCase.php flushes registered comment actions between tests via Config::flushCommentActions().

…tions (#25)

Converts the hand-rolled edit icon-button and delete modal in comment.blade.php
into real Filament Action objects on the Comment Livewire component:

- editAction()/deleteAction() defined via a HasCommentActions concern; the
  delete action uses requiresConfirmation() instead of a bespoke modal.
- Visibility is gated by the existing update/delete policy checks.
- The Comment component now implements HasActions/HasSchemas.

Adds an extension point so host apps can attach their own actions (e.g. an
"Activity Logs" action) via Config::registerCommentActions(). Custom actions
are cached through Filament's cacheTraitActions() hook so modal-opening
actions stay resolvable across requests.

The legacy delete() and edit() Livewire methods are retained for backward
compatibility. Adds an `edit` translation key across all locales.
@ItsMalikJones ItsMalikJones self-assigned this May 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use Filament actions for comment actions/buttons

1 participant