Skip to content

Commit

Permalink
Merge branch 'main' of github.com:avo-hq/avodocs
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianthedev committed Nov 13, 2023
2 parents 9ea2daf + 1c5a8bc commit a96bdf4
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 0 deletions.
95 changes: 95 additions & 0 deletions docs/3.0/basic-filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Index /> 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
```
:::
32 changes: 32 additions & 0 deletions docs/3.0/upgrade.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a96bdf4

Please sign in to comment.