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

Introduce partial search similar to Rails #2467

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

goosys
Copy link
Contributor

@goosys goosys commented Dec 7, 2023

Introduced partial search similar to Rails, as an alternative to to_partial_path.

Models that have an inheritance relationship often use similar or almost identical partials.
Being able to reuse partials not only makes it easier to create new fields, but also improves maintainability.

I tried deleting the HasManyVariant partial as a test, and it continues to operate normally using the HasMany partial.
Pleach check customers.log_entries field.
http://localhost:3000/admin/customers
http://localhost:3000/admin/customers/4

Please review.


refs
https://github.com/rails/rails/blob/d39db5d1891f7509cde2efc425c9d69bbb77e670/actionview/lib/action_view/view_paths.rb#L23-L29 https://github.com/rails/rails/blob/d39db5d1891f7509cde2efc425c9d69bbb77e670/actionview/lib/action_view/view_paths.rb#L72-L77

Copy link
Collaborator

@pablobm pablobm left a comment

Choose a reason for hiding this comment

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

Just saw this for the first time and it caught my eye. Let's come back to it after the PRs we are working on now. Perhaps it can also help solving #2049?

Comment on lines 12 to 14
if prefix = find_partial_prefix(field)
render locals: locals, partial: "#{prefix}/#{field.page}"
end
Copy link
Collaborator

Choose a reason for hiding this comment

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

What if prefix is nil here? No render?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No render, No Exception.

@@ -32,6 +32,21 @@ def self.permitted_attribute(attr, _options = nil)
attr
end

def self._partial_prefixes
@_partial_prefixes ||= begin
if superclass == Administrate::Field::Base
Copy link
Collaborator

Choose a reason for hiding this comment

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

Perhaps we can do something more flexible, like if superclass.respond_to?(:_partial_prefixes)?

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 tried it, but it didn’t work.
Since Field::Base itself also has _partial_prefixes, the prefixes end up including fields/base.

  12) Administrate::Field::Number#_partial_prefixes returns a partial based on the page being rendered
      Failure/Error: expect(prefixes).to eq(["fields/number"])
     
        expected: ["fields/number"]
             got: ["fields/number", "fields/base"]
      

Do you have any ideas?
Should we add abstract? to Field::Base, similar to Rails?
https://github.com/rails/rails/blob/d39db5d1891f7509cde2efc425c9d69bbb77e670/actionview/lib/action_view/view_paths.rb#L23-L29

@goosys
Copy link
Contributor Author

goosys commented Oct 4, 2024

Thank you for checking. I'm not sure if this will help with #2049. It seems like solving 2049 might require implementing a new feature, such as an option to specify a custom partial.

For now, I’ve rebased on the latest main and checked it with standardrb.
I'll address the feedback separately. Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants