Skip to content

Commit aec5ebd

Browse files
committed
fix: include resource's table in polymorphic tables dropdown
1 parent 6c13953 commit aec5ebd

File tree

2 files changed

+10
-79
lines changed

2 files changed

+10
-79
lines changed

lib/ash_admin/components/resource/generic_action.ex

Lines changed: 0 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -255,86 +255,8 @@ defmodule AshAdmin.Components.Resource.GenericAction do
255255

256256
{:ok, assign(socket, initialized: true, form: form)}
257257
end
258-
259-
# else
260-
# socket = assign(socket, assigns)
261-
# params = socket.assigns[:params] || %{}
262-
# arguments = params["args"]
263-
264-
# query =
265-
# socket.assigns[:resource]
266-
# |> AshPhoenix.Form.for_read(socket.assigns.action.name,
267-
# as: "query",
268-
# )
269-
270-
# {query, run_now?} =
271-
# if arguments do
272-
# {Map.put(AshPhoenix.Form.validate(query, arguments), :submitted_once?, true), true}
273-
# else
274-
# {query, socket.assigns.action.arguments == []}
275-
# end
276-
277-
# socket = assign(socket, :query, query)
278-
279-
# socket =
280-
# if params["page"] && socket.assigns.action.pagination do
281-
# default_limit =
282-
# socket.assigns.action.pagination.default_limit ||
283-
# socket.assigns.action.pagination.max_page_size || 25
284-
285-
# count? = !!socket.assigns.action.pagination.countable
286-
287-
# page_params =
288-
# AshPhoenix.LiveView.page_from_params(params["page"], default_limit, count?)
289-
290-
# socket
291-
# |> assign(
292-
# :page_params,
293-
# page_params
294-
# )
295-
# |> assign(
296-
# :page_num,
297-
# page_num_from_page_params(page_params)
298-
# )
299-
# else
300-
# socket
301-
# |> assign(:page_params, nil)
302-
# |> assign(:page_num, 1)
303-
# end
304-
305-
# socket =
306-
# if run_now? do
307-
# if socket.assigns[:tables] not in [[], nil] && !socket.assigns[:table] do
308-
# assign(socket, :data, {:ok, []})
309-
# else
310-
# action_opts =
311-
# if page_params = socket.assigns[:page_params] do
312-
# [page: page_params]
313-
# else
314-
# []
315-
# end
316-
317-
# case AshPhoenix.Form.submit(socket.assigns.query, action_opts: action_opts, params: nil) do
318-
# {:ok, data} -> assign(socket, :data, {:ok, data})
319-
# {:error, query} -> assign(socket, data: {:error, all_errors(query)}, query: query)
320-
# end
321-
# end
322-
# else
323-
# assign(socket, :data, :loading)
324-
# end
325-
326-
# {:ok,
327-
# socket
328-
# |> assign(:initialized, true)}
329-
# end
330258
end
331259

332-
# defp load_fields(query) do
333-
# query
334-
# |> Ash.Query.select([])
335-
# |> Ash.Query.load(AshAdmin.Resource.table_columns(query.resource))
336-
# end
337-
338260
def handle_event("validate", params, socket) do
339261
params = params["form"] || %{}
340262
form = AshPhoenix.Form.validate(socket.assigns.form, params)

lib/ash_admin/resource/resource.ex

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,17 @@ defmodule AshAdmin.Resource do
275275
|> Enum.flat_map(&Ash.Resource.Info.relationships/1)
276276
|> Enum.filter(&(&1.destination == resource))
277277
|> Enum.map(& &1.context[:data_layer][:table])
278-
|> Enum.reject(&is_nil/1)
279278
|> Enum.uniq()
279+
|> then(
280+
&Enum.concat(
281+
[
282+
Spark.Dsl.Extension.get_opt(resource, [:postgres], :table),
283+
Spark.Dsl.Extension.get_opt(resource, [:sqlite], :table)
284+
],
285+
&1
286+
)
287+
)
288+
|> Enum.reject(&is_nil/1)
280289
end
281290

282291
defp actions_with_primary_first(resource, type) do

0 commit comments

Comments
 (0)