Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.
TypeScript analyticsanalytics-dashboardclickhouseelixirgoogle-analyticsmarketingopen-source-analyticsphoenixplausible-analyticspostgresqlprivacyprivacy-friendlyself-hostedsimple-analyticsstatisticstailwindcssweb-analyticswebsite-analyticswebsite-statswebsite-tracking
CRM: fix preserving index on pagination (#6130)
Adam Rutkowskid88b5a1a3e8c
diff --git a/extra/lib/plausible_web/live/customer_support/team/components/sites.ex b/extra/lib/plausible_web/live/customer_support/team/components/sites.exindex cc886669a7..bd12326f99 100644--- a/extra/lib/plausible_web/live/customer_support/team/components/sites.ex+++ b/extra/lib/plausible_web/live/customer_support/team/components/sites.ex@@ -17,10 +17,12 @@ defmodule PlausibleWeb.CustomerSupport.Team.Components.Sites doteam = Repo.preload(team, :owners)owner = List.first(team.owners)- index_state =- Index.build(owner, team: team, sort_by: :traffic, sort_direction: :desc)+ socket =+ assign_new(socket, :index_state, fn ->+ Index.build(owner, team: team, sort_by: :traffic, sort_direction: :desc)+ end)- page = Index.paginate(index_state, tab_params["page"], @page_size)+ page = Index.paginate(socket.assigns.index_state, tab_params["page"], @page_size)sites = fetch_sites(page.entries)@@ -35,7 +37,6 @@ defmodule PlausibleWeb.CustomerSupport.Team.Components.Sites doteam: team,sites: sites,hourly_stats: hourly_stats,- index_state: index_state,page_number: page.page_number,total_pages: page.total_pages,total_entries: page.total_entries,diff --git a/test/plausible_web/live/customer_support/teams_test.exs b/test/plausible_web/live/customer_support/teams_test.exsindex 88dff7fd67..fb273ca570 100644--- a/test/plausible_web/live/customer_support/teams_test.exs+++ b/test/plausible_web/live/customer_support/teams_test.exs@@ -212,6 +212,31 @@ defmodule PlausibleWeb.Live.CustomerSupport.TeamsTest doassert text(html) =~ "Page 1 of 2"end+ test "persists sort order across paginated entries", %{conn: conn, user: user} do+ team = team_of(user)++ for i <- 1..24 do+ new_site(owner: user, domain: "site-#{String.pad_leading("#{i}", 2, "0")}.example.com")+ end++ {:ok, lv, _html} = live(conn, open_team(team.id, tab: "sites"))++ # sort alphabetically ascending+ lv |> element(~s|th[phx-value-by="alnum"]|) |> render_click()++ html = render(lv)+ page1_domains = extract_domains(html)+ assert page1_domains == Enum.sort(page1_domains)++ lv |> render_patch(open_team(team.id, tab: "sites", page: 2))+ html = render(lv)+ page2_domains = extract_domains(html)++ # should still be alphabetically ascending on page 2+ assert page2_domains == Enum.sort(page2_domains)+ assert Enum.max(page1_domains) < Enum.min(page2_domains)+ end+test "shows no pagination when sites fit on one page", %{conn: conn, user: user} doteam = team_of(user)new_site(owner: user, domain: "only-site.example.com")