Skip to content

Commit

Permalink
Merge branch 'main' of github.com:avo-hq/docs.avohq.io
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianthedev committed Sep 10, 2024
2 parents a804334 + 0bd0b1b commit 57f60ed
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/.vitepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ const config = {
{text: "Avo::Current", link: "/3.0/avo-current.html"},
{text: "Avo::ExecutionContext", link: "/3.0/execution-context.html"},
{text: "Avo::Services::EncryptionService", link: "/3.0/encryption-service.html"},
{text: "Select All", link: "/3.0/select-all.html"},
{text: "Icons", link: "/3.0/icons.html"},
],
},
Expand Down
14 changes: 14 additions & 0 deletions docs/3.0/associations/has_many.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,20 @@ field :patrons,
}
```

:::warning
If the through model uses **polymorphism**, the type must be included as a hidden field:

```ruby{6}
field :patrons,
as: :has_many,
through: :patronships,
attach_fields: -> {
field :review, as: :text
field :patronship_type, as: :hidden, default: "TheType"
}
```
:::

<Image src="/assets/img/3_0/has_many/attach-fields.gif" width="600" height="338" alt="" />
</Option>

Expand Down
2 changes: 1 addition & 1 deletion docs/3.0/basic-filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,7 @@ class Avo::Actions::DummyAction < Avo::BaseAction
def handle(**args)
do_something_important

redirect_to avo.resources_users_path(filters: Avo::Filters::BaseFilter.encode_filters({"NameFilter"=>"Apple"}))
redirect_to avo.resources_users_path(encoded_filters: Avo::Filters::BaseFilter.encode_filters({"Avo::Filters::NameFilter"=>"Apple"}))
end
end
```
Expand Down
4 changes: 2 additions & 2 deletions docs/3.0/menu-editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ Additionally, you can pass the `params` option to the `resource` items to add qu
```ruby
resource :posts, params: { status: "published" }
resource :users, params: -> do
decoded_filter = {"IsAdmin"=>["non_admins"]}
decoded_filter = {"Avo::Filters::IsAdmin"=>["non_admins"]}

{ filters: Avo::Filters::BaseFilter.encode_filters(decoded_filter)}
{ encoded_filters: Avo::Filters::BaseFilter.encode_filters(decoded_filter)}
end
```

Expand Down
48 changes: 48 additions & 0 deletions docs/3.0/select-all.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Select All

The "Select All" feature is designed to enable users to select all queried records and perform actions on the entire selection. This feature is particularly useful when dealing with large datasets, allowing users to trigger actions on all queried records, not just the ones visible on the current page.

## How does it work?

<Image src="/assets/img/3_0/select_all.gif" width="687" height="289" alt="Select all demonstration" />

When a user toggles the "Select all" checkbox, Avo will first check to see if there are more records than just those displayed on that page, and if there are, it will ask if the user if they want to select all the records or not.

This is being done through serializing the query to be unserialized back in the action.

## Serializing the query

The query might include various filters, sorting parameters, and other custom elements. Reconstructing this query at the time of the action request can be complex. Therefore, the system serializes the entire query object into a secure format before sending it with the action request.

- **Security**: To ensure that sensitive data is protected, the serialized query is encrypted before it is transmitted.
- **Efficiency**: This approach allows the system to accurately and efficiently reconstruct the original query when the action is executed, ensuring that all relevant records are included.

:::warning
<VersionReq version="3.12.0" />
If an error occurs during the serialization process, the "Select All" feature is automatically disabled. This safeguard ensures that the page will not crash because of a coding error.
We listed a few reasons on why it might crash below.
:::

## Serialization known issues

In this section, we outline common serialization problems and provide guidance on how to resolve them effectively.

##### `normalize`

If your model includes any `normalize` proc, such as:

```ruby
normalizes :status, with: ->(status) { status }
```

Serialization may fail when a filter is applied to the normalized attribute (e.g., `status` in this example). This can result in the error `TypeError: no _dump_data is defined for class Proc`, which causes the "Select All" feature to be automatically disabled.

For applications created before Rails `7.1`, configuring the `marshalling_format_version` to `7.1` or higher will resolve the issue:

```ruby
# config/application.rb

config.active_record.marshalling_format_version = 7.1
```

More details on [`normalizes` documentation](https://api.rubyonrails.org/classes/ActiveRecord/Normalization/ClassMethods.html#method-i-normalizes).
Binary file added docs/public/assets/img/3_0/select_all.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 57f60ed

Please sign in to comment.