From afcc7ae266e954610cadd7801cbe8f157ab7606c Mon Sep 17 00:00:00 2001 From: Zach Daniel Date: Wed, 22 May 2024 00:00:29 -0400 Subject: [PATCH] fix: properly support lists of embeds closes #152 --- .../20240522034001_migrate_resources7.exs | 21 ++ .../repo/tickets/20240522034001.json | 196 ++++++++++++++++++ .../tickets/resources/ticket/ticket.ex | 6 +- lib/ash_admin/components/core_components.ex | 2 +- lib/ash_admin/components/resource/form.ex | 40 +++- priv/static/assets/app.css | 4 - 6 files changed, 253 insertions(+), 16 deletions(-) create mode 100644 dev/repo/migrations/20240522034001_migrate_resources7.exs create mode 100644 dev/resource_snapshots/repo/tickets/20240522034001.json diff --git a/dev/repo/migrations/20240522034001_migrate_resources7.exs b/dev/repo/migrations/20240522034001_migrate_resources7.exs new file mode 100644 index 0000000..9d43784 --- /dev/null +++ b/dev/repo/migrations/20240522034001_migrate_resources7.exs @@ -0,0 +1,21 @@ +defmodule Demo.Repo.Migrations.MigrateResources7 do + @moduledoc """ + Updates resources based on their most recent snapshots. + + This file was autogenerated with `mix ash_postgres.generate_migrations` + """ + + use Ecto.Migration + + def up do + alter table(:tickets) do + add(:metadatas, {:array, :map}) + end + end + + def down do + alter table(:tickets) do + remove(:metadatas) + end + end +end diff --git a/dev/resource_snapshots/repo/tickets/20240522034001.json b/dev/resource_snapshots/repo/tickets/20240522034001.json new file mode 100644 index 0000000..0947969 --- /dev/null +++ b/dev/resource_snapshots/repo/tickets/20240522034001.json @@ -0,0 +1,196 @@ +{ + "attributes": [ + { + "default": "fragment(\"gen_random_uuid()\")", + "size": null, + "type": "uuid", + "source": "id", + "references": null, + "allow_nil?": false, + "generated?": false, + "primary_key?": true + }, + { + "default": "nil", + "size": null, + "type": "text", + "source": "subject", + "references": null, + "allow_nil?": false, + "generated?": false, + "primary_key?": false + }, + { + "default": "nil", + "size": null, + "type": "map", + "source": "metadata", + "references": null, + "allow_nil?": true, + "generated?": false, + "primary_key?": false + }, + { + "default": "nil", + "size": null, + "type": [ + "array", + "map" + ], + "source": "metadatas", + "references": null, + "allow_nil?": true, + "generated?": false, + "primary_key?": false + }, + { + "default": "nil", + "size": null, + "type": "text", + "source": "description", + "references": null, + "allow_nil?": true, + "generated?": false, + "primary_key?": false + }, + { + "default": "nil", + "size": null, + "type": "text", + "source": "response", + "references": null, + "allow_nil?": true, + "generated?": false, + "primary_key?": false + }, + { + "default": "\"new\"", + "size": null, + "type": "text", + "source": "status", + "references": null, + "allow_nil?": false, + "generated?": false, + "primary_key?": false + }, + { + "default": "fragment(\"(now() AT TIME ZONE 'utc')\")", + "size": null, + "type": "utc_datetime_usec", + "source": "inserted_at", + "references": null, + "allow_nil?": false, + "generated?": false, + "primary_key?": false + }, + { + "default": "fragment(\"(now() AT TIME ZONE 'utc')\")", + "size": null, + "type": "utc_datetime_usec", + "source": "updated_at", + "references": null, + "allow_nil?": false, + "generated?": false, + "primary_key?": false + }, + { + "default": "nil", + "size": null, + "type": "uuid", + "source": "reporter_id", + "references": { + "name": "tickets_reporter_id_fkey", + "table": "users", + "schema": "public", + "multitenancy": { + "global": null, + "attribute": null, + "strategy": null + }, + "on_update": null, + "primary_key?": true, + "on_delete": null, + "destination_attribute": "id", + "deferrable": false, + "match_type": null, + "match_with": null, + "destination_attribute_default": null, + "destination_attribute_generated": null + }, + "allow_nil?": true, + "generated?": false, + "primary_key?": false + }, + { + "default": "nil", + "size": null, + "type": "uuid", + "source": "representative_id", + "references": { + "name": "tickets_representative_id_fkey", + "table": "users", + "schema": "public", + "multitenancy": { + "global": null, + "attribute": null, + "strategy": null + }, + "on_update": null, + "primary_key?": true, + "on_delete": null, + "destination_attribute": "id", + "deferrable": false, + "match_type": null, + "match_with": null, + "destination_attribute_default": null, + "destination_attribute_generated": null + }, + "allow_nil?": true, + "generated?": false, + "primary_key?": false + }, + { + "default": "nil", + "size": null, + "type": "uuid", + "source": "organization_id", + "references": { + "name": "tickets_organization_id_fkey", + "table": "organizations", + "schema": "public", + "multitenancy": { + "global": null, + "attribute": null, + "strategy": null + }, + "on_update": null, + "primary_key?": true, + "on_delete": null, + "destination_attribute": "id", + "deferrable": false, + "match_type": null, + "match_with": null, + "destination_attribute_default": null, + "destination_attribute_generated": null + }, + "allow_nil?": false, + "generated?": false, + "primary_key?": false + } + ], + "table": "tickets", + "hash": "3DE3CF59D6C0732CC835F8ACD8D68541934549BB9086EDAC65177EDF6A62FECA", + "repo": "Elixir.Demo.Repo", + "schema": null, + "identities": [], + "multitenancy": { + "global": null, + "attribute": null, + "strategy": null + }, + "base_filter": null, + "check_constraints": [], + "custom_indexes": [], + "custom_statements": [], + "has_create_action": true +} \ No newline at end of file diff --git a/dev/resources/tickets/resources/ticket/ticket.ex b/dev/resources/tickets/resources/ticket/ticket.ex index 2c9e5b1..80d8763 100644 --- a/dev/resources/tickets/resources/ticket/ticket.ex +++ b/dev/resources/tickets/resources/ticket/ticket.ex @@ -69,7 +69,7 @@ defmodule Demo.Tickets.Ticket do end create :open do - accept [:subject, :metadata] + accept [:subject, :metadata, :metadatas] primary? true argument :representative, :map, allow_nil?: false argument :organization, :map, allow_nil?: false @@ -146,6 +146,10 @@ defmodule Demo.Tickets.Ticket do public? true end + attribute :metadatas, {:array, Demo.Tickets.Ticket.Types.Metadata} do + public? true + end + attribute :description, :string do public? true end diff --git a/lib/ash_admin/components/core_components.ex b/lib/ash_admin/components/core_components.ex index 186f2dc..a6327b4 100644 --- a/lib/ash_admin/components/core_components.ex +++ b/lib/ash_admin/components/core_components.ex @@ -326,7 +326,7 @@ defmodule AshAdmin.CoreComponents do