Skip to content

Commit

Permalink
column[url] option removal guide
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdan committed Nov 14, 2024
1 parent e12826b commit b775675
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 6 deletions.
42 changes: 36 additions & 6 deletions version-2/Readme.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,52 @@ Version 2 addresses all that evolution.

List of things introduces:

## API changes

1. Ruby endless ranges for range filters.
1. Use Hash instead of Array for multiparameter attributes.
1. Remove `column[url]` option.
1. Inherit `Datagrid::Base` instead of `include Datagrid`.
1. `ApplicationGrid` is recommended base class instead of `BaseGrid`.

## Frontend Changes

1. Use `form_with` instead of `form_for`.
1. Deprecated `datagrid_order_for`
1. Ruby endless ranges for range filters.
1. Modern modular CSS classes.
1. HTML5 input types: number, date, datetime-local.
1. Use Hash instead of Array for multiparameter attirubtes.
1. Native Rails Engines.
1. Native Rails Engines:
* while supported, the library was not initially designed for it.
1. HTML5 data attributes
1. Consistent id attribute for range filter inputs
1. Inherit `Datagrid::Base` instead of `include Datagrid`
1. `ApplicationGrid` is recommended base class instead of `BaseGrid`
1. Consistent `label[for]` and `input[id]` for range filters.
1. Introduced `datagrid.filters.range.separator` localization
1. Remove SASS dependency
1. Replace `rake datagrid:copy_partials` with `rails g datagrid:views`

## Remove column[url] option

`column[url]` option was introduced before flexible data/html output layer for columns was established. Here is how the deprecated option can be migrated to modern setup:

Version 1:

``` ruby
column(:user, url: -> (user) => { user_profile_path(user) }) do
user.name
end
```

Version 2:

``` ruby
column(:user) do |user|
format(user.name) do |value|
link_to value, user_profile_path(user)
end
end
```

All deprecated columns can be found [with a script](./find_deprecated_url_option.rb)

## Use form\_with

Rails [deprecates form\_for in favor of form\_with](https://guides.rubyonrails.org/form_helpers.html#using-form-tag-and-form-for).
Expand Down
19 changes: 19 additions & 0 deletions version-2/find_deprecated_url_option.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

# Important in development to have all classes in memory
Rails.application.eager_load!

included_classes = ObjectSpace.each_object(Class).select do |klass|
klass.included_modules.include?(Datagrid)
end

base_subclasses = ObjectSpace.each_object(Class).select do |klass|
klass < Datagrid::Base
end
classes = [*included_classes, *base_subclasses].uniq

classes.flat_map(&:columns).select do |f|
f.options[:url]
end.map do |f|
[f.grid_class, f.name].join("#")
end

0 comments on commit b775675

Please sign in to comment.