Skip to content

Commit b8d1a2b

Browse files
committed
improvement: support actor_load option
1 parent 943cbd4 commit b8d1a2b

File tree

8 files changed

+2935
-9
lines changed

8 files changed

+2935
-9
lines changed

.formatter.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
spark_locals_without_parens = [
22
accepted_extensions: 1,
33
actor?: 1,
4+
actor_load: 1,
45
create_actions: 1,
56
default_resource_page: 1,
67
destroy_actions: 1,

documentation/dsls/DSL-AshAdmin.Resource.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Configure the admin dashboard for a given resource.
2222
| Name | Type | Default | Docs |
2323
|------|------|---------|------|
2424
| [`name`](#admin-name){: #admin-name } | `String.t` | | The proper name to use when this resource appears in the admin interface. |
25+
| [`actor_load`](#admin-actor_load){: #admin-actor_load } | `any` | | A load statement to apply on the actor when fetching it |
2526
| [`actor?`](#admin-actor?){: #admin-actor? } | `boolean` | | Whether or not this resource can be used as the actor for requests. |
2627
| [`show_action`](#admin-show_action){: #admin-show_action } | `atom` | | The action to use when linking to the resource/viewing a single record. Defaults to the primary read action. |
2728
| [`read_actions`](#admin-read_actions){: #admin-read_actions } | `list(atom)` | | A list of read actions that can be used to show resource details. By default, all actions are included. |

lib/ash_admin/actor_plug/plug.ex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,12 @@ defmodule AshAdmin.ActorPlug.Plug do
131131
Ash.Resource.Info.action(resource, String.to_existing_atom(action), :read)
132132
end
133133

134+
actor_load = AshAdmin.Resource.actor_load(resource)
135+
134136
resource
135137
|> Ash.Query.filter(^filter)
136138
|> Ash.Query.set_tenant(tenant)
139+
|> Ash.Query.load(actor_load)
137140
|> Ash.read_one!(action: action, authorize?: false, domain: domain)
138141

139142
_ ->

lib/ash_admin/pages/page_live.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,10 +399,12 @@ defmodule AshAdmin.PageLive do
399399
{:ok, pkey_filter} ->
400400
domain = Module.concat([domain])
401401
action = AshAdmin.Helpers.primary_action(resource, :read)
402+
actor_load = AshAdmin.Resource.actor_load(resource)
402403

403404
actor =
404405
resource
405406
|> Ash.Query.filter(^pkey_filter)
407+
|> Ash.Query.load(actor_load)
406408
|> Ash.Query.set_tenant(socket.assigns[:tenant])
407409
|> Ash.read_one!(action: action, authorize?: false, domain: domain)
408410

lib/ash_admin/resource/resource.ex

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ defmodule AshAdmin.Resource do
2626
type: :string,
2727
doc: "The proper name to use when this resource appears in the admin interface."
2828
],
29+
actor_load: [
30+
type: :any,
31+
doc: "A load statement to apply on the actor when fetching it"
32+
],
2933
actor?: [
3034
type: :boolean,
3135
doc: "Whether or not this resource can be used as the actor for requests."
@@ -204,6 +208,10 @@ defmodule AshAdmin.Resource do
204208
Spark.Dsl.Extension.get_opt(resource, [:admin], :actor?, false, true)
205209
end
206210

211+
def actor_load(resource) do
212+
Spark.Dsl.Extension.get_opt(resource, [:admin], :actor_load, [], true)
213+
end
214+
207215
def read_actions(resource) do
208216
Spark.Dsl.Extension.get_opt(resource, [:admin], :read_actions, nil, true) ||
209217
actions_with_primary_first(resource, :read)

mix.lock

Lines changed: 7 additions & 7 deletions
Large diffs are not rendered by default.

priv/static/assets/app.css

Lines changed: 2503 additions & 1 deletion
Large diffs are not rendered by default.

priv/static/assets/app.js

Lines changed: 410 additions & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)