mansoorkhan96 / filament-versionable

Effortlessly manage revisions of your Eloquent models in Filament.
https://filamentphp.com/plugins/mansoor-versionable
MIT License
79 stars 15 forks source link

Unable to restore the first version of the model [Bug]: #22

Closed nabileisa closed 3 months ago

nabileisa commented 3 months ago

What happened?

I'm unable to restore the first version of the model , as all buttons become disabled especially when you have a single revision. I think problem is that you are comparing the current version the lastVersion version instead of the previous one and when restoring you are restoring the version in green instead of the one in red which is the previous one . My suggestion to fix this problem is to restore the version in red instead of the one in green this way all versions become restorable including the first one. To do this we need to make the following changes in the RevionsPage.php: Change the action from this :

    public function restoreVersionAction(): Action
    {
        return Action::make('restoreVersion')
            ->label(__('filament-versionable::actions.restore.label'))
            ->requiresConfirmation()
            ->modalDescription(__('filament-versionable::actions.restore.modal_description'))
            ->modalSubmitActionLabel(__('filament-versionable::actions.restore.modal_submit_action_label'))
            ->disabled(fn () => $this->version->is($this->record->lastVersion))     
            ->action(fn () => $this->restoreVersion());
    }

To this:

    public function restoreVersionAction(): Action
    {
        return Action::make('restoreVersion')
            ->label(__('filament-versionable::actions.restore.label'))
            ->requiresConfirmation()
            ->modalDescription(__('filament-versionable::actions.restore.modal_description'))
            ->modalSubmitActionLabel(__('filament-versionable::actions.restore.modal_submit_action_label'))            
             ->disabled(fn () => $this->version->is($this->record->previousVersion))
            ->action(fn () => $this->restoreVersion());
    }

And change this :

    public function restoreVersion()
    {
        $this->version->revert();
        return redirect(static::$resource::getUrl('edit', ['record' => $this->getRecord()]));
    }

To this:

    public function restoreVersion()
    {
        $this->version->previousVersion()->revert();
        return redirect(static::$resource::getUrl('edit', ['record' => $this->getRecord()]));
    }

and this should fix the problem.

How to reproduce the bug

When you create a post for example , then apply a modifications, it shows that you have 1 Revisions , but when you click the button to go to revisions page, the revision is there , but all buttons are disabled, and you are unable to restore the first revision image

Package Version

0.0.8

PHP Version

8.3.8

Laravel Version

11.18.1

Which operating systems does with happen with?

Windows

Notes

No response

mansoorkhan96 commented 3 months ago

This bug is fixed now. please update to 0.0.9