defmodule SelectoComponents.Views.Detail.Component do @doc """ Display results of a detail view """ import SelectoComponents.Components.Common import SelectoComponents.Components.SqlDebug alias SelectoComponents.EnhancedTable.Sorting use Phoenix.LiveComponent def mount(socket) do # Initialize column configuration # Will be populated in update/2 columns = [] socket = socket |> assign(:columns_config, init_columns_config(columns)) {:ok, socket} end def update(assigns, socket) do # Extract columns from selecto if available columns = if Map.has_key?(assigns, :selecto) do Map.get(assigns.selecto.set, :columns, []) |> Enum.map(fn col -> %{ id: col["field"], name: col["alias"] || col["field"], width: 150, min_width: 50, max_width: 500 } end) else [] end socket = socket |> assign(assigns) |> assign(:columns_config, init_columns_config(columns)) {:ok, socket} end def render(assigns) do ### Todo Deal with page changes without executing again....... # Check for execution error first if Map.get(assigns, :execution_error) do # Display the actual error message ~H"""
<%= inspect(@execution_error.details, pretty: true) %>
| # | <%= for {alias, idx} <- Enum.with_index(@aliases) do %> <% column_field = Enum.at(@columns, idx)["field"] %>{Map.get(config, :title, config.key)} | <% end %> <% end %>|||
|---|---|---|---|---|
| {actual_idx + 1} | <%!-- Display regular columns --%><% def = Selecto.columns(@selecto)[col_conf["field"]] %> <%= case def do %> <% %{format: :component} = def -> %> {safe_render_component(def.component, %{ row: row_data_by_uuid[col_conf["uuid"]], config: col_conf })} <% %{format: :link} = def -> %> {safe_render_link(def.link_parts, row_data_by_uuid[col_conf["uuid"]])} <% _ -> %> {row_data_by_uuid[col_conf["uuid"]]} <% end %> | <%!-- Add subselect columns inline --%> <%= if Map.get(@view_meta, :subselect_configs, []) != [] do %> <%= for config <- Map.get(@view_meta, :subselect_configs, []) do %> <% data = Map.get(row_data_by_column, config.key, []) %> <% # Use actual_idx to ensure unique IDs %> <% unique_id = "page#{@view_meta.page}_idx#{actual_idx}_#{config.key}" %>
<% # Parse the data here to ensure it's fresh %>
<% parsed_data =
SelectoComponents.Components.NestedTable.parse_subselect_data(data, config) %>
<%= if length(parsed_data) > 0 do %>
No data
<% end %>
|
<% end %>
<% end %>