Skip to content

Add custom look#2803

Open
goosys wants to merge 6 commits intothoughtbot:mainfrom
goosys:feature/looks
Open

Add custom look#2803
goosys wants to merge 6 commits intothoughtbot:mainfrom
goosys:feature/looks

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.

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?

goosys and others added 3 commits January 24, 2026 10:03
@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.

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.

I think this is good, just the minor comments. The one thing that I think is missing is simple tests to check that the example looks are working. I would write something like spec/example_app/spec/features/field_looks_spec.rb and examples checking some simple HTML: the <img> tags and the <optgroup> tag should do the trick.

Note that I would put these under spec/example_app/spec instead of under spec because they are things that I think users of Administrate should be testing when they customise their dashboards (it's their own code!), as opposed to things that Administrate should guarantee.

goosys and others added 3 commits February 14, 2026 13:29
Co-authored-by: Pablo Brasero <36066+pablobm@users.noreply.github.com>
Co-authored-by: Pablo Brasero <36066+pablobm@users.noreply.github.com>
@goosys
Copy link
Contributor Author

goosys commented Feb 14, 2026

@pablobm
Thank you for the review. I've made the requested changes and pushed a new commit.

(The failing tests are due to a separate Ruby 4–related issue.)

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