From 5d1b3a1d5bbf77caa5758da0f29a118e166aa6a9 Mon Sep 17 00:00:00 2001 From: Zach Daniel Date: Tue, 2 Apr 2024 22:01:11 -0400 Subject: [PATCH] fix: get checks passing, fix various bugs --- .check.exs | 1 + lib/ash_admin/components/resource/form.ex | 4 +- .../components/resource/metadata_table.ex | 4 +- lib/ash_admin/components/resource/show.ex | 113 ++++++++++++++---- lib/ash_admin/components/resource/table.ex | 59 +++++++-- mix.exs | 2 +- mix.lock | 4 - priv/static/assets/app.js | 27 +++-- test/support/resources/post.ex | 4 +- 9 files changed, 166 insertions(+), 52 deletions(-) diff --git a/.check.exs b/.check.exs index 1a163ab..b928a32 100644 --- a/.check.exs +++ b/.check.exs @@ -8,6 +8,7 @@ ## curated tools may be disabled (e.g. the check for compilation warnings) # {:compiler, false}, {:npm_test, false}, + {:gettext, false}, {:check_formatter, command: "mix spark.formatter --check"} ## ...or adjusted (e.g. use one-line formatter for more compact credo output) diff --git a/lib/ash_admin/components/resource/form.ex b/lib/ash_admin/components/resource/form.ex index 179544b..93b0bc0 100644 --- a/lib/ash_admin/components/resource/form.ex +++ b/lib/ash_admin/components/resource/form.ex @@ -1462,7 +1462,7 @@ defmodule AshAdmin.Components.Resource.Form do def relationships(resource, action, nil) do resource |> Ash.Resource.Info.relationships() - |> Enum.filter(& &1.writable? && &1.public?) + |> Enum.filter(&(&1.writable? && &1.public?)) |> only_accepted(action) |> sort_relationships() end @@ -1523,7 +1523,7 @@ defmodule AshAdmin.Components.Resource.Form do attributes = resource |> Ash.Resource.Info.attributes() - |> Enum.filter(& &1.writable? && &1.public?) + |> Enum.filter(&(&1.writable? && &1.public?)) |> Enum.reject(&(&1.name == :autogenerated_id)) |> only_accepted(action) |> Enum.reject(fn attribute -> diff --git a/lib/ash_admin/components/resource/metadata_table.ex b/lib/ash_admin/components/resource/metadata_table.ex index e1dc794..d880695 100644 --- a/lib/ash_admin/components/resource/metadata_table.ex +++ b/lib/ash_admin/components/resource/metadata_table.ex @@ -157,7 +157,7 @@ defmodule AshAdmin.Components.Resource.MetadataTable do defp attributes(resource) do resource |> Ash.Resource.Info.attributes() - |> Enum.sort_by(& not(&1.public?)) + |> Enum.sort_by(&(not &1.public?)) end defp attribute_type(attribute) do @@ -173,6 +173,6 @@ defmodule AshAdmin.Components.Resource.MetadataTable do defp relationships(resource) do resource |> Ash.Resource.Info.relationships() - |> Enum.sort_by(& not(&1.public?)) + |> Enum.sort_by(&(not &1.public?)) end end diff --git a/lib/ash_admin/components/resource/show.ex b/lib/ash_admin/components/resource/show.ex index e1d6393..052aeb3 100644 --- a/lib/ash_admin/components/resource/show.ex +++ b/lib/ash_admin/components/resource/show.ex @@ -144,7 +144,7 @@ defmodule AshAdmin.Components.Resource.Show do ~H"""
- <%= render_attributes(assigns, @record, @destination) %> + <%= render_attributes(assigns, @record, @destination, @name) %>
<.link :if={AshAdmin.Resource.show_action(@destination)} @@ -192,7 +192,7 @@ defmodule AshAdmin.Components.Resource.Show do """ end - defp render_attributes(assigns, record, resource) do + defp render_attributes(assigns, record, resource, relationship_name \\ nil) do {attributes, flags, bottom_attributes, _} = AshAdmin.Components.Resource.Form.attributes(resource, :show) @@ -202,7 +202,8 @@ defmodule AshAdmin.Components.Resource.Show do resource: resource, attributes: attributes, flags: flags, - bottom_attributes: bottom_attributes + bottom_attributes: bottom_attributes, + relationship_name: relationship_name ) ~H""" @@ -219,7 +220,13 @@ defmodule AshAdmin.Components.Resource.Show do >
<%= to_name(attribute.name) %>
- <%= render_maybe_sensitive_attribute(assigns, @resource, @record, attribute) %> + <%= render_maybe_sensitive_attribute( + assigns, + @resource, + @record, + attribute, + @relationship_name + ) %>
@@ -241,7 +248,13 @@ defmodule AshAdmin.Components.Resource.Show do >
<%= to_name(attribute.name) %>
- <%= render_maybe_sensitive_attribute(assigns, @resource, @record, attribute) %> + <%= render_maybe_sensitive_attribute( + assigns, + @resource, + @record, + attribute, + @relationship_name + ) %>
@@ -264,39 +277,46 @@ defmodule AshAdmin.Components.Resource.Show do >
<%= to_name(attribute.name) %>
- <%= render_maybe_sensitive_attribute(assigns, @resource, @record, attribute) %> + <%= render_maybe_sensitive_attribute( + assigns, + @resource, + @record, + attribute, + @relationship_name + ) %>
""" end - defp render_maybe_sensitive_attribute(assigns, resource, record, attribute) do - assigns = assign(assigns, attribute: attribute) + defp render_maybe_sensitive_attribute(assigns, resource, record, attribute, relationship_name) do + assigns = assign(assigns, attribute: attribute, relationship_name: relationship_name) show_sensitive_fields = AshAdmin.Resource.show_sensitive_fields(resource) if attribute.sensitive? && not Enum.member?(show_sensitive_fields, attribute.name) do ~H""" <.live_component - id={"#{@record.id}-#{@attribute.name}"} + id={"#{@relationship_name}_#{AshAdmin.Helpers.encode_primary_key(@record)}-#{@attribute.name}"} module={SensitiveAttribute} value={Map.get(@record, @attribute.name)} > - <%= render_attribute(assigns, @resource, @record, @attribute) %> + <%= render_attribute(assigns, @resource, @record, @attribute, @relationship_name) %> """ else - render_attribute(assigns, resource, record, attribute) + render_attribute(assigns, resource, record, attribute, relationship_name) end end - defp render_attribute(assigns, resource, record, attribute, nested? \\ false) + defp render_attribute(assigns, resource, record, attribute, relationship_name, nested? \\ false) defp render_attribute( assigns, resource, record, %{type: {:array, type}, name: name} = attribute, + relationship_name, nested? ) do if Map.get(record, name) in [[], nil] do @@ -309,6 +329,7 @@ defmodule AshAdmin.Components.Resource.Show do type: type, name: name, attribute: attribute, + relationship_name: relationship_name, nested: nested? ) @@ -321,6 +342,7 @@ defmodule AshAdmin.Components.Resource.Show do @resource, Map.put(@record, @name, value), %{@attribute | type: @type}, + @relationship_name, true ) %> @@ -334,6 +356,7 @@ defmodule AshAdmin.Components.Resource.Show do @resource, Map.put(@record, @name, value), %{@attribute | type: @type}, + @relationship_name, true ) %> @@ -349,21 +372,42 @@ defmodule AshAdmin.Components.Resource.Show do resource, record, %{type: {:array, Ash.Type.Map}} = attribute, + relationship_name, nested? ) do - render_attribute(assigns, resource, record, %{attribute | type: Ash.Type.Map}, nested?) + render_attribute( + assigns, + resource, + record, + %{attribute | type: Ash.Type.Map}, + relationship_name, + nested? + ) end - defp render_attribute(assigns, _resource, record, %{type: Ash.Type.Map} = attribute, _nested?) do + defp render_attribute( + assigns, + _resource, + record, + %{type: Ash.Type.Map} = attribute, + relationship_name, + _nested? + ) do encoded = Jason.encode!(Map.get(record, attribute.name)) - assigns = assign(assigns, record: record, attribute: attribute, encoded: encoded) + assigns = + assign(assigns, + record: record, + attribute: attribute, + encoded: encoded, + relationship_name: relationship_name + ) ~H"""
""" rescue @@ -371,7 +415,14 @@ defmodule AshAdmin.Components.Resource.Show do "..." end - defp render_attribute(assigns, _resource, record, %{name: name, type: Ash.Type.Boolean}, _) do + defp render_attribute( + assigns, + _resource, + record, + %{name: name, type: Ash.Type.Boolean}, + _relationship_name, + _ + ) do case Map.get(record, name) do true -> ~H""" @@ -390,7 +441,14 @@ defmodule AshAdmin.Components.Resource.Show do end end - defp render_attribute(assigns, _resource, record, %{name: name, type: Ash.Type.Binary}, _) do + defp render_attribute( + assigns, + _resource, + record, + %{name: name, type: Ash.Type.Binary}, + _relationship_name, + _ + ) do if Map.get(record, name) do ~H""" (binary data) @@ -400,7 +458,7 @@ defmodule AshAdmin.Components.Resource.Show do end end - defp render_attribute(assigns, resource, record, attribute, nested?) do + defp render_attribute(assigns, resource, record, attribute, relationship_name, nested?) do if Ash.Type.embedded_type?(attribute.type) do if Map.get(record, attribute.name) in [nil, []] do "None" @@ -410,17 +468,28 @@ defmodule AshAdmin.Components.Resource.Show do resource: resource, record: record, attribute: attribute, - nested: nested? + nested: nested?, + relationship_name: relationship_name ) ~H""" <%= if @nested do %>
- <%= render_attributes(assigns, Map.get(@record, @attribute.name), @attribute.type) %> + <%= render_attributes( + assigns, + Map.get(@record, @attribute.name), + @attribute.type, + @relationship_name + ) %>
<% else %>
- <%= render_attributes(assigns, Map.get(@record, @attribute.name), @attribute.type) %> + <%= render_attributes( + assigns, + Map.get(@record, @attribute.name), + @attribute.type, + @relationship_name + ) %>
<% end %> """ diff --git a/lib/ash_admin/components/resource/table.ex b/lib/ash_admin/components/resource/table.ex index a30d8ff..0df8810 100644 --- a/lib/ash_admin/components/resource/table.ex +++ b/lib/ash_admin/components/resource/table.ex @@ -101,8 +101,24 @@ defmodule AshAdmin.Components.Resource.Table do |> Enum.reject(&(&1.name in skip)) end - defp render_attribute(domain, record, attribute, formats, show_sensitive_fields, actor, relationship_name) do - process_attribute(domain, record, attribute, formats, show_sensitive_fields, actor, relationship_name) + defp render_attribute( + domain, + record, + attribute, + formats, + show_sensitive_fields, + actor, + relationship_name + ) do + process_attribute( + domain, + record, + attribute, + formats, + show_sensitive_fields, + actor, + relationship_name + ) rescue _ -> "..." @@ -138,13 +154,29 @@ defmodule AshAdmin.Components.Resource.Table do attributes = attributes(attribute.destination, display_attributes, []) Enum.map_join(attributes, " - ", fn x -> - render_attribute(domain, relationship, x, formats, show_sensitive_fields, actor, relationship_name) + render_attribute( + domain, + relationship, + x, + formats, + show_sensitive_fields, + actor, + relationship_name + ) end) end end end - defp process_attribute(_, record, %struct{} = attribute, formats, show_sensitive_fields, _actor, relationship_name) + defp process_attribute( + _, + record, + %struct{} = attribute, + formats, + show_sensitive_fields, + _actor, + relationship_name + ) when struct in [Ash.Resource.Attribute, Ash.Resource.Aggregate, Ash.Resource.Calculation] do {mod, func, args} = Keyword.get(formats || [], attribute.name, {Phoenix.HTML.Safe, :to_iodata, []}) @@ -162,16 +194,29 @@ defmodule AshAdmin.Components.Resource.Table do end end - defp process_attribute(_domain, _record, _attr, _formats, _show_sensitive_fields, _actor) do + defp process_attribute( + _domain, + _record, + _attr, + _formats, + _show_sensitive_fields, + _actor, + _relationship_name + ) do "..." end defp format_sensitive_value(value, attribute, record, relationship_name) do - assigns = %{value: value, attribute: attribute, record: record, relationship_name: relationship_name} + assigns = %{ + value: value, + attribute: attribute, + record: record, + relationship_name: relationship_name + } ~H""" <.live_component - id={"#{@relationship_name}-#{@record.id}-#{@attribute.name}"} + id={"#{@relationship_name}-#{AshAdmin.Helpers.encode_primary_key(@record)}-#{@attribute.name}"} module={SensitiveAttribute} value={@value} > diff --git a/mix.exs b/mix.exs index ce99672..80249d4 100644 --- a/mix.exs +++ b/mix.exs @@ -37,7 +37,7 @@ defmodule AshAdmin.MixProject do end defp elixirc_paths(:test) do - ["test/support", "lib"] + ["test/support", "lib", "dev"] end defp elixirc_paths(:prod) do diff --git a/mix.lock b/mix.lock index 1884264..f092662 100644 --- a/mix.lock +++ b/mix.lock @@ -12,11 +12,9 @@ "db_connection": {:hex, :db_connection, "2.6.0", "77d835c472b5b67fc4f29556dee74bf511bbafecdcaf98c27d27fa5918152086", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "c2f992d15725e721ec7fbc1189d4ecdb8afef76648c746a8e1cad35e3b8a35f3"}, "decimal": {:hex, :decimal, "2.1.1", "5611dca5d4b2c3dd497dec8f68751f1f1a54755e8ed2a966c2633cf885973ad6", [:mix], [], "hexpm", "53cfe5f497ed0e7771ae1a475575603d77425099ba5faef9394932b35020ffcc"}, "dialyxir": {:hex, :dialyxir, "1.4.3", "edd0124f358f0b9e95bfe53a9fcf806d615d8f838e2202a9f430d59566b6b53b", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "bf2cfb75cd5c5006bec30141b131663299c661a864ec7fbbc72dfa557487a986"}, - "earmark": {:hex, :earmark, "1.4.46", "8c7287bd3137e99d26ae4643e5b7ef2129a260e3dcf41f251750cb4563c8fb81", [:mix], [], "hexpm", "798d86db3d79964e759ddc0c077d5eb254968ed426399fbf5a62de2b5ff8910a"}, "earmark_parser": {:hex, :earmark_parser, "1.4.39", "424642f8335b05bb9eb611aa1564c148a8ee35c9c8a8bba6e129d51a3e3c6769", [:mix], [], "hexpm", "06553a88d1f1846da9ef066b87b57c6f605552cfbe40d20bd8d59cc6bde41944"}, "ecto": {:hex, :ecto, "3.11.2", "e1d26be989db350a633667c5cda9c3d115ae779b66da567c68c80cfb26a8c9ee", [:mix], [{:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "3c38bca2c6f8d8023f2145326cc8a80100c3ffe4dcbd9842ff867f7fc6156c65"}, "ecto_sql": {:hex, :ecto_sql, "3.11.1", "e9abf28ae27ef3916b43545f9578b4750956ccea444853606472089e7d169470", [:mix], [{:db_connection, "~> 2.4.1 or ~> 2.5", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.11.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.6.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.16.0 or ~> 0.17.0 or ~> 1.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.1 or ~> 2.2", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "ce14063ab3514424276e7e360108ad6c2308f6d88164a076aac8a387e1fea634"}, - "elixir_make": {:hex, :elixir_make, "0.8.2", "cd4a5a75891362e9207adaac7e66223fd256ec2518ae013af7f10c9c85b50b5c", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:certifi, "~> 2.0", [hex: :certifi, repo: "hexpm", optional: true]}], "hexpm", "9d9607d640c372a7291e5a56ce655aa2351897929be20bd211648fdb79e725dc"}, "erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"}, "esbuild": {:hex, :esbuild, "0.8.1", "0cbf919f0eccb136d2eeef0df49c4acf55336de864e63594adcea3814f3edf41", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}, {:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "25fc876a67c13cb0a776e7b5d7974851556baeda2085296c14ab48555ea7560f"}, "ets": {:hex, :ets, "0.9.0", "79c6a6c205436780486f72d84230c6cba2f8a9920456750ddd1e47389107d5fd", [:mix], [], "hexpm", "2861fdfb04bcaeff370f1a5904eec864f0a56dcfebe5921ea9aadf2a481c822b"}, @@ -35,7 +33,6 @@ "makeup_elixir": {:hex, :makeup_elixir, "0.16.2", "627e84b8e8bf22e60a2579dad15067c755531fea049ae26ef1020cad58fe9578", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "41193978704763f6bbe6cc2758b84909e62984c7752b3784bd3c218bb341706b"}, "makeup_erlang": {:hex, :makeup_erlang, "0.1.5", "e0ff5a7c708dda34311f7522a8758e23bfcd7d8d8068dc312b5eb41c6fd76eba", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "94d2e986428585a21516d7d7149781480013c56e30c6a233534bedf38867a59a"}, "mime": {:hex, :mime, "2.0.5", "dc34c8efd439abe6ae0343edbb8556f4d63f178594894720607772a041b04b02", [:mix], [], "hexpm", "da0d64a365c45bc9935cc5c8a7fc5e49a0e0f9932a761c55d6c52b142780a05c"}, - "nimble_options": {:hex, :nimble_options, "1.1.0", "3b31a57ede9cb1502071fade751ab0c7b8dbe75a9a4c2b5bbb0943a690b63172", [:mix], [], "hexpm", "8bbbb3941af3ca9acc7835f5655ea062111c9c27bcac53e004460dfd19008a99"}, "nimble_parsec": {:hex, :nimble_parsec, "1.4.0", "51f9b613ea62cfa97b25ccc2c1b4216e81df970acd8e16e8d1bdc58fef21370d", [:mix], [], "hexpm", "9c565862810fb383e9838c1dd2d7d2c437b3d13b267414ba6af33e50d2d1cf28"}, "phoenix": {:hex, :phoenix, "1.7.11", "1d88fc6b05ab0c735b250932c4e6e33bfa1c186f76dcf623d8dd52f07d6379c7", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.1", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:phoenix_template, "~> 1.0", [hex: :phoenix_template, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 2.0", [hex: :phoenix_view, repo: "hexpm", optional: true]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.7", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:plug_crypto, "~> 1.2 or ~> 2.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}, {:websock_adapter, "~> 0.5.3", [hex: :websock_adapter, repo: "hexpm", optional: false]}], "hexpm", "b1ec57f2e40316b306708fe59b92a16b9f6f4bf50ccfa41aa8c7feb79e0ec02a"}, "phoenix_html": {:hex, :phoenix_html, "4.1.1", "4c064fd3873d12ebb1388425a8f2a19348cef56e7289e1998e2d2fa758aa982e", [:mix], [], "hexpm", "f2f2df5a72bc9a2f510b21497fd7d2b86d932ec0598f0210fed4114adc546c6f"}, @@ -44,7 +41,6 @@ "phoenix_pubsub": {:hex, :phoenix_pubsub, "2.1.3", "3168d78ba41835aecad272d5e8cd51aa87a7ac9eb836eabc42f6e57538e3731d", [:mix], [], "hexpm", "bba06bc1dcfd8cb086759f0edc94a8ba2bc8896d5331a1e2c2902bf8e36ee502"}, "phoenix_template": {:hex, :phoenix_template, "1.0.4", "e2092c132f3b5e5b2d49c96695342eb36d0ed514c5b252a77048d5969330d639", [:mix], [{:phoenix_html, "~> 2.14.2 or ~> 3.0 or ~> 4.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}], "hexpm", "2c0c81f0e5c6753faf5cca2f229c9709919aba34fab866d3bc05060c9c444206"}, "phoenix_view": {:hex, :phoenix_view, "2.0.3", "4d32c4817fce933693741deeb99ef1392619f942633dde834a5163124813aad3", [:mix], [{:phoenix_html, "~> 2.14.2 or ~> 3.0 or ~> 4.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:phoenix_template, "~> 1.0", [hex: :phoenix_template, repo: "hexpm", optional: false]}], "hexpm", "cd34049af41be2c627df99cd4eaa71fc52a328c0c3d8e7d4aa28f880c30e7f64"}, - "picosat_elixir": {:hex, :picosat_elixir, "0.2.3", "bf326d0f179fbb3b706bb2c15fbc367dacfa2517157d090fdfc32edae004c597", [:make, :mix], [{:elixir_make, "~> 0.6", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm", "f76c9db2dec9d2561ffaa9be35f65403d53e984e8cd99c832383b7ab78c16c66"}, "plug": {:hex, :plug, "1.15.3", "712976f504418f6dff0a3e554c40d705a9bcf89a7ccef92fc6a5ef8f16a30a97", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2 or ~> 2.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "cc4365a3c010a56af402e0809208873d113e9c38c401cabd88027ef4f5c01fd2"}, "plug_cowboy": {:hex, :plug_cowboy, "2.7.0", "3ae9369c60641084363b08fe90267cbdd316df57e3557ea522114b30b63256ea", [:mix], [{:cowboy, "~> 2.7.0 or ~> 2.8.0 or ~> 2.9.0 or ~> 2.10.0", [hex: :cowboy, repo: "hexpm", optional: false]}, {:cowboy_telemetry, "~> 0.3", [hex: :cowboy_telemetry, repo: "hexpm", optional: false]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "d85444fb8aa1f2fc62eabe83bbe387d81510d773886774ebdcb429b3da3c1a4a"}, "plug_crypto": {:hex, :plug_crypto, "2.0.0", "77515cc10af06645abbfb5e6ad7a3e9714f805ae118fa1a70205f80d2d70fe73", [:mix], [], "hexpm", "53695bae57cc4e54566d993eb01074e4d894b65a3766f1c43e2c61a1b0f45ea9"}, diff --git a/priv/static/assets/app.js b/priv/static/assets/app.js index 3e797be..ca096ae 100644 --- a/priv/static/assets/app.js +++ b/priv/static/assets/app.js @@ -2307,14 +2307,17 @@ findPhxChildren(el, parentId) { return this.all(el, `${PHX_VIEW_SELECTOR}[${PHX_PARENT_ID}="${parentId}"]`); }, - findParentCIDs(node, cids) { - let initial = new Set(cids); - let parentCids = cids.reduce((acc, cid) => { - let selector = `[${PHX_COMPONENT}="${cid}"] [${PHX_COMPONENT}]`; - this.filterWithinSameLiveView(this.all(node, selector), node).map((el) => parseInt(el.getAttribute(PHX_COMPONENT))).forEach((childCID) => acc.delete(childCID)); - return acc; - }, initial); - return parentCids.size === 0 ? new Set(cids) : parentCids; + findExistingParentCIDs(node, cids) { + let parentCids = /* @__PURE__ */ new Set(); + let childrenCids = /* @__PURE__ */ new Set(); + cids.forEach((cid) => { + this.filterWithinSameLiveView(this.all(node, `[${PHX_COMPONENT}="${cid}"]`), node).forEach((parent) => { + parentCids.add(cid); + this.all(parent, `[${PHX_COMPONENT}]`).map((el) => parseInt(el.getAttribute(PHX_COMPONENT))).forEach((childCID) => childrenCids.add(childCID)); + }); + }); + childrenCids.forEach((childCid) => parentCids.delete(childCid)); + return parentCids; }, filterWithinSameLiveView(nodes, parent) { if (parent.querySelector(PHX_VIEW_SELECTOR)) { @@ -4918,7 +4921,7 @@ removing illegal node: "${(childNode.outerHTML || childNode.nodeValue).trim()}" let phxChildrenAdded = false; if (this.rendered.isComponentOnlyDiff(diff)) { this.liveSocket.time("component patch complete", () => { - let parentCids = dom_default.findParentCIDs(this.el, this.rendered.componentCIDs(diff)); + let parentCids = dom_default.findExistingParentCIDs(this.el, this.rendered.componentCIDs(diff)); parentCids.forEach((parentCID) => { if (this.componentPatch(this.rendered.getComponent(diff, parentCID), parentCID)) { phxChildrenAdded = true; @@ -6569,13 +6572,13 @@ removing illegal node: "${(childNode.outerHTML || childNode.nodeValue).trim()}" document.cookie = "actor_resource=" + payload.resource + ";path=/"; 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=/"; }); @@ -6623,7 +6626,7 @@ removing illegal node: "${(childNode.outerHTML || childNode.nodeValue).trim()}" 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") }; diff --git a/test/support/resources/post.ex b/test/support/resources/post.ex index 6d22f71..36b2d8e 100644 --- a/test/support/resources/post.ex +++ b/test/support/resources/post.ex @@ -1,7 +1,7 @@ defmodule AshAdmin.Test.Post do @moduledoc false use Ash.Resource, - domain: Demo.Tickets.Domain, + domain: AshAdmin.Test.Domain, data_layer: Ash.DataLayer.Ets attributes do @@ -9,7 +9,7 @@ defmodule AshAdmin.Test.Post do attribute :body, :string do allow_nil?(false) - public? true + public?(true) end end end