From 0d5d5e8dd29750c9b266cf67709c7708c641299b Mon Sep 17 00:00:00 2001 From: Adam Rutkowski Date: Thu, 5 Mar 2026 11:02:32 +0100 Subject: [PATCH 1/4] Fix preserving the sort order, compute index only once --- .../live/customer_support/team/components/sites.ex | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) 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.ex index cc886669a76f..bd12326f996b 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 do team = 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 do team: 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, From d00c2647c96be62e2b45fe65c560f5a1a3c440c1 Mon Sep 17 00:00:00 2001 From: Adam Rutkowski Date: Thu, 5 Mar 2026 11:03:43 +0100 Subject: [PATCH 2/4] Test --- .../live/customer_support/teams_test.exs | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/plausible_web/live/customer_support/teams_test.exs b/test/plausible_web/live/customer_support/teams_test.exs index 88dff7fd678d..fb273ca570d9 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 do assert 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} do team = team_of(user) new_site(owner: user, domain: "only-site.example.com") From 3a22aeab56cefed7114d15c2077c599f7fd8688b Mon Sep 17 00:00:00 2001 From: Adam Rutkowski Date: Thu, 5 Mar 2026 11:04:01 +0100 Subject: [PATCH 3/4] Revert "Fix preserving the sort order, compute index only once" This reverts commit 0d5d5e8dd29750c9b266cf67709c7708c641299b. --- .../live/customer_support/team/components/sites.ex | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) 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.ex index bd12326f996b..cc886669a76f 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,12 +17,10 @@ defmodule PlausibleWeb.CustomerSupport.Team.Components.Sites do team = Repo.preload(team, :owners) owner = List.first(team.owners) - socket = - assign_new(socket, :index_state, fn -> - Index.build(owner, team: team, sort_by: :traffic, sort_direction: :desc) - end) + index_state = + Index.build(owner, team: team, sort_by: :traffic, sort_direction: :desc) - page = Index.paginate(socket.assigns.index_state, tab_params["page"], @page_size) + page = Index.paginate(index_state, tab_params["page"], @page_size) sites = fetch_sites(page.entries) @@ -37,6 +35,7 @@ defmodule PlausibleWeb.CustomerSupport.Team.Components.Sites do team: 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, From 0f4fb6308dfe771dd5b04ee116def7d3f53f7f04 Mon Sep 17 00:00:00 2001 From: Adam Rutkowski Date: Thu, 5 Mar 2026 11:04:24 +0100 Subject: [PATCH 4/4] Reapply "Fix preserving the sort order, compute index only once" This reverts commit 3a22aeab56cefed7114d15c2077c599f7fd8688b. --- .../live/customer_support/team/components/sites.ex | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) 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.ex index cc886669a76f..bd12326f996b 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 do team = 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 do team: 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,