Skip to content

Conversation

@goosys
Copy link
Contributor

@goosys goosys commented Mar 11, 2025


Introduces a custom look implementation based on the discussion in #2291.

Changes:

  • Added look option to FieldBase
    • Added RSpec tests for FieldBase
    • Updated RSpec tests for each Field
  • Added look option to generators
    • Field generator
    • Custom Field generator
  • Updated documentation
    • Custom Dashboard
    • Field generator
    • Custom Field generator
  • Added example for changing BelongsTo look in demo app
    • product: Field::BelongsTo.with_options(look: :product_card)
    • The Product card now displays the product image and name side by side.

Please review and let me know if any changes are needed! 🚀

Usage:

class PageDashboard < Administrate::BaseDashboard
  ATTRIBUTE_TYPES = {
    product: Field::BelongsTo.with_options(look: :product_card)
  }
end
class LineItemDashboard < Administrate::BaseDashboard
  ATTRIBUTE_TYPES = {
    product: Field::BelongsTo.with_options(look: :product_card)
  }
end

/admin/pages

image

/admin/orders/:id

image

@goosys
Copy link
Contributor Author

goosys commented Mar 14, 2025

I added a sample since #2354 might also be easily resolved with looks. f280d50

/admin/products/:id/edit

image

@goosys
Copy link
Contributor Author

goosys commented Mar 20, 2025

@pablobm @nickcharlton

I've been playing around with this for the past few days, and it's incredibly fun! 🎉
I feel like this significantly expands the possibilities for customizing Administrate.
Some simple third-party custom field plugins could already be replaced with the looks feature.
Would you like to give it a try?

Also, could you update the beta tag to beta4 once looks is merged?
With virtual field, partial prefixes, and looks as the foundation, plugin development should become easier than before. Having an updated tag would be really helpful.

@nickcharlton
Copy link
Member

Yay! Thanks for doing this.

I think it's a big enough conceptual change it should probably go in after v1, if not just so that we can highlight the new functionality and it not get lost in other changes. But I'm still thinking this through!

@nickcharlton nickcharlton added views-and-styles how administrate looks and is interacted with feature new functionality that’s not yet implemented dashboards how administrate presents fields and displays data fields new fields, displaying and editing data install initial setup, first-run experience, generators generators labels Mar 20, 2025
@nickcharlton nickcharlton added this to the Post v1 milestone Mar 20, 2025
@goosys
Copy link
Contributor Author

goosys commented Mar 20, 2025

@nickcharlton

Thanks! That makes sense.

That said, since looks doesn’t break compatibility, I believe there’s no need to delay merging it. It’s stable as is, and if anything is missing, I’d be happy to help improve it further.

My application really depends on both looks and contextualize. Would it be possible to merge it now? 😭

@nickcharlton
Copy link
Member

The code change is small, but it's a big (positive) step in functionality which makes a nice highlight for a next release. I'm just trying to see if I can draw a line and get v1 done, as I've dragged my feet on it much longer than I was hoping I'd do.

I appreciate this makes things annoying for you and your application though 😭

@goosys
Copy link
Contributor Author

goosys commented Mar 20, 2025

Thank you! I really appreciate it. I’m looking forward to the completion of v1. 😊

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.

Looking great! 🙂 Let some minor comments and after that I think this is a good first feature for the post-v1 release.

def self.local_partial_prefixes
["fields/#{field_type}"]
def self.local_partial_prefixes(look: :default)
fallback = ["fields/#{field_type}/looks/default", "fields/#{field_type}"]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need to allow for default? I think it might get confusing and affect maintenance in the long run. There's already the normal option (no look), so not sure we need this.

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 don't think having both would cause significant confusion, but which approach do you prefer?

I felt that plugin developers might prefer having everything neatly organized within looks dir, so I designed it this way to allow both options.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm thinking now it's good with both. Basic fields without looks will use the normal one, while field with looks can organise their templates better.

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.

@goosys - Do you want to rebase this, and we can see if we can give it another chance?

def self.local_partial_prefixes
["fields/#{field_type}"]
def self.local_partial_prefixes(look: :default)
fallback = ["fields/#{field_type}/looks/default", "fields/#{field_type}"]
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm thinking now it's good with both. Basic fields without looks will use the normal one, while field with looks can organise their templates better.

@goosys
Copy link
Contributor Author

goosys commented Jan 24, 2026

@pablobm
Rebased.
Some time has passed since then, so I may have forgotten if there were any remaining issues. Please let me know if you notice anything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dashboards how administrate presents fields and displays data feature new functionality that’s not yet implemented fields new fields, displaying and editing data generators install initial setup, first-run experience, generators views-and-styles how administrate looks and is interacted with

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Multiple "looks" per Field

3 participants