Skip to content

Commit

Permalink
Fix boolean group docs (#246)
Browse files Browse the repository at this point in the history
* fix boolean group docs

* tweaks
  • Loading branch information
Paul-Bob authored Jul 15, 2024
1 parent afeda99 commit 96b94df
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 23 deletions.
57 changes: 34 additions & 23 deletions docs/3.0/fields/boolean_group.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,55 @@ license: community

# Boolean Group

<Image src="/assets/img/fields/boolean-group.jpg" width="916" height="244" alt="Boolean group field" />
<Image src="/assets/img/fields/boolean-group.jpg" width="645" height="275" alt="Boolean group field" />

The `BooleanGroup` is used to update a `Hash` with `string` keys and `boolean` values in the database.

It's useful when you have something like a roles hash in your database.

### DB payload example
An example of a boolean group object stored in the database:

```ruby
{
"admin": true,
"manager": true,
"writer": true,
}
```

### Field declaration example
Below is an example of declaring a `boolean_group` field for roles that matches the DB value from the example above:

```ruby
field :roles, as: :boolean_group, name: 'User roles', options: { admin: 'Administrator', manager: 'Manager', writer: 'Writer' }
field :roles,
as: :boolean_group,
name: "User roles",
options: {
admin: "Administrator",
manager: "Manager",
writer: "Writer"
}
```

## Options


:::option `options`
`options` should be a `Hash` with the keys to one of the four available types (`info`, `success`, `warning`, `danger`) and the values matching your record's database values.
The `options` attribute should be a `Hash` where the keys match the DB keys and the values are the visible labels.

#### Default value

Empty `Hash`.

```ruby
{
info: :info,
success: :success,
danger: :danger,
warning: :warning
}
{}
```

#### Computed options

You may want to compute the values on the fly for your `BooleanGroup` 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.
You may need to compute the options dynamically for your `BooleanGroup` field. You can use a lambda for this, which provides access to the `record`, `resource`, `view`, and `field` properties where you can pull data off.

```ruby{5-7}
```ruby{5-9}
# app/avo/resources/project.rb
class Avo::Resources::Project < Avo::BaseResource
field :features,
Expand All @@ -52,18 +70,10 @@ The output value must be a hash as described above.

:::

## Example DB payload

```ruby
# Example boolean group object stored in the database
{
"admin": true,
"manager": true,
"creator": true,
}
```
## Updates

Before version 3.7.0 Avo would override the whole attribute with only the payload sent from the client.
Before version <Version version="3.7.0" /> Avo would override the whole attribute with only the payload sent from the client.

```json
// Before update.
Expand All @@ -72,14 +82,15 @@ Before version 3.7.0 Avo would override the whole attribute with only the payloa
"another_feature_enabled": false,
"something_else": "some_value" // this will disappear
}

// After update.
{
"feature_enabled": true,
"another_feature_enabled": false,
}
```

Version 3.7.0 and up will only update the keys that you send from the client.
<VersionReq version="3.7.0" /> will only update the keys that you send from the client.

```json
// Before update.
Expand Down
Binary file modified docs/public/assets/img/fields/boolean-group.jpg
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 96b94df

Please sign in to comment.