Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

select input for relationship via label_field config on destination resource POC (#209) #210

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
92505e2
Add select field type POC (#209)
netProphET Oct 7, 2024
f68ec16
select field for relationships, revised POC
netProphET Oct 19, 2024
07977e8
chore(deps): bump the production-dependencies group with 2 updates (#…
dependabot[bot] Oct 3, 2024
e7d3097
chore(deps-dev): bump the dev-dependencies group with 3 updates (#208)
dependabot[bot] Oct 3, 2024
93ca22e
chore(deps): bump ash in the production-dependencies group (#211)
dependabot[bot] Oct 10, 2024
0549b22
chore(deps-dev): bump the dev-dependencies group across 1 directory w…
dependabot[bot] Oct 10, 2024
fc9f415
chore(deps): bump the production-dependencies group with 2 updates (#…
dependabot[bot] Oct 17, 2024
ce40e77
chore(deps-dev): bump the dev-dependencies group with 2 updates (#215)
dependabot[bot] Oct 17, 2024
8151d17
improvement: support for generic actions
zachdaniel Oct 17, 2024
870d946
chore: release version v0.11.7
zachdaniel Oct 17, 2024
2ccad0c
chore: typo
zachdaniel Oct 17, 2024
341f1a4
chore: don't show generic actions if there are none
zachdaniel Oct 17, 2024
5c93471
fix: clean up remaining generic action necessities
zachdaniel Oct 17, 2024
22f1637
chore: release version v0.11.8
zachdaniel Oct 17, 2024
75f9c72
improvement: make generic actions list properly configurable
zachdaniel Oct 17, 2024
b9109d0
chore: release version v0.11.9
zachdaniel Oct 17, 2024
d1be340
chore: docs
zachdaniel Oct 17, 2024
837581c
chore: update formatter
zachdaniel Oct 17, 2024
d51feca
chore: update spark for docs fixes
zachdaniel Oct 17, 2024
217fba4
chore(deps-dev): bump the dev-dependencies group with 4 updates (#218)
dependabot[bot] Oct 24, 2024
3893ce2
docs: Add more details of documentation of format_fields (#219)
aifrak Oct 27, 2024
48bf737
chore: clarify scope example in getting started guide
zachdaniel Oct 27, 2024
6cb17bd
fix: various fixes for unions & form mutations
zachdaniel Oct 29, 2024
22d8e5a
chore: release version v0.11.10
zachdaniel Oct 29, 2024
97a181a
fix: fix relationship loading on Resource Update form (#220) (#221)
netProphET Oct 30, 2024
6ae40f2
fix: properly update any kind of form data
zachdaniel Oct 30, 2024
d7e0cdf
chore: release version v0.11.11
zachdaniel Oct 30, 2024
7ef075f
add optional typeahead component for selecting relationship
netProphET Oct 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .formatter.exs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ spark_locals_without_parens = [
field: 1,
field: 2,
format_fields: 1,
generic_actions: 1,
name: 1,
polymorphic_actions: 1,
polymorphic_tables: 1,
Expand Down
47 changes: 47 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,53 @@ See [Conventional Commits](Https://conventionalcommits.org) for commit guideline

<!-- changelog -->

## [v0.11.11](https://github.com/ash-project/ash_admin/compare/v0.11.10...v0.11.11) (2024-10-30)




### Bug Fixes:

* properly update any kind of form data

* fix relationship loading on Resource Update form (#220) (#221)

## [v0.11.10](https://github.com/ash-project/ash_admin/compare/v0.11.9...v0.11.10) (2024-10-29)




### Bug Fixes:

* various fixes for unions & form mutations

## [v0.11.9](https://github.com/ash-project/ash_admin/compare/v0.11.8...v0.11.9) (2024-10-17)




### Improvements:

* make generic actions list properly configurable

## [v0.11.8](https://github.com/ash-project/ash_admin/compare/v0.11.7...v0.11.8) (2024-10-17)




### Bug Fixes:

* clean up remaining generic action necessities

## [v0.11.7](https://github.com/ash-project/ash_admin/compare/v0.11.6...v0.11.7) (2024-10-17)




### Improvements:

* support for generic actions

## [v0.11.6](https://github.com/ash-project/ash_admin/compare/v0.11.5...v0.11.6) (2024-09-19)


Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@

Welcome! This is a super-admin UI dashboard for [Ash Framework](https://hexdocs.pm/ash) applications, built with Phoenix LiveView.

If you are using Phoenix LiveView 1.0.0 release candidate, you will need to use the live_view_1.0 branch of this repo.

## Tutorials

- [Getting Started with AshAdmin](documentation/tutorials/getting-started-with-ash-admin.md)

## Reference

- [AshAdmin.Domain DSL](documentation/dsls/DSL:-AshAdmin.Domain.md)
- [AshAdmin.Resource DSL](documentation/dsls/DSL:-AshAdmin.Resource.md)
- [AshAdmin.Domain DSL](documentation/dsls/DSL-AshAdmin.Domain.md)
- [AshAdmin.Resource DSL](documentation/dsls/DSL-AshAdmin.Resource.md)
43 changes: 40 additions & 3 deletions assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Hooks.JsonEditor = {
target.dispatchEvent(
new Event("change", { bubbles: true, target: this.el.name }),
);
} catch (_e) {}
} catch (_e) { }
},
onChange: () => {
try {
Expand All @@ -37,7 +37,7 @@ Hooks.JsonEditor = {
target.dispatchEvent(
new Event("change", { bubbles: true, target: this.el.name }),
);
} catch (_e) {}
} catch (_e) { }
},
onModeChange: (newMode) => {
hook.mode = newMode;
Expand All @@ -63,7 +63,7 @@ Hooks.JsonEditorSource = {
} else {
}
}
} catch (_e) {}
} catch (_e) { }
},
};

Expand Down Expand Up @@ -163,6 +163,43 @@ Hooks.MaintainAttrs = {
},
};

Hooks.Typeahead = {
mounted() {
const target_id = this.el.getAttribute("data-target-id");
const target_el = document.getElementById(target_id);

switch (this.el.tagName) {
case "INPUT":
this.el.addEventListener("keydown", e => {
if (e.key === "Enter") {
e.preventDefault();
}
});
this.el.addEventListener("keyup", e => {
switch (e.key) {
case "Enter":
case "Escape":
this.el.blur();
window.setTimeout(function () { target_el.dispatchEvent(new Event("input", { bubbles: true })) }, 750);
break;
}
});
break;

case "LI":
this.el.addEventListener("click", e => {
window.setTimeout(function () { target_el.dispatchEvent(new Event("input", { bubbles: true })) }, 750);
});
break;
}
},
updated() {
if (this.el.tagName === "INPUT" && this.el.name.match(/suggest$/) && this.el.value.length === 0) {
this.el.focus();
}
}
};

function getCookie(name) {
var re = new RegExp(name + "=([^;]+)");
var value = re.exec(document.cookie);
Expand Down
1 change: 1 addition & 0 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Config

config :ash, :validate_domain_resource_inclusion?, false
config :ash, :validate_domain_config_inclusion?, false
config :ash, :custom_expressions, [AshAdmin.Expressions.Position]

pg_url = System.get_env("PG_URL") || "postgres:[email protected]"
pg_database = System.get_env("PG_DATABASE") || "ash_admin_dev"
Expand Down
22 changes: 22 additions & 0 deletions dev/resources/tickets/resources/ticket/ticket.ex
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,26 @@ defmodule Demo.Tickets.Ticket do
pagination offset?: true, countable: true, required?: false, default_limit: 25
end

action :ticket_count, :integer do
run fn _, context ->
Ash.count(__MODULE__, Ash.Context.to_opts(context))
end
end

action :fake_ticket, :struct do
constraints instance_of: __MODULE__
run fn _, context ->
{:ok, %__MODULE__{id: Ash.UUID.generate()}}
end
end

action :map_type, :map do
constraints fields: [foo: [type: :integer], bar: [type: :string]]
run fn _, context ->
{:ok, %{foo: 10, bar: "hello"}}
end
end

read :assigned do
filter representative: actor(:id)
pagination offset?: true, countable: true, required?: false, default_limit: 25
Expand Down Expand Up @@ -83,9 +103,11 @@ defmodule Demo.Tickets.Ticket do
update :update do
primary? true
argument :organization_id, :uuid
argument :comments, {:array, :map}
require_atomic? false

change manage_relationship(:organization_id, :organization, type: :append_and_remove)
change manage_relationship(:comments, :comments, type: :direct_control)
end

update :assign do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ Configure the admin dashboard for a given resource.
| [`actor?`](#admin-actor?){: #admin-actor? } | `boolean` | | Whether or not this resource can be used as the actor for requests. |
| [`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. |
| [`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. |
| [`generic_actions`](#admin-generic_actions){: #admin-generic_actions } | `list(atom)` | | A list of generic actions that can be used to show resource details. By default, all actions are included. |
| [`create_actions`](#admin-create_actions){: #admin-create_actions } | `list(atom)` | | A list of create actions that can create records. By default, all actions are included. |
| [`update_actions`](#admin-update_actions){: #admin-update_actions } | `list(atom)` | | A list of update actions that can be used to update records. By default, all actions are included. |
| [`destroy_actions`](#admin-destroy_actions){: #admin-destroy_actions } | `list(atom)` | | A list of destroy actions that can be used to destroy records. By default, all actions are included. |
| [`polymorphic_tables`](#admin-polymorphic_tables){: #admin-polymorphic_tables } | `list(String.t)` | | For resources that use ash_postgres' polymorphism capabilities, you can provide a list of tables that should be available to select. These will be added to the list of derivable tables based on scanning all domains and resources provided to ash_admin. |
| [`polymorphic_actions`](#admin-polymorphic_actions){: #admin-polymorphic_actions } | `list(atom)` | | For resources that use ash_postgres' polymorphism capabilities, you can provide a list of actions that should require a table to be set. If this is not set, then *all* actions will require tables. |
| [`table_columns`](#admin-table_columns){: #admin-table_columns } | `list(atom)` | | The list of attributes to render on the table view. |
| [`format_fields`](#admin-format_fields){: #admin-format_fields } | `list(any)` | | The list of fields and their formats. |
| [`format_fields`](#admin-format_fields){: #admin-format_fields } | `list(any)` | | The list of fields and their formats represented as a MFA. For example: `updated_at: {Timex, :format!, ["{0D}-{0M}-{YYYY} {h12}:{m} {AM}"]}`. |
| [`relationship_display_fields`](#admin-relationship_display_fields){: #admin-relationship_display_fields } | `list(atom)` | | The list of attributes to render when this resource is shown as a relationship on another resource's datatable. |
| [`resource_group`](#admin-resource_group){: #admin-resource_group } | `atom` | | The group in the top resource dropdown that the resource appears in. |
| [`show_sensitive_fields`](#admin-show_sensitive_fields){: #admin-show_sensitive_fields } | `list(atom)` | | The list of fields that should not be redacted in the admin UI even if they are marked as sensitive. |
Expand Down
8 changes: 6 additions & 2 deletions documentation/tutorials/getting-started-with-ash-admin.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Ensure your domains are configured in `config.exs`:
config :my_app, ash_domains: [MyApp.Foo, MyApp.Bar]
```

Add the `AshAdmin.Domain` extension to each domain you want to show in the AshAdmin dashboard, and configure it to show. See [DSL: AshAdmin.Domain](/documentation/dsls/DSL:-AshAdmin.Domain.md) for more configuration options.
Add the `AshAdmin.Domain` extension to each domain you want to show in the AshAdmin dashboard, and configure it to show. See [DSL: AshAdmin.Domain](/documentation/dsls/DSL-AshAdmin.Domain.md) for more configuration options.

```elixir
# In your Domain(s)
Expand All @@ -32,7 +32,7 @@ admin do
end
```

All resources in each Domain will automatically be included in AshAdmin. To configure a resource, use the `AshAdmin.Resource` extension, and then use the [DSL: AshAdmin.Resource](/documentation/dsls/DSL:-AshAdmin.Resource.md) configuration options. Specifically, if your app has an actor you will want to configure that.
All resources in each Domain will automatically be included in AshAdmin. To configure a resource, use the `AshAdmin.Resource` extension, and then use the [DSL: AshAdmin.Resource](/documentation/dsls/DSL-AshAdmin.Resource.md) configuration options. Specifically, if your app has an actor you will want to configure that.

```elixir
# In your resource that acts as an actor (e.g. User)
Expand All @@ -58,6 +58,8 @@ defmodule MyAppWeb.Router do
# Most applications will not need this:
admin_browser_pipeline :browser

# NOTE: `scope/2` here does not have a second argument.
# If it looks like `scope "/", MyAppWeb`, create a *new* scope, don't copy the contents into your scope
scope "/" do
# Pipe it through your browser pipeline
pipe_through [:browser]
Expand Down Expand Up @@ -100,9 +102,11 @@ This will allow AshAdmin-generated inline CSS and JS blocks to execute normally.
## Troubleshooting

#### UI issues

If your admin UI is not responding as expected, check your browser's developer console for content-security-policy violations (see above).

#### Router issues

If you are seeing the following error `(UndefinedFunctionError) function YourAppWeb.AshAdmin.PageLive.__live__/0 is undefined (module YourAppWeb.AshAdmin.PageLive is not available)` it likely means that you added the ash admin route macro under a scope with a prefix. Make sure that you add it under a scope without any prefixes.

```elixir
Expand Down
Loading
Loading