diff --git a/version-2/Readme.markdown b/version-2/Readme.markdown index f8e958b..236ffdf 100644 --- a/version-2/Readme.markdown +++ b/version-2/Readme.markdown @@ -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 @@ -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 @@ -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 diff --git a/version-2/deprecations.sh b/version-2/deprecations.sh new file mode 100644 index 0000000..9671188 --- /dev/null +++ b/version-2/deprecations.sh @@ -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' + diff --git a/version-2/find_broken_range_filters.rb b/version-2/find_broken_range_filters.rb new file mode 100644 index 0000000..b8a988f --- /dev/null +++ b/version-2/find_broken_range_filters.rb @@ -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