-
-
Notifications
You must be signed in to change notification settings - Fork 256
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
feature: allow params on resource menu item #1957
feature: allow params on resource menu item #1957
Conversation
Code Climate has analyzed commit 2656bf5 and detected 0 issues on this pull request. View more on Code Climate. |
Documentations changes - avo-hq/docs.avohq.io#114 According to the Contributing guide I should add some tags to the PR, but I don't know how. I can't change labels. When it comes to the Checklist point "I have commented my code, particularly in hard-to-understand areas" - I don't think there is part of the code that would require commenting. Correct me if I'm wrong. |
lib/avo/menu/resource.rb
Outdated
def fetch_params | ||
Avo::ExecutionContext.new( | ||
target: params, | ||
resource: resource |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resource: resource | |
resource: parsed_resource |
lib/avo/menu/resource.rb
Outdated
@@ -3,6 +3,7 @@ class Avo::Menu::Resource < Avo::Menu::BaseItem | |||
|
|||
option :resource | |||
option :label, optional: true | |||
option :params, default: proc { {} } | |||
|
|||
def parsed_resource | |||
Avo::App.guess_resource resource.to_s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avo::App.guess_resource resource.to_s | |
@parsed_resource ||= Avo::App.guess_resource resource.to_s |
Thank you for this amazing PR @bryszard! I let some tweaks suggestions and also added the tags so don't worry about it. |
Description
Fixes #1651
Docs https://docs.avohq.io/2.0/menu-editor.html
In this Pull Request I'm adding an option to pass
params
to theresource
method on theMenuBuilder
. It can be a Hash or a Proc that will return a Hash.Whatever is passed as
params
will be added to the path of the menu item, when navigating to it.Before this PR, there was a POC on which @Paul-Bob helped me understand the scope of the changes to be done.
In the POC we've identified one caveat for future users of the feature - we don't support having multiple menu items for the same resource, but with different params. The reason is simple - if we have two menu items with the same path, they would be both highlighted as
active
when visited. The workarounds for that using current libraryactive_link_for
are imperfect and substituting it right now has no point.As @Paul-Bob stated here - we already have a feature to achieve the goal of having different filters for the same resource applied and these are the scopes.
With this feature it will be possible to add some default params to the menu item, which don't necessarily need to be the filters.
Checklist:
Video QA
2023-09-29.07-45-48.mp4
Manual review steps
Users
resource and check the pathManual reviewer: please leave a comment with output from the test if that's the case.