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

enhancement: allow dynamic content in description and name #3693

Conversation

marlena-b
Copy link
Contributor

@marlena-b marlena-b commented Feb 25, 2025

Description

Fixes #3596

I'm not sure about this solution as there is a lot of metaprogramming that I don't fully understand.
The description already supported lambdas so I just extended it so it now has access to query. I tried to do the same for name but it cannot have access to the query as it is also used to display the text of the tab (see screenshot). When rendering these tabs we don't have access to the query.

I appreciate the feedback, and if this is not the correct way to solve this I don't mind closing this PR :)

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

Screenshots & recording

Zrzut ekranu 2025-02-25 o 18 50 10

Manual review steps

  1. Start the dummy app
  2. Open any user
  3. Notice the description of Posts relationship has a counter
  4. Notice that we use lambda in code to display the name of the relationship

Copy link

codeclimate bot commented Feb 25, 2025

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

View more on Code Climate.

@Paul-Bob Paul-Bob self-requested a review February 26, 2025 09:04
@Paul-Bob Paul-Bob added Enhancement Not necessarily a feature, but something has improved and removed Feature labels Feb 26, 2025
Copy link
Contributor

@Paul-Bob Paul-Bob left a comment

Choose a reason for hiding this comment

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

Thank you for this contribution @marlena-b it's already looking great!

I tried to do the same for name but it cannot have access to the query as it is also used to display the text of the tab (see screenshot).

I understand the challenge. Let's keep it without query access for now, and we can iterate on it later if needed.

Let's focus on the name_attributes comment.

Thank you!

Comment on lines 119 to 124
if custom_name?
return Avo::ExecutionContext.new(
target: @name,
**name_attributes
).handle
end
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we currently have any use for name_attributes? If not, we should consider removing it

def name
  if custom_name?
    Avo::ExecutionContext.new(target: @name).handle
  elsif translation_key
    translated_name default: default_name
  else
    default_name
  end
end

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wanted to keep it consistent with how the description attribute is implemented. But I also don't see how this could be used, so I will remove it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it.

Avo::Concerns::HasDescription is included in multiple classes, some within the avo repository and others across private repositories.

Each class that includes Avo::Concerns::HasDescription can define its own description_attributes. When description is called, description_attributes will vary based on the class from which it is invoked.

For name_attributes, however, we currently don’t have a similar use case.

@marlena-b marlena-b requested a review from Paul-Bob February 26, 2025 09:59
Copy link
Contributor

@Paul-Bob Paul-Bob left a comment

Choose a reason for hiding this comment

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

I just added a small tweak suggestion, otherwise, it's ready for documentation and merge!

Thanks again, @marlena-b!


if translation_key
if custom_name?
return Avo::ExecutionContext.new(target: @name).handle
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
return Avo::ExecutionContext.new(target: @name).handle
Avo::ExecutionContext.new(target: @name).handle

We don’t need an explicit return since everything is already wrapped within the if/else condition.

@Paul-Bob Paul-Bob changed the title Feature/allow dynamic content in description and name enhancement: allow dynamic content in description and name Feb 26, 2025
@marlena-b
Copy link
Contributor Author

I added docs: avo-hq/docs.avohq.io#354

@Paul-Bob
Copy link
Contributor

Awesome!! Thank you!

@Paul-Bob Paul-Bob merged commit dac4c27 into avo-hq:main Feb 26, 2025
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Not necessarily a feature, but something has improved
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fields :title and :description to allow lambda
2 participants