Skip to content

Commit 80499ee

Browse files
committed
Refactoring, fixes
1 parent e056334 commit 80499ee

1 file changed

Lines changed: 15 additions & 6 deletions

File tree

lib/phoenix/live_dashboard/components/table_component.ex

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,26 @@ defmodule Phoenix.LiveDashboard.TableComponent do
8383
row_fetcher: row_fetcher
8484
} = assigns
8585

86-
{rows, total, socket} = fetch_rows(row_fetcher, table_params, page.node, socket)
87-
assigns = Map.merge(assigns, %{rows: rows, total: total})
86+
{rows, total, active_filter, socket} =
87+
fetch_rows(row_fetcher, table_params, page.node, socket)
88+
89+
assigns =
90+
Map.merge(assigns, %{
91+
rows: rows,
92+
total: total,
93+
table_params: Map.put(table_params, :filter, active_filter)
94+
})
95+
8896
{:ok, assign(socket, assigns)}
8997
end
9098

9199
defp fetch_rows(row_fetcher, table_params, page_node, socket)
92100
when is_function(row_fetcher, 2) do
93101
{rows, total} = row_fetcher.(table_params, page_node)
94-
{rows, total, assign(socket, :filter_list, nil)}
102+
103+
{rows, total, nil,
104+
socket
105+
|> assign(:filter_list, nil)}
95106
end
96107

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

106117
## Update `filter` in table_params
107-
table_params = Map.put(table_params, :filter, active_filter)
108118

109-
{rows, total,
119+
{rows, total, active_filter,
110120
socket
111121
|> assign(:row_fetcher_state, state)
112-
|> assign(:table_params, table_params)
113122
|> assign(:filter_list, available_filters)}
114123
end
115124

0 commit comments

Comments
 (0)