filament-comments
filament-comments copied to clipboard
Hide form option
Like I wrote about in issue #7, I wanted to have the form only in a modal and display the comments in an infolist. I think this UX works better as the infolist should be view/read only and I want it as compact as possible to avoid scrolling.
This is a working example with the modal as a headerAction on a section:
Section::make('Admin comments')
->headerActions([
Action::make('Add comment')
->form(function (Form $form, Booking $booking) {
$comments = new CommentsComponent();
$comments->record = $booking;
return $comments->form($form);
})
->action(function (array $data, Booking $booking): void {
CommentsComponent::macro('fillForm', function ($data) {
$this->form->fill($data);
});
$comments = new CommentsComponent();
$comments->record = $booking;
$comments->fillForm($data);
$comments->create();
})
])
->columnSpanFull()
->schema([
CommentsEntry::make('filament_comments')->withoutForm(),
]),
It looks like this:
Possible enhancements:
- The comments list does not refresh when you submit a new comment in the modal. You need to refresh the page for the new comment to show up.
- Split the form into it's own component to make this even easier/cleaner to do. It would also be nice with an action that you can use directly, or even a method that returns this whole section.