Skip to content

Commit

Permalink
improvement: upgrade to 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
zachdaniel committed Mar 29, 2024
1 parent 7e30388 commit 657d36d
Show file tree
Hide file tree
Showing 42 changed files with 381 additions and 362 deletions.
7 changes: 3 additions & 4 deletions .github/ISSUE_TEMPLATE/proposal.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
---
name: Proposal
about: Suggest an idea for this project
title: ''
title: ""
labels: enhancement, needs review
assignees: ''

assignees: ""
---

**Is your feature request related to a problem? Please describe.**
Expand All @@ -29,7 +28,7 @@ For example
Or

```elixir
Api.read(:resource, bar: 10) # <- Adding `bar` here would cause <x>
Ash.read(:resource, bar: 10) # <- Adding `bar` here would cause <x>
```

**Additional context**
Expand Down
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,30 @@ First, ensure you've added ash_admin to your `mix.exs` file.

## Setup

Ensure your apis are configured in `config.exs`
Ensure your domains are configured in `config.exs`

```elixir
config :my_app, ash_apis: [MyApp.Foo, MyApp.Bar]
config :my_app, ash_domains: [MyApp.Foo, MyApp.Bar]
```

Add the admin extension to each api you want to show in AshAdmin dashboard, and configure it to show. See [`AshAdmin.Api`](https://hexdocs.pm/ash_admin/AshAdmin.Api.html) for more configuration options.
Add the admin extension to each domain you want to show in AshAdmin dashboard, and configure it to show. See [`AshAdmin.Domain`](https://hexdocs.pm/ash_admin/AshAdmin.Domain.html) for more configuration options.

```elixir
# In your Api(s)
use Ash.Api,
extensions: [AshAdmin.Api]
# In your Domain(s)
use Ash.Domain,
extensions: [AshAdmin.Domain]

admin do
show? true
end
```

Resources in each Api will be automagically included in AshAdmin. See [`AshAdmin.Resource`](https://hexdocs.pm/ash_admin/AshAdmin.Resource.html) for more resource configuration options. Specifically, if you app has an actor you will want to configure that. Ash Admin allows you to change actors and therefore doesn't rely on `Ash.set_actor`
Resources in each Domain will be included in AshAdmin. See [`AshAdmin.Resource`](https://hexdocs.pm/ash_admin/AshAdmin.Resource.html) for more resource configuration options. Specifically, if you app has an actor you will want to configure that. Ash Admin allows you to change actors and therefore doesn't rely on `Ash.set_actor`

```elixir
# In your resource that acts as an actor (e.g. User)
use Ash.Resource,
domain: YourDomain,
extensions: [AshAdmin.Resource]

admin do
Expand Down Expand Up @@ -103,7 +104,7 @@ This will allow AshAdmin-generated inline CSS and JS blocks to execute normally.

## Configuration

See the documentation in [`AshAdmin.Resource`](https://hexdocs.pm/ash_admin/AshAdmin.Resource.html) and [`AshAdmin.Api`](https://hexdocs.pm/ash_admin/AshAdmin.Api.html) for information on the available configuration.
See the documentation in [`AshAdmin.Resource`](https://hexdocs.pm/ash_admin/AshAdmin.Resource.html) and [`AshAdmin.Domain`](https://hexdocs.pm/ash_admin/AshAdmin.Domain.html) for information on the available configuration.

## Troubleshooting

Expand Down
25 changes: 12 additions & 13 deletions assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Hooks.JsonEditor = {
},
modes: ["text", "tree"],
},
JSON.parse(document.getElementById(inputId).value)
JSON.parse(document.getElementById(inputId).value),
);

editors[this.el.id] = this.editor;
Expand Down Expand Up @@ -71,7 +71,7 @@ Hooks.JsonView = {
{
mode: "preview",
},
json
json,
);
},
mounted() {
Expand All @@ -81,7 +81,7 @@ Hooks.JsonView = {
{
mode: "preview",
},
json
json,
);
},
};
Expand Down Expand Up @@ -111,13 +111,13 @@ Hooks.Actor = {
document.cookie =
"actor_primary_key" + "=" + payload.primary_key + ";path=/";
document.cookie = "actor_action" + "=" + payload.action + ";path=/";
document.cookie = "actor_api" + "=" + payload.api + ";path=/";
document.cookie = "actor_domain" + "=" + payload.domain + ";path=/";
});
this.handleEvent("clear_actor", () => {
document.cookie = "actor_resource" + "=" + ";path=/";
document.cookie = "actor_primary_key" + "=" + ";path=/";
document.cookie = "actor_action" + ";path=/";
document.cookie = "actor_api" + "=" + ";path=/";
document.cookie = "actor_domain" + "=" + ";path=/";
document.cookie = "actor_authorizing=false;path=/";
document.cookie = "actor_paused=true;path=/";
});
Expand Down Expand Up @@ -160,22 +160,21 @@ Hooks.MaintainAttrs = {
function getCookie(name) {
var re = new RegExp(name + "=([^;]+)");
var value = re.exec(document.cookie);
return (value != null) ? unescape(value[1]) : null;
};

return value != null ? unescape(value[1]) : null;
}

let params = () => {
return {
_csrf_token: csrfToken,
_csrf_token: csrfToken,
tenant: getCookie("tenant"),
actor_resource: getCookie("actor_resource"),
actor_primary_key: getCookie("actor_primary_key"),
actor_action: getCookie("actor_action"),
actor_api: getCookie("actor_api"),
actor_domain: getCookie("actor_domain"),
actor_authorizing: getCookie("actor_authorizing"),
actor_paused: getCookie("actor_paused")
}
}
actor_paused: getCookie("actor_paused"),
};
};

let liveSocket = new LiveSocket(socketPath, Socket, {
params: params,
Expand Down
10 changes: 5 additions & 5 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ config :phoenix, :serve_endpoints, true

if config_env() == :dev do
config :ash_admin,
ash_apis: [
Demo.Accounts.Api,
Demo.Tickets.Api
ash_domains: [
Demo.Accounts.Domain,
Demo.Tickets.Domain
]

config :git_ops,
Expand All @@ -73,7 +73,7 @@ if config_env() == :test do
config :ash, :disable_async?, true

config :ash_admin,
ash_apis: [
AshAdmin.Test.Api
ash_domains: [
AshAdmin.Test.Domain
]
end
13 changes: 0 additions & 13 deletions dev/resources/accounts/api.ex

This file was deleted.

13 changes: 13 additions & 0 deletions dev/resources/accounts/domain.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
defmodule Demo.Accounts.Domain do
@moduledoc false
use Ash.Domain,
extensions: [AshAdmin.Domain]

admin do
show? true
end

resources do
resource Demo.Accounts.User
end
end
7 changes: 0 additions & 7 deletions dev/resources/accounts/registry.ex

This file was deleted.

12 changes: 2 additions & 10 deletions dev/resources/accounts/resources/nested_embed.ex
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
defmodule Demo.Accounts.NestedEmbed do
use Ash.Resource,
data_layer: :embedded,
extensions: [AshAdmin.Resource]

admin do
form do
field :bio, type: :long_text
field :history, type: :long_text
end
end
data_layer: :embedded

attributes do
attribute :tags, {:array, :string}, default: []
attribute :tags, {:array, :string}, default: [], public?: true
end
end
10 changes: 5 additions & 5 deletions dev/resources/accounts/resources/profile.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ defmodule Demo.Accounts.Profile do
end

attributes do
attribute :bio, :string, allow_nil?: false
attribute :history, :string
attribute :tags, {:array, :string}, default: []
attribute :metadata, :map
attribute :nested_embed, Demo.Accounts.NestedEmbed
attribute :bio, :string, allow_nil?: false, public?: true
attribute :history, :string, public?: true
attribute :tags, {:array, :string}, default: [], public?: true
attribute :metadata, :map, public?: true
attribute :nested_embed, Demo.Accounts.NestedEmbed, public?: true
end
end
26 changes: 21 additions & 5 deletions dev/resources/accounts/resources/user.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
defmodule Demo.Accounts.User do
use Ash.Resource,
domain: Demo.Accounts.Domain,
data_layer: AshPostgres.DataLayer,
authorizers: [
Ash.Policy.Authorizer
Expand Down Expand Up @@ -38,6 +39,7 @@ defmodule Demo.Accounts.User do
end

actions do
default_accept :*
read :me, filter: [id: actor(:id)]
read :read, primary?: true
read :by_id do
Expand Down Expand Up @@ -80,16 +82,21 @@ defmodule Demo.Accounts.User do

attribute :first_name, :string do
constraints min_length: 1
public? true
end

attribute :last_name, :string do
constraints min_length: 1
public? true
end

attribute :metadata, :map
attribute :metadata, :map do
public? true
end

attribute :representative, :boolean do
allow_nil? false
public? true
default false
description """
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
Expand All @@ -102,30 +109,39 @@ defmodule Demo.Accounts.User do
end

attribute :admin, :boolean do
public? true
allow_nil? false
default false
end

attribute :api_key, :string do
private? true
sensitive? true
end

attribute :date_of_birth, :date do
public? true
sensitive? true
end

attribute :profile, Demo.Accounts.Profile
attribute :alternate_profiles, {:array, Demo.Accounts.Profile}
attribute :profile, Demo.Accounts.Profile do
public? true
end
attribute :alternate_profiles, {:array, Demo.Accounts.Profile} do
public? true
end
attribute :type, :atom do
public? true
constraints one_of: [:type1, :type2]
default :type1
end

attribute :types, {:array, :atom} do
public? true
constraints items: [one_of: [:type1, :type2]]
end
attribute :tags, {:array, :string}
attribute :tags, {:array, :string} do
public? true
end

timestamps()
end
Expand Down
13 changes: 0 additions & 13 deletions dev/resources/tickets/api.ex

This file was deleted.

10 changes: 6 additions & 4 deletions dev/resources/tickets/comment.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
defmodule Demo.Tickets.Comment do
use Ash.Resource,
domain: Demo.Tickets.Domain,
data_layer: AshPostgres.DataLayer,
extensions: [AshAdmin.Resource]

Expand All @@ -10,6 +11,7 @@ defmodule Demo.Tickets.Comment do
end

actions do
default_accept :*
defaults [:read, :update, :destroy]
create :create do
primary? true
Expand All @@ -29,12 +31,12 @@ defmodule Demo.Tickets.Comment do
attributes do
uuid_primary_key :id

attribute :comment, :string
attribute :resource_id, :uuid, allow_nil?: false
attribute :comment, :string, public?: true
attribute :resource_id, :uuid, allow_nil?: false, public?: true
end

relationships do
belongs_to :commenting_customer, Demo.Tickets.Customer
belongs_to :commenting_representative, Demo.Tickets.Representative
belongs_to :commenting_customer, Demo.Tickets.Customer, public?: true
belongs_to :commenting_representative, Demo.Tickets.Representative, public?: true
end
end
18 changes: 18 additions & 0 deletions dev/resources/tickets/domain.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
defmodule Demo.Tickets.Domain do
@moduledoc false
use Ash.Domain,
extensions: [AshAdmin.Domain]

admin do
show? true
end

resources do
resource(Demo.Tickets.Customer)
resource(Demo.Tickets.Representative)
resource(Demo.Tickets.Ticket)
resource(Demo.Tickets.Comment)
resource(Demo.Tickets.TicketLink)
resource(Demo.Tickets.Organization)
end
end
13 changes: 0 additions & 13 deletions dev/resources/tickets/registry.ex

This file was deleted.

Loading

0 comments on commit 657d36d

Please sign in to comment.