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 Aug 7, 2023
2 parents 9dd1ac4 + ea0da85 commit 153f395
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 14 deletions.
22 changes: 11 additions & 11 deletions docs/3.0/fields/select.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class Project < ApplicationRecord
enum type: { 'Large container': 'large', 'Medium container': 'medium', 'Tiny container': 'small' }
end
# app/avo/resources/project_resource.rb
class ProjectResource < Avo::BaseResource
# app/avo/resources/project.rb
class Avo::Resources::Project < Avo::BaseResource
field :type,
as: :select,
enum: ::Project.types,
Expand All @@ -59,8 +59,8 @@ end
You may want to display the values from the database and not the labels of the options. You may change that by setting `display_value` to `true`.

```ruby{5}
# app/avo/resources/project_resource.rb
class ProjectResource < Avo::BaseResource
# app/avo/resources/project.rb
class Avo::Resources::Project < Avo::BaseResource
field :type,
as: :select,
display_with_value: true
Expand All @@ -82,8 +82,8 @@ If it's set to `true` and you have a `placeholder` value assigned, it will use t
If it's a string `include_blank: "No country"`, the `No country` string will appear as the first option in the `<select>` and will set the value empty or `nil` depending on your settings.

```ruby{5}
# app/avo/resources/project_resource.rb
class ProjectResource < Avo::BaseResource
# app/avo/resources/project.rb
class Avo::Resources::Project < Avo::BaseResource
field :type,
as: :select,
include_blank: 'No type'
Expand All @@ -101,15 +101,15 @@ end

## Computed options

You may want to compute the values on the fly for your `Select` field. You can use a lambda for that where you have access to the `model`, `resource`, `view`, and `field` properties where you can pull data off.
You may want to compute the values on the fly for your `Select` field. You can use a lambda for that where you have access to the `record`, `resource`, `view`, and `field` properties where you can pull data off.

```ruby{5-7}
# app/avo/resources/project_resource.rb
class ProjectResource < Avo::BaseResource
# app/avo/resources/project.rb
class Avo::Resources::Project < Avo::BaseResource
field :type,
as: :select,
options: ->(model:, resource:, view:, field:) do
model.get_types_from_the_database.map { |type| [type.name, type.id] }
options: -> do
record.get_types_from_the_database.map { |type| [type.name, type.id] }
end,
placeholder: 'Choose the type of the container.'
end
Expand Down
25 changes: 22 additions & 3 deletions docs/3.0/upgrade.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ group :development do
end
```

Next you should run the `bin/rails avo:upgrade:2_to_3` command and go throught the process.
Next you should run the `bin/rails avo:upgrade:2_to_3` command and go through the process.

Ideally, you'd run the command with a clean tree and then make the last adjustments manually. The command will tell you what those the last adjustments are that you have to do manually.

Expand Down Expand Up @@ -210,7 +210,7 @@ We'll probably change these in the stable release.
Rename the following:

- `Avo::App.context` -> `Avo::Current.context`
- `Avo::App.current_user` -> `Avo::Current.current_user`
- `Avo::App.current_user` -> `Avo::Current.user`
- `Avo::App.params` -> `Avo::Current.params`
- `Avo::App.request` -> `Avo::Current.request`
- `Avo::App.view_context` -> `Avo::Current.view_context`
Expand Down Expand Up @@ -250,7 +250,7 @@ gem "avo_dashboards"

::::option Rename Avo configuration classes

We are falling more in line with how Rails and zeitwerk autoloads classes. We do this to avoidsome issues like class conflicts and difficult to remember naming schemes.
We are falling more in line with how Rails and zeitwerk autoloads classes. We do this to avoid some issues like class conflicts and difficult to remember naming schemes.

The old naming scheme: `{NAME}{TYPE}` (`UserResource`)
The new naming scheme: `Avo::{TYPE}::Name` (`Avo::Resources::User`)
Expand Down Expand Up @@ -471,6 +471,7 @@ All block arguments are removed from Avo. We did this in order to make blocks mo
We don't have a complete list of blocks but we'll try to give you a few examples:

- Field options: `visible`, `readonly`, `disabled`, `format_using`, etc.
- Select field `options` option
- Resource options: `index_query`, `search_query`, `find_record_method`, etc.
- Actions, Dashboards, and Cards `self.visible`
- anything that you are passing as a block should be without arguments
Expand All @@ -493,6 +494,24 @@ field :name, as: :text, default: ->(resource:) {something}, format_using: ->(val

# After
field :name, as: :text, default: -> {something}, format_using: -> {}, visible: -> {}

# Before
field :level, as: :select, options: ->(model:, resource:, field:, view:) do
{
Beginner: :beginner,
Intermediate: :intermediate,
Advanced: :advanced,
}
end

# After
field :level, as: :select, options: -> do
{
Beginner: :beginner,
Intermediate: :intermediate,
Advanced: :advanced,
}
end
```
:::

Expand Down

0 comments on commit 153f395

Please sign in to comment.