-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
base: main
Are you sure you want to change the base?
Conversation
577a77d
to
1fe7873
Compare
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.
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?
if prefix = find_partial_prefix(field) | ||
render locals: locals, partial: "#{prefix}/#{field.page}" | ||
end |
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.
What if prefix is nil
here? No render?
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.
No render, No Exception.
lib/administrate/field/base.rb
Outdated
@@ -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 |
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.
Perhaps we can do something more flexible, like if superclass.respond_to?(:_partial_prefixes)
?
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.
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
1fe7873
to
2084605
Compare
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 |
2084605
to
5027f67
Compare
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