Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert togglecolumn $state if condition unsatisfied. #14359

Open
Sze-Huang opened this issue Sep 26, 2024 · 4 comments
Open

Revert togglecolumn $state if condition unsatisfied. #14359

Sze-Huang opened this issue Sep 26, 2024 · 4 comments
Labels
Milestone

Comments

@Sze-Huang
Copy link

Sze-Huang commented Sep 26, 2024

Package

filament/filament

Package Version

^3.2

Laravel Version

^11.9

Livewire Version

^3.0

PHP Version

^8.2

Problem description

I have togglecolumn on table. when

ToggleColumn::make( 'confirmed' )
    ->label( 'Confirmed' )
    ->updateStateUsing( function ($record, $state): bool {
        $user = auth()->user();
        if ($user->hasRole( 'admin' )) {
            return $state; // Confirm toggle on success
        } else {
            Notification::make()
              ->title( 'Action Blocked' )
              ->body( 'You do not have permission to change this status.' )
              ->color( 'danger' )
              ->warning()
              ->send();
            throw ValidationException::withMessages( [] );
        }
    } ),

if the togglecolumn is currently false, when toggle from false to true, if the condition didn't meet, the toggle stay at false.

the problem is
if the togglecolumn is currently true, when toggle from true to false, if the condition didnt meet, the toggle will still move to false. if refresh the page, the toggle will show true again.

Expected behavior

when condition not met, the toggle should stay at original state.

Steps to reproduce

  1. try with user's email not end with @admin.com
  2. User table status toggle from false to true, works as intended (toggle wont move).
  3. User table status toggle from true to false, toggle move to false (should be not moving). after refresh will show toggle is true.

Reproduction repository (issue will be closed if this is not valid)

https://github.com/Sze-Huang/filament-togglecolumn-issue

Relevant log output

No response

Donate 💰 to fund this issue

  • You can donate funding to this issue. We receive the money once the issue is completed & confirmed by you.
  • 100% of the funding will be distributed between the Filament core team to run all aspects of the project.
  • Thank you in advance for helping us make maintenance sustainable!
Fund with Polar
Copy link

Hey @Sze-Huang! We're sorry to hear that you've hit this issue. 💛

However, it looks like you forgot to fill in the reproduction repository URL. Can you edit your original post and then we'll look at your issue?

We need a public GitHub repository which contains a Laravel app with the minimal amount of Filament code to reproduce the problem. Please do not link to your actual project, what we need instead is a minimal reproduction in a fresh project without any unnecessary code. This means it doesn't matter if your real project is private / confidential, since we want a link to a separate, isolated reproduction. That would allow us to download it and review your bug much easier, so it can be fixed quicker. Please make sure to include a database seeder with everything we need to set the app up quickly.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Sep 26, 2024
Copy link

Thank you for providing reproduction steps! Reopening the issue now.

@github-actions github-actions bot reopened this Sep 26, 2024
@zepfietje
Copy link
Member

No reproduction repository.

@zepfietje zepfietje closed this as not planned Won't fix, can't repro, duplicate, stale Sep 27, 2024
@zepfietje zepfietje added this to the v3 milestone Sep 27, 2024
@Sze-Huang
Copy link
Author

No reproduction repository.

Updated reproduction repository, and steps to reproduce.

@zepfietje zepfietje reopened this Sep 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Todo
Development

No branches or pull requests

2 participants