Skip to content

Commit

Permalink
add click record behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
mokhosh committed Nov 29, 2023
1 parent d05a94f commit 1950e9b
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 1 deletion.
21 changes: 21 additions & 0 deletions resources/views/components/edit-record-modal.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<x-filament-panels::form wire:submit.prevent="onEditModalFormSubmit">
<x-filament::modal id="kanban--edit-modal-form" :width="$this->getEditModalWidth()">
<x-slot name="header">
<x-filament::modal.heading>
{{ $this->getEditModalTitle() }}
</x-filament::modal.heading>
</x-slot>

{{ $this->editModalForm }}

<x-slot name="footer">
<x-filament::button type="submit">
{{$this->getEditModalSaveButtonLabel()}}
</x-filament::button>

<x-filament::button color="gray" x-on:click="isOpen = false">
{{$this->getEditModalCancelButtonLabel()}}
</x-filament::button>
</x-slot>
</x-filament::modal>
</x-filament-panels::form>
2 changes: 2 additions & 0 deletions resources/views/kanban-board.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@
@include('filament-kanban::kanban-scripts')
</div>
</div>

<x-filament-kanban::edit-record-modal/>
</x-filament-panels::page>
1 change: 1 addition & 0 deletions resources/views/kanban-record.blade.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<div
id="{{ $record['id'] }}"
wire:click="recordClicked('{{ $record['id'] }}', {{ @json_encode($record) }})"
class="record bg-white rounded border px-4 py-2 cursor-grab font-medium text-gray-600"
>
{{ $record['title'] }}
Expand Down
94 changes: 94 additions & 0 deletions src/Concerns/HasEditRecordModal.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php

namespace Mokhosh\FilamentKanban\Concerns;

trait HasEditRecordModal
{
public array $editModalFormState = [];

public ?int $editModalRecordId = null;

protected string $editModalTitle = 'Edit Record';

protected string $editModalWidth = '2xl';

protected string $editModalSaveButtonLabel = "Save";

protected string $editModalCancelButtonLabel = "Cancel";

public function recordClicked($recordId, $data): void
{
$this->editModalRecordId = $recordId;

$this->editModalForm->fill($this->getEditModalRecordData($recordId, $data));

$this->dispatch('open-modal', id: 'kanban--edit-modal-form');
}

public function getEditModalRecordData($recordId, $data): array
{
return $data;
}

protected function getEditModalTitle(): string
{
return $this->editModalTitle;
}

protected function getEditModalWidth(): string
{
return $this->editModalWidth;
}

protected function getEditModalSaveButtonLabel(): string
{
return $this->editModalSaveButtonLabel;
}

protected function getEditModalCancelButtonLabel(): string
{
return $this->editModalCancelButtonLabel;
}

//

public function onEditModalFormSubmit(): void
{
$this->editRecord($this->editModalRecordId, $this->editModalForm->getState(), $this->editModalFormState);

$this->dispatch('close-modal', id: 'kanban--edit-modal-form');
}

public function editRecord($recordId, array $data, array $state): void
{
// Override this function and do whatever you want with $data
}

protected function getEditModalFormSchema(int|null $recordId): array
{
return [];
}

protected function getEditModalForm(): array
{
return [
'editModalForm' => $this->makeForm()
->schema($this->getEditModalFormSchema($this->editModalRecordId))
->statePath('editModalFormState'),
];
}

//

protected function setUpForms(): void
{
$this->editModalForm->fill();
}

protected function getForms(): array
{
return array_merge(
$this->getEditModalForm()
);
}
}
5 changes: 4 additions & 1 deletion src/Pages/KanbanBoard.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

namespace Mokhosh\FilamentKanban\Pages;

use Filament\Forms\Contracts\HasForms;
use Filament\Pages\Page;
use Illuminate\Support\Collection;
use Mokhosh\FilamentKanban\Concerns\HasEditRecordModal;
use Mokhosh\FilamentKanban\Concerns\RespondsToStatusChange;

class KanbanBoard extends Page
class KanbanBoard extends Page implements HasForms
{
use RespondsToStatusChange;
use HasEditRecordModal;

protected static ?string $navigationIcon = 'heroicon-o-document-text';

Expand Down

0 comments on commit 1950e9b

Please sign in to comment.