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
trial prospects: sort by traffic and show notes (#6710)
Marko Saric27cbc4419c50
diff --git a/extra/lib/plausible/customer_support/trial_prospects.ex b/extra/lib/plausible/customer_support/trial_prospects.exindex 998ed274a1..f689b83049 100644--- a/extra/lib/plausible/customer_support/trial_prospects.ex+++ b/extra/lib/plausible/customer_support/trial_prospects.ex@@ -44,7 +44,7 @@ defmodule Plausible.CustomerSupport.TrialProspects do@kind_rank %{starter: 0, growth: 1, business: 2}@page_size 100- @sortable_columns ~w(mrr trial_start)+ @sortable_columns ~w(mrr traffic trial_start)@max_expired_days 30@spec sortable_columns() :: [String.t()]@@ -84,6 +84,8 @@ defmodule Plausible.CustomerSupport.TrialProspects dobase|> preload_team()|> order_prospects(sort_by, sort_direction)+ # Unique final key keeps offset pagination stable across ties+ |> order_by([p], asc: p.team_id)|> limit(^@page_size)|> offset(^((page_number - 1) * @page_size))|> Repo.all()@@ -114,6 +116,10 @@ defmodule Plausible.CustomerSupport.TrialProspects doorder_by(q, [team: t], [{^direction, t.inserted_at}])end+ defp order_prospects(q, "traffic", direction) do+ order_by(q, [p], [{^direction, p.estimated_monthly}])+ end+# Over-the-top-tier (Custom/Enterprise) prospects rank firstdefp order_prospects(q, "mrr", direction) doorder_by(q, [p], [{^direction, p.over_top_tier}, {^direction, p.estimated_mrr}])diff --git a/extra/lib/plausible_web/live/customer_support/trial_prospects.ex b/extra/lib/plausible_web/live/customer_support/trial_prospects.exindex ced4cf8850..7360fe4581 100644--- a/extra/lib/plausible_web/live/customer_support/trial_prospects.ex+++ b/extra/lib/plausible_web/live/customer_support/trial_prospects.ex@@ -54,7 +54,12 @@ defmodule PlausibleWeb.Live.CustomerSupport.TrialProspects do/><.th>Feature tier</.th><.th>Forced by</.th>- <.th>Traffic estimate</.th>+ <.sort_th+ label="Traffic estimate"+ by="traffic"+ sort_by={@sort_by}+ sort_direction={@sort_direction}+ /><.sort_thlabel="Trial start"by="trial_start"@@ -62,6 +67,7 @@ defmodule PlausibleWeb.Live.CustomerSupport.TrialProspects dosort_direction={@sort_direction}/><.th>Trial expiry</.th>+ <.th>Notes</.th></:thead><:tbody :let={p}><.td>@@ -87,6 +93,7 @@ defmodule PlausibleWeb.Live.CustomerSupport.TrialProspects do<.td>{StatsView.large_number_format(p.estimated_monthly)}</.td><.td>{format_date(trial_start(p.team))}</.td><.td>{format_date(p.team.trial_expiry_date)}</.td>+ <.td truncate max_width="max-w-40" title={p.team.notes}>{p.team.notes}</.td></:tbody></.table>diff --git a/test/plausible_web/live/customer_support/trial_prospects_test.exs b/test/plausible_web/live/customer_support/trial_prospects_test.exsindex 1b5c8609bf..cd906cfd86 100644--- a/test/plausible_web/live/customer_support/trial_prospects_test.exs+++ b/test/plausible_web/live/customer_support/trial_prospects_test.exs@@ -127,6 +127,41 @@ defmodule PlausibleWeb.Live.CustomerSupport.TrialProspectsTest doassert text_of_element(html, "tbody tr:first-child") =~ "Older Co"end+ test "can toggle traffic estimate sorting in both directions", %{conn: conn} do+ small = insert(:team, name: "Small Traffic Co")+ big = insert(:team, name: "Big Traffic Co")++ prospect(small, estimated_monthly: 9_000, estimated_mrr: 339)+ prospect(big, estimated_monthly: 100_000, estimated_mrr: 19)++ {:ok, lv, html} = live(conn, open_prospects())+ assert text_of_element(html, "tbody tr:first-child") =~ "Small Traffic Co"++ html = lv |> element("a", "Traffic estimate") |> render_click()+ assert_patch(lv, open_prospects(sort_by: "traffic", sort_direction: "desc"))+ assert text_of_element(html, "tbody tr:first-child") =~ "Big Traffic Co"++ html = lv |> element("a", "Traffic estimate") |> render_click()+ assert_patch(lv, open_prospects(sort_by: "traffic", sort_direction: "asc"))+ assert text_of_element(html, "tbody tr:first-child") =~ "Small Traffic Co"+ end++ test "shows existing team notes alongside each prospect", %{conn: conn} do+ noted = insert(:team, name: "Noted Co", notes: "Contacted owner\nFollow up next week")+ blank = insert(:team, name: "Blank Co", notes: nil)++ prospect(noted, estimated_mrr: 99)+ prospect(blank, estimated_mrr: 19)++ {:ok, _lv, html} = live(conn, open_prospects())++ assert text_of_element(html, "thead") =~ "Notes"++ assert text_of_element(html, "tbody tr:first-child td:last-child") =~ "Contacted owner"++ assert text_of_element(html, "tbody tr:last-child td:last-child") == ""+ end+test "excludes rows left behind for teams no longer on a trial", %{conn: conn} dolive_team = insert(:team, name: "Live Co")prospect(live_team, estimated_mrr: 19)