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 2, 2023
2 parents ff2d331 + 8b650fc commit 0f099db
Show file tree
Hide file tree
Showing 15 changed files with 276 additions and 30 deletions.
83 changes: 72 additions & 11 deletions docs/2.0/actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ end
:::
:::option `redirect_to`

`redirect_to` will execute a redirect to a new path of your app. It accept `allow_other_host` and `status` arguments.
`redirect_to` will execute a redirect to a new path of your app. It accept `allow_other_host`, `status` and any other arguments.

Example:
`redirect_to path, allow_other_host: true, status: 303`
Expand All @@ -204,23 +204,84 @@ end



:::warning
If you're redirecting to an external link you should add the `self.turbo = false` option in order to bypass [Turbo's navigation](https://turbo.hotwired.dev/handbook/drive#disabling-turbo-drive-on-specific-links-or-forms).
:::
You may want to redirect to another action. Here's an example of how to create a multi-step process, passing arguments from one action to another.
In this example the initial action prompts the user to select the fields they wish to update, and in the subsequent action, the chosen fields will be accessible for updating.

:::option `turbo`
There are times when you don't want to perform the actions with Turbo, such as when the action leads to an external link or you might download a file. In such cases, turbo should be set to false.
:::code-group
```ruby[PreUpdate]
class PreUpdate < Avo::BaseAction
self.name = "Update"
self.message = "Set the fields you want to update."
```ruby{3,6}
class DummyAction < Avo::BaseAction
self.name = "Dummy action"
self.turbo = false
with_options as: :boolean do
field :first_name
field :last_name
field :user_email
field :active
field :admin
end
def handle(**args)
redirect_to "https://www.google.com/" # external link
arguments = Base64.encode64 Avo::Services::EncryptionService.encrypt(
message: {
render_first_name: args[:fields][:first_name],
render_last_name: args[:fields][:last_name],
render_user_email: args[:fields][:user_email],
render_active: args[:fields][:active],
render_admin: args[:fields][:admin]
},
purpose: :action_arguments
)
redirect_to "/admin/resources/users/actions?action_id=Update&arguments=#{arguments}", turbo_frame: "actions_show"
end
end
```

```ruby[Update]
class Update < Avo::BaseAction
self.name = "Update"
self.message = ""
self.visible = -> do
false
end
{
first_name: :text,
last_name: :text,
user_email: :text,
active: :boolean,
admin: :boolean
}.each do |field_name, field_type|
field field_name.to_sym, as: field_type, visible: -> (resource:) {
Avo::Services::EncryptionService.decrypt(
message: Base64.decode64(resource.params[:arguments]),
purpose: :action_arguments
).dig("render_#{field_name}".to_sym)
}
end
def handle(models:, fields:, **args)
non_roles_fields = fields.slice!(:admin)
models.each { |model| model.update!(non_roles_fields) }
fields.each do |field_name, field_value|
models.each { |model| model.update! roles: model.roles.merge!({"#{field_name}": field_value}) }
end
succeed "User(s) updated!"
end
end
```

:::info `turbo_frame`
Notice the `turbo_frame: "actions_show"` present on the redirect of `PreUpdate` action. That argument is essential to have a flawless redirect between the actions.
:::


:::option `turbo`
There are times when you don't want to perform the actions with Turbo. In such cases, turbo should be set to false.
:::

:::option `download`
Expand Down
25 changes: 23 additions & 2 deletions docs/2.0/cache.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,37 @@ The cache system dynamically selects the appropriate cache store based on the ap

### Production

In production, it uses the existing cache store when it's one of the following: `ActiveSupport::Cache::MemCacheStore`, `ActiveSupport::Cache::RedisCacheStore` or `SolidCache::Store`. Otherwise, it defaults to `:file_store` with a cache path of `tmp/cache`.
In production, if the existing cache store is one of the following: `ActiveSupport::Cache::MemoryStore` or `ActiveSupport::Cache::NullStore` it will use the default `:file_store` with a cache path of `tmp/cache`. Otherwise, the existing cache store `Rails.cache` will be used.

### Test

In testing, it directly uses the Rails cache store.
In testing, it directly uses the `Rails.cache` store.

### Development and other environments

In all other environments the `:memory_store` is used.

### Custom selection

There is the possibility to force the usage of a custom cache store into Avo.

```ruby
# config/initializers/avo.rb
config.cache_store = -> {
ActiveSupport::Cache.lookup_store(:solid_cache_store)
}

# or

config.cache_store = ActiveSupport::Cache.lookup_store(:solid_cache_store)
```

`cache_store` configuration option is expecting a cache store object, the lambda syntax can be useful if different stores are desired on different environments.

:::warning MemoryStore in production
Our computed system do not use MemoryStore in production because it will not be shared between multiple processes (when using Puma).
:::

## Solid Cache

Avo seamlessly integrates with [Solid Cache](https://github.com/rails/solid_cache). To setup Solid Cache follow these essential steps
Expand Down
2 changes: 1 addition & 1 deletion docs/2.0/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ All in all **we're confident you'll have the necessary instruments** you need to

### STI example

For **STI** you can check out the models and resources in the [demo app](https://avodemo.herokuapp.com/).
For **STI** you can check out the models and resources in the [demo app](https://main.avodemo.com/).

- [person.rb](https://github.com/avo-hq/avodemo/blob/main/app/models/person.rb)
- [spouse.rb](https://github.com/avo-hq/avodemo/blob/main/app/models/spouse.rb)
Expand Down
21 changes: 21 additions & 0 deletions docs/2.0/fields/tags.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,27 @@ field :skills,
<!-- @include: ./../common/default_boolean_false.md-->
:::

:::option `suggestions_max_items`
Set of suggestions that can be displayed at once. The excessive items will be hidden and the user will have to narrow down the query to see them.

```ruby{4}
field :skills,
as: :tags,
suggestions: %w(one two three),
suggestions_max_items: 2
```

<img :src="('/assets/img/fields/tags-field/suggestions_max_items.gif')" alt="Avo tags field - suggestions max items option" class="border mb-4" />

#### Default

`20`

#### Possible values

Integers
:::

:::option `close_on_select`
Set whether the `suggestions` dropdown should close after the user makes a selection.

Expand Down
2 changes: 1 addition & 1 deletion docs/2.0/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Please take your time and read the documentation pages to see how Avo interacts
1. [Create a Resource](./resources.html#defining-resources)
1. [Set up authorization](authorization.html)
1. [Set up licensing](licensing)
1. [Explore the live demo app](https://avodemo.herokuapp.com)
1. [Explore the live demo app](https://main.avodemo.com/)
1. Explore these docs
1. Enjoy building your app without ever worrying about the admin layer ever again
1. Explore the [FAQ](faq) pages for guides on how to set up your Avo instance.
Expand Down
12 changes: 12 additions & 0 deletions docs/2.0/upgrade.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@
We generally push changes behind the scenes, so you don't have to update your code, but sometimes the public API is updated too.

Follow these guides to make sure your configuration files are up to date.

## Upgrade from 2.43 to 2.44

We've internally implemented some changes around actions to resolve certain bugs. No action is needed from your end, but if you happen to notice any anomalies in the actions flow, please get in touch with us so we can address them promptly. Thank you.

## Upgrade from 2.42.1 to 2.42.2
Since there are many available cache stores and we were allowing only few we changed the way of computing the cache store to be used by Avo.

One of our concerns was to maintain the status quo, but if you notice any caching issues there is a new configurable option [`config.cache_store`](cache#custom-selection) that allows you to tell Avo what `cache_store` to use.

Check [cache page](cache) for more details.

## Upgrade from 2.40 to 2.41

### Badge field `secondary` option renamed to `neutral`
Expand Down
59 changes: 48 additions & 11 deletions docs/3.0/actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ end
:::
:::option `redirect_to`

`redirect_to` will execute a redirect to a new path of your app. It accept `allow_other_host` and `status` arguments.
`redirect_to` will execute a redirect to a new path of your app. It accept `allow_other_host`, `status` and any other arguments.

Example:
`redirect_to path, allow_other_host: true, status: 303`
Expand All @@ -204,27 +204,64 @@ def handle(**args)
end
```

You may want to redirect to another action. Here's an example of how to create a multi-step process, passing arguments from one action to another.
In this example the initial action prompts the user to select the fields they wish to update, and in the subsequent action, the chosen fields will be accessible for updating.

:::code-group
```ruby[PreUpdate]
class Avo::Actions::City::PreUpdate < Avo::BaseAction
self.name = "Update"
:::warning
If you're redirecting to an external link you should add the `self.turbo = false` option in order to bypass [Turbo's navigation](https://turbo.hotwired.dev/handbook/drive#disabling-turbo-drive-on-specific-links-or-forms).
:::
def fields
field :name, as: :boolean
field :population, as: :boolean
end
:::option `turbo`
There are times when you don't want to perform the actions with Turbo, such as when the action leads to an external link or you might download a file. In such cases, turbo should be set to false.
def handle(**args)
arguments = Base64.encode64 Avo::Services::EncryptionService.encrypt(
message: {
query: Avo::Services::EncryptionService.encrypt(message: args[:query], purpose: :multiple_actions_flux, serializer: Marshal),
render_name: args[:fields][:name],
render_population: args[:fields][:population]
},
purpose: :action_arguments
)
redirect_to "/admin/resources/city/actions?action_id=Avo::Actions::City::Update&arguments=#{arguments}", turbo_frame: "actions_show"
end
end
```

```ruby{3,6}
class Avo::Actions::DummyAction < Avo::BaseAction
self.name = "Dummy action"
self.turbo = false
```ruby[Update]
class Avo::Actions::City::Update < Avo::BaseAction
self.name = "Update"
self.visible = -> { false }
def fields
field :name, as: :text if arguments[:render_name]
field :population, as: :number if arguments[:render_population]
end
def handle(**args)
redirect_to "https://www.google.com/"
query = Avo::Services::EncryptionService.decrypt(message: arguments[:query], purpose: :multiple_actions_flux, serializer: Marshal)
query.each do |city|
city.update! args[:fields]
end
succeed "City updated!"
end
end
```

:::info `turbo_frame`
Notice the `turbo_frame: "actions_show"` present on the redirect of `Avo::Actions::City::PreUpdate` action. That argument is essential to have a flawless redirect between the actions.
:::


:::option `turbo`
There are times when you don't want to perform the actions with Turbo. In such cases, turbo should be set to false.
:::
:::option `download`

`download` will start a file download to your specified `path` and `filename`.
Expand Down
27 changes: 27 additions & 0 deletions docs/3.0/avo-2-avo-3-upgrade.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,33 @@ field :status,
```
:::

:::option `heading` has become a field type
Before, a heading used the `heading` method with a text string or HTML string as an argument.
Now, it is a field type with an ID. It supports rendering as text and as HTML.

### Actions to take

Rename `heading` to `field`. Give the field an ID and add the `as: :heading` argument.

```ruby
# Before
heading 'User Information'

# After
field :user_information, as: :heading
# or...
field :some_id, as: :heading, label: 'User Information'

# Before
heading '<div class="underline uppercase font-bold">User Information</div>', as_html: true

# After
field :some_id, as: :heading, as_html: true do
'<div class="underline uppercase font-bold">User Information</div>'
end
```
:::

:::option Moved some globals from `Avo::App` to `Avo::Current`

### Actions to take
Expand Down
25 changes: 23 additions & 2 deletions docs/3.0/cache.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,37 @@ The cache system dynamically selects the appropriate cache store based on the ap

### Production

In production, it uses the existing cache store when it's one of the following: `ActiveSupport::Cache::MemCacheStore`, `ActiveSupport::Cache::RedisCacheStore` or `SolidCache::Store`. Otherwise, it defaults to `:file_store` with a cache path of `tmp/cache`.
In production, if the existing cache store is one of the following: `ActiveSupport::Cache::MemoryStore` or `ActiveSupport::Cache::NullStore` it will use the default `:file_store` with a cache path of `tmp/cache`. Otherwise, the existing cache store `Rails.cache` will be used.

### Test

In testing, it directly uses the Rails cache store.
In testing, it directly uses the `Rails.cache` store.

### Development and other environments

In all other environments the `:memory_store` is used.

### Custom selection

There is the possibility to force the usage of a custom cache store into Avo.

```ruby
# config/initializers/avo.rb
config.cache_store = -> {
ActiveSupport::Cache.lookup_store(:solid_cache_store)
}

# or

config.cache_store = ActiveSupport::Cache.lookup_store(:solid_cache_store)
```

`cache_store` configuration option is expecting a cache store object, the lambda syntax can be useful if different stores are desired on different environments.

:::warning MemoryStore in production
Our computed system do not use MemoryStore in production because it will not be shared between multiple processes (when using Puma).
:::

## Solid Cache

Avo seamlessly integrates with [Solid Cache](https://github.com/rails/solid_cache). To setup Solid Cache follow these essential steps
Expand Down
17 changes: 17 additions & 0 deletions docs/3.0/dynamic-filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,23 @@ This filter will give you options from the database.
- Is blank
:::

::::option Array

Used on `tags` fields.

### Conditions

- Are
- Contains
- Overlap
- Contained in

:::warning
This will only work with database array columns, not when using the `acts-as-taggable-on` gem.
:::

::::

## Options

You can have a few customization options available that you can add in your `avo.rb` initializer file.
Expand Down
2 changes: 1 addition & 1 deletion docs/3.0/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ All in all **we're confident you'll have the necessary instruments** you need to

### STI example

For **STI** you can check out the models and resources in the [demo app](https://avodemo.herokuapp.com/).
For **STI** you can check out the models and resources in the [demo app](https://main.avodemo.com/).

- [person.rb](https://github.com/avo-hq/avodemo/blob/main/app/models/person.rb)
- [spouse.rb](https://github.com/avo-hq/avodemo/blob/main/app/models/spouse.rb)
Expand Down
Loading

0 comments on commit 0f099db

Please sign in to comment.