TrestleAdmin / trestle

A modern, responsive admin framework for Ruby on Rails
https://trestle.io
GNU Lesser General Public License v3.0
1.97k stars 177 forks source link

[PoC] Add ability to exclude fields from automatic forms and tables #519

Open spohlenz opened 3 weeks ago

spohlenz commented 3 weeks ago

This is a proof of concept PR for an alternative way to support excluding fields from automatic tables and forms, as seen in #517 and #416.

It adds the ability to specify the :exclude option when defining an automatic table or form (i.e. without a block).

Trestle.resource(:articles) do
  table exclude: [:updated_at, :created_at]
  form exclude: [:updated_at, :created_at]
end

The advantage I see to this approach is that it confines the exclusion logic to the automatic form and table classes where it is most relevant. One disadvantage perhaps is that it is slightly harder to re-use specific exclusions between resources via adapter methods/modules.

A logical next step would be to add global configuration options for the default excluded fields (e.g. Trestle.config.default_table_exclusions / Trestle.config.default_form_exclusions).

coveralls commented 3 weeks ago

Coverage Status

coverage: 91.428% (+0.01%) from 91.416% when pulling bfeffe3a809c619674c074ca7952f71b6b558e96 on exclude-fields-poc into dc8e987a2c32c72c51a63eb7c3b8638c6e9de4f3 on main.