Skip to content

Commit

Permalink
Finding deprecation scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdan committed Nov 11, 2024
1 parent 80d56f5 commit cb8d752
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 11 deletions.
32 changes: 21 additions & 11 deletions version-2/Readme.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,27 @@ datagrid_form_with(model: @users_grid, url: users_path)

Built-in partial uses `form_with` no matter

[Grep all deprecations](./deprecations.sh).

## Deprecated datagrid\_order\_for

`datagrid_order_for` helper serves no purpose and should not be used directly.
The recommended way is to include your ordering code directly into `datagrid/head` partial.
See default [head partial](../app/views/datagrid/_head.html.erb) for example.
[Grep all deprecations](./deprecations.sh).

## Inherit Datagrid::Base

`include Datagrid` causes method name space to be clamsy.
Version 2 introduces a difference between the class
that needs to be inherited and high level namespace (just like most gems do):

``` ruby
class ApplicationGrid < Datagrid::Base
end
```

[Grep all deprecations](./deprecations.sh).

## Endless ranges for range filters

Expand Down Expand Up @@ -92,6 +108,11 @@ grid = UsersGrid.new(ActiveSupport::JSON.load(grid.attributes.to_json))
grid.id # => 3..7
```

This very likely breaks all `range: true` filters with custom block passed.
All such filters can be seen with this script (works only for V2):

[Search all broken range filters](./find_broken_range_filters.rb)

## Modern CSS classes naming conventions

Built-in generated CSS classes renamed to match modern CSS naming conventions
Expand Down Expand Up @@ -336,17 +357,6 @@ Renders:
[Modify built-in partials](https://github.com/bogdan/datagrid/wiki/Frontend#modifying-built-in-partials)
if you want to change this behavior completely.

## Inherit Datagrid::Base

`include Datagrid` causes method name space to be clamsy.
Version 2 introduces a difference between the class
that needs to be inherited and high level namespace (just like most gems do):

``` ruby
class ApplicationGrid < Datagrid::Base
end
```

## ApplicationGrid base class

Previously recommended base class `BaseGrid` is incosistent
Expand Down
16 changes: 16 additions & 0 deletions version-2/deprecations.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Use datagrid_form_with
git grep 'datagrid_form_for'

# Inline content of datagrid/order_for partial
git grep 'datagrid_order_for'

# Put necessary classes manually
git grep 'datagrid_column_classes'

# Inherit Datagrid::Base
git grep 'include Datagrid'

# Rename to ApplicationGrid (optional)
git grep 'BaseDatagrid'
git grep 'BaseGrid'

15 changes: 15 additions & 0 deletions version-2/find_broken_range_filters.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Important in development to have all classes in memory
Rails.application.eager_load!

raise "Use version 2" if Datagrid::VERSION < "2.0.0"

included_classes = ObjectSpace.each_object(Class).select do |klass|
klass.included_modules.include?(Datagrid)
end
classes = [*included_classes, *Datagrid::Base.subclasses].uniq

classes.flat_map(&:filters).select do |f|
f.respond_to?(:range?) && f.range? && f.block
end.map do |f|
[f.grid_class, f.name].join("#")
end

0 comments on commit cb8d752

Please sign in to comment.