diff --git a/docs/3.0/basic-filters.md b/docs/3.0/basic-filters.md index 4e0a6e0f..c55a3ad0 100644 --- a/docs/3.0/basic-filters.md +++ b/docs/3.0/basic-filters.md @@ -700,3 +700,98 @@ class Avo::Filters::Name < Avo::Filters::TextFilter end ``` +## Manually create encoded URLs + +You may want to redirect users to filtered states of the view from other places in your app. In order to create those filtered states you may use these helpers functions or Rails helpers. + + +### Rails helpers + +:::option `decode_filter_params` + +Decodes the `filters` param. This Rails helper can be used anywhere in a view or off the `view_context`. + +#### Usage + +```ruby +# in a view +decode_filter_params params[:filters] # {"NameFilter"=>"Apple"} + +# Or somewhere in an Avo configuration file + +class Avo::Actions::DummyAction < Avo::BaseAction + self.name = "Dummy action" + + def handle(**args) + filters = view_context.decode_filter_params(params[:filters]) + + do_something_important_with_the_filters filters + end +end +``` +::: + +:::option `encode_filter_params` + +Encodes a `filters` object into a serialized state that Avo understands. This Rails helper can be used anywhere in a view or off the `view_context`. + +#### Usage + +```ruby +# in a view +filters = {"NameFilter"=>"Apple"} +encode_filter_params filters # eyJOYW1lRmlsdGVyIjoiQXBwbGUifQ== + +# Or somewhere in an Avo configuration file + +class Avo::Actions::DummyAction < Avo::BaseAction + self.name = "Dummy action" + + def handle(**args) + do_something_important + + redirect_to avo.resources_users_path(filters: view_context.decode_filter_params({"NameFilter"=>"Apple"})) + end +end +``` +::: + +### Standalone helpers + +:::option `Avo::Filters::BaseFilter.decode_filters` + +Decodes the `filters` param. This standalone method can be used anywhere. + +#### Usage + +```ruby +class Avo::Actions::DummyAction < Avo::BaseAction + self.name = "Dummy action" + + def handle(**args) + filters = Avo::Filters::BaseFilter.decode_filters(params[:filters]) + + do_something_important_with_the_filters filters + end +end +``` +::: + +:::option `Avo::Filters::BaseFilter.encode_filters` + +Encodes a `filters` object into a serialized state that Avo understands. This standalone method can be used anywhere. + +#### Usage + +```ruby +class Avo::Actions::DummyAction < Avo::BaseAction + self.name = "Dummy action" + + def handle(**args) + do_something_important + + redirect_to avo.resources_users_path(filters: Avo::Filters::BaseFilter.encode_filters({"NameFilter"=>"Apple"})) + end +end +``` +::: diff --git a/docs/3.0/upgrade.md b/docs/3.0/upgrade.md index 42982c8b..ef1950b6 100644 --- a/docs/3.0/upgrade.md +++ b/docs/3.0/upgrade.md @@ -4,6 +4,38 @@ We'll update this page when we release new Avo 3 versions. If you're looking for the Avo 2 to Avo 3 upgrade guide, please visit [the dedicated page](./avo-2-avo-3-upgrade). +## Upgrade from 3.0.1.beta24 to 3.0.1.beta25 + +:::option Attachments eager load + +Attachments are no longer automatically eager loading. If you want to eager load attachments there are at least two ways: + +### Use [`self.includes`](resources.html#self_includes) option + +```ruby +class Avo::Resources::PhotoComment < Avo::BaseResource + self.includes = [:user, [photo_attachment: :blob]] + + def fields + field :user, as: :belongs_to + field :photo, as: :file, is_image: true + end +``` + +### Use [`self.index_query`](customization.html#custom-scope-for-index-page) option +```ruby +class Avo::Resources::Product < Avo::BaseResource + self.index_query = -> { + query.includes image_attachment: :blob + } + + def fields + field :image, as: :file, is_image: true + end +``` + +::: + ## Upgrade from 3.0.1.beta23 to 3.0.1.beta24 :::option Cards