changed
CHANGELOG.md
|
@@ -5,6 +5,21 @@ See [Conventional Commits](Https://conventionalcommits.org) for commit guideline
|
5
5
|
|
6
6
|
<!-- changelog -->
|
7
7
|
|
8
|
+ ## [v2.1.7](https://github.com/ash-project/ash_phoenix/compare/v2.1.6...v2.1.7) (2024-10-29)
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+ ### Bug Fixes:
|
14
|
+
|
15
|
+ * set _union_type param when unnesting a resource in a union
|
16
|
+
|
17
|
+ * don't wrap resources inside of unions as WrappedValue
|
18
|
+
|
19
|
+ * warn on missing `params` on submit
|
20
|
+
|
21
|
+ * unwrap unions & wrapped values when fetching values
|
22
|
+
|
8
23
|
## [v2.1.6](https://github.com/ash-project/ash_phoenix/compare/v2.1.5...v2.1.6) (2024-10-17)
|
changed
README.md
|
@@ -15,7 +15,7 @@ Welcome! This is the package for integrating [Phoenix Framework](https://www.pho
|
15
15
|
Add `ash_phoenix` to your list of dependencies in `mix.exs`:
|
16
16
|
|
17
17
|
```elixir
|
18
|
- {:ash_phoenix, "~> 2.1.6"}
|
18
|
+ {:ash_phoenix, "~> 2.1.7"}
|
19
19
|
```
|
20
20
|
|
21
21
|
## Whats in the box?
|
changed
documentation/topics/union-forms.md
|
@@ -84,7 +84,7 @@ We might have a form like this:
|
84
84
|
<.inputs_for :let={fc} field={@form[:content]}>
|
85
85
|
<!-- Dropdown for setting the union type -->
|
86
86
|
<.input
|
87
|
- field={fc[:_union_type}
|
87
|
+ field={fc[:_union_type]}
|
88
88
|
phx-change="type-changed"
|
89
89
|
type="select"
|
90
90
|
options={[Normal: "normal", Special: "special"]}
|
changed
hex_metadata.config
|
@@ -1,7 +1,7 @@
|
1
1
|
{<<"links">>,
|
2
2
|
[{<<"GitHub">>,<<"https://github.com/ash-project/ash_phoenix">>}]}.
|
3
3
|
{<<"name">>,<<"ash_phoenix">>}.
|
4
|
- {<<"version">>,<<"2.1.6">>}.
|
4
|
+ {<<"version">>,<<"2.1.7">>}.
|
5
5
|
{<<"description">>,<<"Utilities for integrating Ash and Phoenix">>}.
|
6
6
|
{<<"elixir">>,<<"~> 1.11">>}.
|
7
7
|
{<<"app">>,<<"ash_phoenix">>}.
|
changed
lib/ash_phoenix/form/auto.ex
|
@@ -347,7 +347,7 @@ defmodule AshPhoenix.Form.Auto do
|
347
347
|
Map.get(data, config[:tag]) == value
|
348
348
|
|
349
349
|
value ->
|
350
|
- data[config[:tag]] == value
|
350
|
+ Map.get(data, config[:tag]) == value
|
351
351
|
end
|
352
352
|
else
|
353
353
|
false
|
changed
lib/ash_phoenix/form/form.ex
|
@@ -397,20 +397,32 @@ defmodule AshPhoenix.Form do
|
397
397
|
#{Spark.Options.docs(@nested_form_opts)}
|
398
398
|
"""
|
399
399
|
def for_action(resource_or_data, action, opts \\ []) do
|
400
|
- {resource, data} =
|
400
|
+ {resource, data, opts} =
|
401
401
|
case resource_or_data do
|
402
402
|
module when is_atom(resource_or_data) and not is_nil(resource_or_data) ->
|
403
|
- {module, module.__struct__()}
|
403
|
+ {module, module.__struct__(), opts}
|
404
|
+
|
405
|
+ %Ash.Union{value: %resource{} = data, type: type} ->
|
406
|
+ if Ash.Resource.Info.resource?(resource) do
|
407
|
+ opts =
|
408
|
+ opts
|
409
|
+ |> Keyword.put_new(:params, %{})
|
410
|
+ |> Keyword.update!(:params, &Map.put(&1, "_union_type", to_string(type)))
|
411
|
+
|
412
|
+ {resource, data, opts}
|
413
|
+ else
|
414
|
+ {AshPhoenix.Form.WrappedValue, %AshPhoenix.Form.WrappedValue{value: data}, opts}
|
415
|
+ end
|
404
416
|
|
405
417
|
%resource{} = data ->
|
406
418
|
if Ash.Resource.Info.resource?(resource) do
|
407
|
- {resource, data}
|
419
|
+ {resource, data, opts}
|
408
420
|
else
|
409
|
- {AshPhoenix.Form.WrappedValue, %AshPhoenix.Form.WrappedValue{value: data}}
|
421
|
+ {AshPhoenix.Form.WrappedValue, %AshPhoenix.Form.WrappedValue{value: data}, opts}
|
410
422
|
end
|
411
423
|
|
412
424
|
value ->
|
413
|
- {AshPhoenix.Form.WrappedValue, %AshPhoenix.Form.WrappedValue{value: value}}
|
425
|
+ {AshPhoenix.Form.WrappedValue, %AshPhoenix.Form.WrappedValue{value: value}, opts}
|
414
426
|
end
|
415
427
|
|
416
428
|
opts = update_opts(opts, data, opts[:params] || %{})
|
|
@@ -1818,6 +1830,21 @@ defmodule AshPhoenix.Form do
|
1818
1830
|
"""
|
1819
1831
|
end
|
1820
1832
|
|
1833
|
+ if !Keyword.has_key?(opts, :params) do
|
1834
|
+ IO.warn("""
|
1835
|
+ The `params` option should be supplied at all times. This will be required in a future major release.
|
1836
|
+ To silence this warning without providing `params`, you can pass `params: nil`.
|
1837
|
+
|
1838
|
+ For example:
|
1839
|
+
|
1840
|
+ def handle_event("submit", %{"form" => params}, socket) do
|
1841
|
+ case AshPhoenix.Form.submit(socket.assigns.form, params: params) do
|
1842
|
+ ...
|
1843
|
+ end
|
1844
|
+ end
|
1845
|
+ """)
|
1846
|
+ end
|
1847
|
+
|
1821
1848
|
changeset_opts =
|
1822
1849
|
drop_form_opts(form.opts)
|
1823
1850
|
|
|
@@ -2727,7 +2754,7 @@ defmodule AshPhoenix.Form do
|
2727
2754
|
:error <- get_casted_value(changeset, field),
|
2728
2755
|
:error <- Ash.Changeset.fetch_argument(changeset, field),
|
2729
2756
|
:error <- get_non_attribute_non_argument_param(changeset, form, field),
|
2730
|
- :error <- Map.fetch(changeset.data, field) do
|
2757
|
+ :error <- get_data_value(changeset.data, field) do
|
2731
2758
|
nil
|
2732
2759
|
else
|
2733
2760
|
{:ok, %Ash.NotLoaded{}} ->
|
|
@@ -2768,6 +2795,24 @@ defmodule AshPhoenix.Form do
|
2768
2795
|
end
|
2769
2796
|
end
|
2770
2797
|
|
2798
|
+ defp get_data_value(%AshPhoenix.Form.WrappedValue{value: value}, field) do
|
2799
|
+ get_data_value(value, field)
|
2800
|
+ end
|
2801
|
+
|
2802
|
+ defp get_data_value(%Ash.Union{value: value}, field) when is_struct(value) do
|
2803
|
+ get_data_value(value, field)
|
2804
|
+ end
|
2805
|
+
|
2806
|
+ defp get_data_value(%Ash.Union{value: value}, :value) do
|
2807
|
+ {:ok, value}
|
2808
|
+ end
|
2809
|
+
|
2810
|
+ defp get_data_value(value, field) when is_map(value) do
|
2811
|
+ Map.fetch(value, field)
|
2812
|
+ end
|
2813
|
+
|
2814
|
+ defp get_data_value(_, _), do: :error
|
2815
|
+
|
2771
2816
|
defp get_nested(form, field) do
|
2772
2817
|
Map.fetch(form.forms, field)
|
2773
2818
|
end
|
changed
mix.exs
|
@@ -5,7 +5,7 @@ defmodule AshPhoenix.MixProject do
|
5
5
|
Utilities for integrating Ash and Phoenix
|
6
6
|
"""
|
7
7
|
|
8
|
- @version "2.1.6"
|
8
|
+ @version "2.1.7"
|
9
9
|
|
10
10
|
def project do
|
11
11
|
[
|