Skip to content

Commit

Permalink
Merge pull request #114 from bryszard/feature/allow_params_for_menu_item
Browse files Browse the repository at this point in the history
feature: add docs about params on resource menu item
  • Loading branch information
Paul-Bob authored Oct 9, 2023
2 parents 9071cab + 6358a22 commit aa83912
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 15 deletions.
27 changes: 20 additions & 7 deletions docs/2.0/menu-editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
feedbackId: 831
demoVideo: https://youtu.be/VMvG-j1Vxio
license: pro
version: '2.3.0'
version: "2.3.0"
---

# Menu editor
Expand Down Expand Up @@ -96,6 +96,7 @@ Link to is the menu item that the user will probably interact with the most. It
```ruby
link_to "Google", path: "https://google.com", target: :_blank
```

<img :src="('/assets/img/menu-editor/external-link.jpg')" alt="Avo menu editor" class="border mb-4" />

When you add the `target: :_blank` option, a tiny external link icon will be displayed.
Expand All @@ -119,6 +120,17 @@ You can also change the label for the `resource` items to something else.
resource :posts, label: "News posts"
```

Additionally, you can pass the `params` option to the `resource` items to add query params to the link.

```ruby
resource :posts, params: { status: "published" }
resource :users, params: -> do
decoded_filter = {"IsAdmin"=>["non_admins"]}

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

:::

:::option `dashboard`
Expand Down Expand Up @@ -180,6 +192,7 @@ section "App", icon: "heroicons/outline/beaker" do
end
end
```

:::

:::option `all_dashboards`
Expand All @@ -192,6 +205,7 @@ section "App", icon: "heroicons/outline/beaker" do
end
end
```

:::

:::option `all_tools`
Expand All @@ -204,6 +218,7 @@ section "App", icon: "heroicons/outline/beaker" do
end
end
```

:::

### `all_` helpers
Expand All @@ -230,15 +245,14 @@ The `all_resources` helper is taking into account your [authorization](./authori

<img :src="('/assets/img/menu-editor/all-helpers.jpg')" alt="Avo menu editor" class="border mb-4" />


## Item visibility

The `visible` option is available on all menu items. It can be a boolean or a block that has access to a few things:

- the `current_user`. Given that you [set a way](authentication.html#customize-the-current-user-method) for Avo to know who the current user is, that will be available in that block call
- the [`context`](customization.html#context) object.
- the `params` object of that current request
- the [`view_context`](https://apidock.com/rails/AbstractController/Rendering/view_context) object. The `view_context` object lets you use the route helpers. eg: `view_context.main_app.posts_path`.
- the `current_user`. Given that you [set a way](authentication.html#customize-the-current-user-method) for Avo to know who the current user is, that will be available in that block call
- the [`context`](customization.html#context) object.
- the `params` object of that current request
- the [`view_context`](https://apidock.com/rails/AbstractController/Rendering/view_context) object. The `view_context` object lets you use the route helpers. eg: `view_context.main_app.posts_path`.

```ruby
# config/initializers/avo.rb
Expand Down Expand Up @@ -387,7 +401,6 @@ end

It's common to have forms that `POST` to a path to do sign ut a user. For this scenario we added the `method` and `params` option to the profile item `link_to`, so if you have a custom sign out path you can do things like this.


```ruby
# config/initializers/avo.rb
Avo.configure do |config|
Expand Down
28 changes: 20 additions & 8 deletions docs/3.0/menu-editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
feedbackId: 831
demoVideo: https://youtu.be/VMvG-j1Vxio
license: pro
version: '2.3.0'
version: "2.3.0"
---

# Menu editor
Expand Down Expand Up @@ -96,6 +96,7 @@ Link to is the menu item that the user will probably interact with the most. It
```ruby
link_to "Google", path: "https://google.com", target: :_blank
```

<img :src="('/assets/img/menu-editor/external-link.jpg')" alt="Avo menu editor" class="border mb-4" />

When you add the `target: :_blank` option, a tiny external link icon will be displayed.
Expand All @@ -119,6 +120,17 @@ You can also change the label for the `resource` items to something else.
resource :posts, label: "News posts"
```

Additionally, you can pass the `params` option to the `resource` items to add query params to the link.

```ruby
resource :posts, params: { status: "published" }
resource :users, params: -> do
decoded_filter = {"IsAdmin"=>["non_admins"]}

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

:::

:::option `dashboard`
Expand Down Expand Up @@ -180,6 +192,7 @@ section "App", icon: "heroicons/outline/beaker" do
end
end
```

:::

:::option `all_dashboards`
Expand All @@ -192,6 +205,7 @@ section "App", icon: "heroicons/outline/beaker" do
end
end
```

:::

:::option `all_tools`
Expand All @@ -204,6 +218,7 @@ section "App", icon: "heroicons/outline/beaker" do
end
end
```

:::

### `all_` helpers
Expand All @@ -230,15 +245,14 @@ The `all_resources` helper is taking into account your [authorization](./authori

<img :src="('/assets/img/menu-editor/all-helpers.jpg')" alt="Avo menu editor" class="border mb-4" />


## Item visibility

The `visible` option is available on all menu items. It can be a boolean or a block that has access to a few things:

- the `current_user`. Given that you [set a way](authentication.html#customize-the-current-user-method) for Avo to know who the current user is, that will be available in that block call
- the [`context`](customization.html#context) object.
- the `params` object of that current request
- the [`view_context`](https://apidock.com/rails/AbstractController/Rendering/view_context) object. The `view_context` object lets you use the route helpers. eg: `view_context.main_app.posts_path`.
- the `current_user`. Given that you [set a way](authentication.html#customize-the-current-user-method) for Avo to know who the current user is, that will be available in that block call
- the [`context`](customization.html#context) object.
- the `params` object of that current request
- the [`view_context`](https://apidock.com/rails/AbstractController/Rendering/view_context) object. The `view_context` object lets you use the route helpers. eg: `view_context.main_app.posts_path`.

```ruby
# config/initializers/avo.rb
Expand Down Expand Up @@ -282,7 +296,6 @@ Avo.configure do |config|
end
```


## Icons

For [`Section`](#section)s, you can use icons to make them look better. You can use some local ones that we used throughout the app and all [heroicons](https://heroicons.com/) designed by [Steve Schoger](https://twitter.com/steveschoger). In addition, you can use the `solid` or `outline` versions. We used the `outline` version throughout the app.
Expand Down Expand Up @@ -382,7 +395,6 @@ end

It's common to have forms that `POST` to a path to do sign ut a user. For this scenario we added the `method` and `params` option to the profile item `link_to`, so if you have a custom sign out path you can do things like this.


```ruby
# config/initializers/avo.rb
Avo.configure do |config|
Expand Down

0 comments on commit aa83912

Please sign in to comment.