Skip to content

Commit

Permalink
chore: form -> query
Browse files Browse the repository at this point in the history
  • Loading branch information
zachdaniel committed Mar 19, 2024
1 parent 7bafba8 commit 5a44b15
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions lib/ash_admin/components/resource/data_table.ex
Original file line number Diff line number Diff line change
Expand Up @@ -298,41 +298,44 @@ defmodule AshAdmin.Components.Resource.DataTable do
_ -> :create
end

form = AshPhoenix.Form.add_form(socket.assigns.form, path, type: type)
query = AshPhoenix.Form.add_form(socket.assigns.query, path, type: type)

{:noreply,
socket
|> assign(:form, form)}
|> assign(:query, query)}
end

def handle_event("remove_form", %{"path" => path}, socket) do
form = AshPhoenix.Form.remove_form(socket.assigns.form, path)
query = AshPhoenix.Form.remove_form(socket.assigns.query, path)

{:noreply,
socket
|> assign(:form, form)}
|> assign(:query, query)}
end

def handle_event("append_value", %{"path" => path, "field" => field}, socket) do
list =
AshPhoenix.Form.get_form(socket.assigns.form, path)
AshPhoenix.Form.get_form(socket.assigns.query, path)
|> AshPhoenix.Form.value(String.to_existing_atom(field))
|> Kernel.||([])
|> indexed_list()
|> append_to_and_map(nil)

params =
put_in_creating(
socket.assigns.form.params || %{},
Enum.map(AshPhoenix.Form.parse_path!(socket.assigns.form, path) ++ [field], &to_string/1),
socket.assigns.query.params || %{},
Enum.map(
AshPhoenix.Form.parse_path!(socket.assigns.query, path) ++ [field],
&to_string/1
),
list
)

form = AshPhoenix.Form.validate(socket.assigns.form, params)
query = AshPhoenix.Form.validate(socket.assigns.query, params)

{:noreply,
socket
|> assign(:form, form)}
|> assign(:query, query)}
end

defp indexed_list(map) when is_map(map) do
Expand Down

0 comments on commit 5a44b15

Please sign in to comment.