Skip to content

RFC: View hooks beyond Deface #3233

@tvdeyen

Description

@tvdeyen

The problem

Extensions and stores want to make additions (or even changes) to the admin views. As of yet, the defacto standard for this is Deface. Deface brings a lot of other problems - first and foremost it hides view changes into places where they are hard to track down or introduces "where does this checkbox coming from?" problems. Also it is barely known outside the Spree/Solidus ecosystem. Additionally we need to maintain HTML hooks (data-hook) that exist solely for Deface to work properly. That makes admin views refactoring very hard.

Proposal

I am proposing an idea that originally came up from @mamhoff while working with him on a client store that makes lots of changes to the Solidus admin. We removed Deface from that store a while ago and introduced another way to make admin view changes maintainable:

Rails partials

By splitting up the admin views into smaller chunks we make it easier for us to keep our admin maintainable during Solidus updates.

This is how it works

The Admin Orders table for example.

We split the admin/orders/index.html.erb template into several partials:

1. The filter fields

...
<% content_for :table_filter do %>
  <div data-hook="admin_orders_index_search">
    <%= search_form_for [:admin, @search] do |f| %>
      <%= render 'filter_fields', f: f %>
      ...
    <% end %>
  </div>
<% end %>
...

2. The table

...
<% if @orders.any? %>
  <%= render 'table', orders: @orders, ransack_search: @search, show_only_completed: @show_only_completed %>
<% else %>
  ...
<% end %>
...

3. The table row

<table class="index" id="listing_orders" data-hook>
  <colgroup>
    ...
  </colgroup>
  <thead>
    ...
  </thead>
  <tbody>
    <%= render collection: orders, partial: 'spree/admin/orders/order' %>
  </tbody>
</table>

Summary

For index views I propose implementing a pattern like:

admin/resource/index.html.erb
  - admin/resource/_filter_fields.html.erb
  - admin/resource/_table.html.erb
    - admin/resource/_resource.html.erb

For edit views I propose implementing a pattern like:

admin/resource/edit.html.erb
  - admin/resource/_form.html.erb
    - admin/resource/_form_additions.html.erb
  - admin/resource/_side_bar.html.erb
    - admin/resource/_side_bar_additions.html.erb

I think adopting this into core will make future changes to the admin easier for us and extension maintainers as well as stores. Sure, this is a lot of work and there will be many cases where need to find a good solution for, but still I think it is worth it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions