invaders-xx / filament-kanban-board
Add a Kanban page to filament
Installs: 15 718
Dependents: 0
Suggesters: 0
Security: 0
Stars: 79
Watchers: 1
Forks: 15
Open Issues: 2
Requires
- php: ^8.0
- filament/filament: ^3.0-stable
- illuminate/contracts: ^8.74|^9.0|^10.0|^11.0
- spatie/laravel-package-tools: ^1.9.2
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.8
- nunomaduro/collision: ^6.0|^7.0|^8.0
- nunomaduro/larastan: ^2.0.1
- orchestra/testbench: ^7.0|^8.0|^9.0
- pestphp/pest: ^1.21
- pestphp/pest-plugin-laravel: ^1.1
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^9.5|^10.0
- spatie/laravel-ray: ^1.26
README
Define a Kanban page within your Filament's application. It can be a page or a resource's page.
Installation
You can install the package via composer:
composer require invaders-xx/filament-kanban-board
You can publish the config file with:
php artisan vendor:publish --tag="filament-kanban-board-config"
This is the contents of the published config file:
return [
];
Optionally, you can publish the views using
php artisan vendor:publish --tag="filament-kanban-board-views"
You can also specify your own view for record content to change the behaviour:
public string $recordContentView = 'filament-kanban-board::record-content';
in your class to add more content to your kanban's boxes.
You can define your own styles for each element of the Kanban:
protected function styles(): array { return [ 'wrapper' => 'w-full h-full flex space-x-4 overflow-x-auto', 'kanbanWrapper' => 'h-full flex-1', 'kanban' => 'bg-primary-200 rounded px-2 flex flex-col h-full', 'kanbanHeader' => 'p-2 text-sm text-gray-900', 'kanbanFooter' => '', 'kanbanRecords' => 'space-y-2 p-2 flex-1 overflow-y-auto', 'record' => 'shadow bg-white dark:bg-gray-800 p-2 rounded border', 'recordContent' => 'w-full', ]; }
Usage
In order to use this component, you must create a new Filament Page that extends from FilamentKanbanBoard
class KanbanOrders extends FilamentKanbanBoard { protected function statuses() : Collection { return collect([ [ 'id' => 'registered', 'title' => 'Registered', ], [ 'id' => 'awaiting_confirmation', 'title' => 'Awaiting Confirmation', ], [ 'id' => 'confirmed', 'title' => 'Confirmed', ], [ 'id' => 'delivered', 'title' => 'Delivered', ], ]); } }
For each status we define, we must return an array with at least 2 keys: id and title.
Now, for records() we may define a list of Sales Orders that come from an Eloquent model in your project.
protected function records() : Collection { return SalesOrder::all() ->map(function (SalesOrder $item) { return [ 'id' => $item->id, 'title' => $item->customer->name, 'status' => $item->status, ]; }); }
As you might see in the above snippet, we must return a collection of array items where each item must have at least 3 keys: id, title and status. The last one is of most importance since it is going to be used to match to which status the record belongs to. For this matter, the component matches status and records with the following comparison.
$status['id'] == $record['status'];
if you need to use this page within a Filament's resource, add the route function definition to the class:
public static function route(string $path): array { return [ 'class' => static::class, 'route' => $path, ]; }
Sorting and Dragging
By default, sorting and dragging between statuses is disabled. To enable it, set in your class:
public bool $sortable = true; public bool $sortableBetweenStatuses = true;
Behavior and Interactions
When sorting and dragging is enabled, your component can be notified when any of these events occur. The callbacks
triggered by these two events are onStatusSorted
and onStatusChanged
On onStatusSorted
you are notified about which record
has changed position within it's status
. You are also given
a $orderedIds
array which holds the ids of the records
after being sorted. You must override the following method to
get notified on this change.
public function onStatusSorted($recordId, $statusId, $orderedIds) { // }
On onStatusChanged
gets triggered when a record
is moved to another status
. In this scenario, you get notified
about the record
that was changed, the new status
, the ordered ids from the previous status and the ordered ids of
the new status the record in entering. To be notified about this event, you must override the following method:
public function onStatusChanged($recordId, $statusId, $fromOrderedIds, $toOrderedIds) { // }
onStatusSorted
and onStatusChanged
are never triggered simultaneously. You'll get notified of one or the other when
an interaction occurs.
You can also get notified when a record in the status board is clicked via the onRecordClick
event
public function onRecordClick($recordId) { // }
To enable onRecordClick
set it in the class:
public bool $recordClickEnabled = true;
Editing records in Modal window
You can enable Modal window to edit records:
Make sure to have $recordClickEnabled
set to true
and $modalRecordClickEnabled
set to true
:
public bool $recordClickEnabled = true; public bool $modalRecordClickEnabled = true;
You can set modal title, width, save / cancel button labels:
protected string $editModalRecordTitle = 'Edit modal record title'; protected string $editModalRecordWidth = '2xl'; public string $editModalSaveButtonLabel = "Save"; public string $editModalCancelButtonLabel = "Cancel";
You can set Form components by overriding function getEditModalRecordSchema()
:
protected static function getEditModalRecordSchema(): array { return [ TextInput::make('title'), TextInput::make('status'), ]; }
To call Modal with Form override onRecordClick()
function and add the following:
public function onRecordClick($recordId, $data): void { $this->editModalRecord->fill($data); $this->dispatchBrowserEvent('open-modal', ['id' => 'kanban--edit-modal-record']); }
To manipulate with data from the Modal Form override editRecord()
function:
public function editRecord(array $data): void { }
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.