-
-
Notifications
You must be signed in to change notification settings - Fork 254
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
when remove_scope_all, the first load is not filtering by the first scope #2402
Comments
Hello @jetienne that is indeed the wanted and expected behavior, there isn't a way yet to apply a default scope and the We debated it when implemented Possible APIS to be implemented: def scopes
remove_scope_all
scope Avo::Scopes::CustomAll
default_scope Avo::Scopes::Admins
end def scopes
remove_scope_all
scope Avo::Scopes::CustomAll
scope Avo::Scopes::Admins, default: -> { true }
end As a possible workaround for now you can add params on the menu link something like |
@Paul-Bob Thanks. But what's the point of hiding a tab (All) if you still display the content in it ? This super counter-intuitive for the users! IMHO, default: -> { true } is the way to go, since you can have some dynamic default-ing based on some context... |
@Paul-Bob I tried your workaround, works like a charm. I would not even call it a workaround IMHO, it's just the way to set the default scope... :D |
@jetienne I called it workaround because it works only when that link is clicked, for example when the table is rendered on a association context ( i.e. I'm also inclined to the |
Related comment: #2276 (comment) |
I see the need for some dynamic way to set and unset the default scope. I mean # this looks better
if current_user.admin?
default_scope CLASS
else
default_scope ANOTHER_CLASS
end
# than this
scope CLASS, default: -> { current_user.admin? }
scope ANOTHER_CLASS, default: -> { !current_user.admin? } We're just choosing one. |
Let's do a quick analyze to the above snippet scope CLASS, default: -> { current_user.admin? }
scope ANOTHER_CLASS, default: -> { !current_user.admin? } Result: With this API when user is admin, CLASS will be the default scope but ANOTHER_CLASS will still there as not selected. if current_user.admin?
default_scope CLASS
else
default_scope ANOTHER_CLASS
end Result: With this API when user is admin, CLASS will be the default and only present scope, ANOTHER_CLASS would not even be visible since was declared on the else that is never executed. This is weird IMHO, if you want always both scopes but different default you would need to do something like: if current_user.admin?
default_scope CLASS
scope ANOTHER_CLASS
else
default_scope ANOTHER_CLASS
scope CLASS
end From a distant perspective none are great. One makes you duplicate and invert the logic inside def scopes
scope CLASS
scope ANOTHER_CLASS
scope ONE_MORE_CLASS
end
# Called to define the default scope class
self.default_scope = -> do
if current_user.admin?
CLASS
else
ANOTHER_CLASS
end
end One last thought: It seems to me that people would expect the first scope as always the default one after removing the |
Yes, in the absence of any other default, I would expect the first scope listed to be the default when landing on the resource index page. |
Yes. That's my expectation as well. |
Another nice to have would be to have the first scope applied without changing the URL. So if |
Ensure that if default scope visible block return true page loads without any scope: #2587 |
Describe the bug
On a given resource
deals
, add some scopes like:When accessing the URL /admin/resources/deals, the content initially appears unfiltered. However, selecting the first tab refreshes the page and correctly applies the filters to the displayed data.
Expected behavior & Actual behavior
When
all
scope is removed, the first scope is correctly being displayed.System configuration
Avo version:
3.3.0
Rails version:
7.1.3
Ruby version:
3.3.0
License type:
Are you using Avo monkey patches, overriding views or view components?
Screenshots or screen recordings
https://www.loom.com/share/8c60793f3815495bb7d431a284325002?sid=3eba226a-c7c6-4f14-9cdc-e9e3ee9e322b
Impact
Urgency
The text was updated successfully, but these errors were encountered: