Skip to content

Commit

Permalink
Close #204 (#236)
Browse files Browse the repository at this point in the history
Skip pagination when beacon_page.table is not available
  • Loading branch information
leandrocp authored Sep 10, 2024
1 parent 35fb5c2 commit 2f93d13
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
### Breaking Changes
* Require minimum Gettext v0.26 to use the new backend module

### Fixes
- Close #204 - skip `PageBuilder.Table.handle_params/3` when the requested page has no pagination data

### Enhancements
- [Visual Editor] Improve DnD highlight states and simplify logic significantly ([#219](https://github.com/BeaconCMS/beacon_live_admin/pull/219))
- [Visual Editor] Better detect overlapping when dragging elements to reorder ([#216](https://github.com/BeaconCMS/beacon_live_admin/pull/216))
Expand Down
6 changes: 4 additions & 2 deletions lib/beacon/live_admin/page_builder/table.ex
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ defmodule Beacon.LiveAdmin.PageBuilder.Table do
updating params for a Table.
"""
@spec handle_params(Socket.t(), map(), (Page.t() -> integer())) :: Socket.t()
def handle_params(socket, params, count_fn) do
%{per_page: per_page, sort_by: sort_by} = socket.assigns.beacon_page.table
def handle_params(socket, params, count_fn)

def handle_params(%{assigns: %{beacon_page: %{table: %{per_page: per_page, sort_by: sort_by}}}} = socket, params, count_fn) do
current_page = params |> Map.get("page", "1") |> String.to_integer()
page_count = ceil(count_fn.(socket.assigns.beacon_page) / per_page)
sort_by = params |> Map.get("sort_by", sort_by) |> safe_to_atom()
Expand All @@ -141,6 +141,8 @@ defmodule Beacon.LiveAdmin.PageBuilder.Table do
)
end

def handle_params(socket, _params, _count_fn), do: socket

defp safe_to_atom(value) when is_atom(value), do: value
defp safe_to_atom(value) when is_binary(value), do: String.to_existing_atom(value)

Expand Down

0 comments on commit 2f93d13

Please sign in to comment.