mokhosh / filament-kanban

Add kanban boards to your Filament pages
https://filamentphp.com/plugins/mokhosh-kanban
MIT License
228 stars 32 forks source link

[Bug]: Manage team relationship members #18

Closed eele94 closed 4 months ago

eele94 commented 4 months ago

What happened?

Manage team relationship members is not working when using an select.

How to reproduce the bug

Call to a member function isRelation() on null

    public static function getSchema(): array
    {
        return [
            TextInput::make('title')
                ->required(),
            Textarea::make('description')
                ->autosize(),
            Toggle::make('urgent'),
            TextInput::make('progress')->numeric(),
            Select::make('team')
                ->relationship('team', 'name')
                ->multiple()
                ->options(Filament::getTenant()->allUsers()->pluck('name', 'id'))
                ->searchable(['name', 'email'])
                ->preload()
        ];
    }
<?php

namespace App\Filament\Pages;

use App\Enums\TaskStatus;
use App\Models\Task;
use Filament\Actions\CreateAction;
use Illuminate\Database\Eloquent\Model;
use Mokhosh\FilamentKanban\Pages\KanbanBoard;

class TasksKanbanBoard extends KanbanBoard
{
    public bool $disableEditModal = false;
    protected static ?string $title = 'Tasks';
    protected static ?string $slug = 'tasks';
    protected static string $model = Task::class;
    protected static string $statusEnum = TaskStatus::class;

    protected static string $headerView = 'tasks-kanban.kanban-header';

    protected static string $recordView = 'tasks-kanban.kanban-record';

    protected static string $statusView = 'tasks-kanban.kanban-status';

    public function mount(): void
    {
        $this->form->model(static::$model);
    }

    public function getHeaderActions(): array
    {
        return [
            CreateAction::make()
                ->model(self::$model)
                ->form(self::$model::getSchema())
                ->mutateFormDataUsing(fn ($data) => array_merge($data, [
                    'user_id' => auth()->id(),
                ])),
        ];
    }

    protected function getEditModalFormSchema(?int $recordId): array
    {
        return self::$model::getSchema();
    }

    protected function getModel(int $recordId): Model
    {
        return self::$model::findOrFail($recordId);
    }

    protected function getEditModalRecordData(int $recordId, array $data): array
    {
        return $this->getModel($recordId)->toArray();
    }

    protected function editRecord(int $recordId, array $data, array $state): void
    {
        static::$model::find($recordId)->update($data);
    }
}

Package Version

2.4.0

PHP Version

8.3

Laravel Version

10

Which operating systems does with happen with?

Linux

Which browsers does with happen with?

Chrome

Notes

No response

mokhosh commented 4 months ago

Nice catch!

Fixed in https://github.com/mokhosh/filament-kanban/releases/tag/v2.5.0

eele94 commented 4 months ago

Thanks man, however it's still not working for me. Creating a Task is working, but when updating it's not using the state of the form and instead has the previous state.

mokhosh commented 4 months ago

I've added tests, and have tested manually, and it worked.

Can you please provide a reproduction repository, or a failing test, so I can see where your issue is?

eele94 commented 4 months ago

Thanks for testing. I still had a mount function to set a model which I should've removed