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

feature: allow params on resource menu item #1957

Merged
merged 2 commits into from
Oct 9, 2023

Conversation

bryszard
Copy link
Contributor

@bryszard bryszard commented Sep 29, 2023

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 the resource method on the MenuBuilder. 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 library active_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:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works

Video QA

2023-09-29.07-45-48.mp4

Manual review steps

  1. Open the Avo app on local environment
  2. Click on the Users resource and check the path

Manual reviewer: please leave a comment with output from the test if that's the case.

@codeclimate
Copy link

codeclimate bot commented Sep 29, 2023

Code Climate has analyzed commit 2656bf5 and detected 0 issues on this pull request.

View more on Code Climate.

@bryszard
Copy link
Contributor Author

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.

def fetch_params
Avo::ExecutionContext.new(
target: params,
resource: resource
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
resource: resource
resource: parsed_resource

@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Avo::App.guess_resource resource.to_s
@parsed_resource ||= Avo::App.guess_resource resource.to_s

@Paul-Bob
Copy link
Contributor

Paul-Bob commented Oct 3, 2023

Thank you for this amazing PR @bryszard! I let some tweaks suggestions and also added the tags so don't worry about it.

@Paul-Bob Paul-Bob merged commit 99a8d26 into avo-hq:main Oct 9, 2023
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow resource menu items to receive params
2 participants