Skip to content

Commit

Permalink
Refactoring, fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bokner committed Apr 29, 2023
1 parent e056334 commit 80499ee
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions lib/phoenix/live_dashboard/components/table_component.ex
Expand Up @@ -83,15 +83,26 @@ defmodule Phoenix.LiveDashboard.TableComponent do
row_fetcher: row_fetcher
} = assigns

{rows, total, socket} = fetch_rows(row_fetcher, table_params, page.node, socket)
assigns = Map.merge(assigns, %{rows: rows, total: total})
{rows, total, active_filter, socket} =
fetch_rows(row_fetcher, table_params, page.node, socket)

assigns =
Map.merge(assigns, %{
rows: rows,
total: total,
table_params: Map.put(table_params, :filter, active_filter)
})

{:ok, assign(socket, assigns)}
end

defp fetch_rows(row_fetcher, table_params, page_node, socket)
when is_function(row_fetcher, 2) do
{rows, total} = row_fetcher.(table_params, page_node)
{rows, total, assign(socket, :filter_list, nil)}

{rows, total, nil,
socket
|> assign(:filter_list, nil)}
end

defp fetch_rows({row_fetcher, initial_state}, table_params, page_node, socket)
Expand All @@ -104,12 +115,10 @@ defmodule Phoenix.LiveDashboard.TableComponent do
end

## Update `filter` in table_params
table_params = Map.put(table_params, :filter, active_filter)

{rows, total,
{rows, total, active_filter,
socket
|> assign(:row_fetcher_state, state)
|> assign(:table_params, table_params)
|> assign(:filter_list, available_filters)}
end

Expand Down

0 comments on commit 80499ee

Please sign in to comment.