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

View Components for /admin #605

Merged
merged 14 commits into from Aug 19, 2022
Merged

View Components for /admin #605

merged 14 commits into from Aug 19, 2022

Conversation

joemasilotti
Copy link
Owner

@joemasilotti joemasilotti commented Aug 18, 2022

This PR is my first deep dive into generic, styled, reusable View Components. The codebase already has a fair amount of existing ones. But they weren't built in a way that makes them easily reusable.

The ones introduced in this PR are more generic to specific use-cases: styled tables in an admin context. I'm using this as a pressure test to see how I could add more components like these to the rest of the app.

Notes and thoughts

  • app/views/admin/users/index.html.erb looks real clean now!
  • Using #call directly in the .rb file of a component for simple layout cleans up the code quite a bit. There's no additional .html.erb file!
  • Working inside-out seemed to work better (in this example) than outside-in. Working outside-in made it a bit harder to conceptualize how the components played together.
  • I'm not sold on passing "first" into components to style them differently. Ideally, that could be handled by the parent component. But I haven't figured out how to do that yet.
    • I restyled the table headers a bit so the concept of "first" no longer exists.
  • I punted on anything related to Action View Form Helpers. There doesn't seem to be a good way to integrate these helpers with View Component (yet), so I opted to ignore them for now.
    • I went ahead and injected the Rails form object directly into the View Components. I understand that this tightly couples them, but it feels like an OK trade-off for now. I still get to use all the nice Rails helpers we all know and love.
  • title || content is a nice shortcut to be able to pass in a string or a block to render more custom content in a component.
  • render TableComponent.new do |table| over render TableComponent.new do |component| - makes it easier to understand which component you are chaining off of when nested.

@joemasilotti joemasilotti merged commit 289b9f5 into main Aug 19, 2022
5 checks passed
@joemasilotti joemasilotti deleted the admin-view-components branch August 19, 2022 22:16
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.

None yet

1 participant