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
Fix sites list when user has no sites
Uku Tahta92bca2c86ff
diff --git a/lib/plausible/stats/clickhouse.ex b/lib/plausible/stats/clickhouse.exindex 37dfad3c9c..2142885d2d 100644--- a/lib/plausible/stats/clickhouse.ex+++ b/lib/plausible/stats/clickhouse.ex@@ -762,6 +762,7 @@ defmodule Plausible.Stats.Clickhouse doend)end+ def last_24h_visitors([]), do: %{}def last_24h_visitors(sites) dodomains = Enum.map(sites, & &1.domain)diff --git a/lib/plausible_web/templates/site/index.html.eex b/lib/plausible_web/templates/site/index.html.eexindex 034cdf8107..474f64abcf 100644--- a/lib/plausible_web/templates/site/index.html.eex+++ b/lib/plausible_web/templates/site/index.html.eex@@ -7,6 +7,10 @@</div><ul class="my-6 grid grid-cols-1 gap-6 sm:grid-cols-2 lg:grid-cols-3">+ <%= if Enum.empty?(@sites) do %>+ <p>You don't have any sites yet</p>+ <% end %>+<%= for site <- @sites do %><div class="relative group"><%= link(to: "/" <> URI.encode_www_form(site.domain)) do %>@@ -20,8 +24,7 @@<div class="pl-8 mt-2 flex items-center justify-between"><span class="text-gray-600 text-sm truncate"><span class="text-gray-800">- <b><%= PlausibleWeb.StatsView.large_number_format(Map.get(@visitors, site.domain, 0)) %></b>- visitors in last 24h+ <b><%= PlausibleWeb.StatsView.large_number_format(Map.get(@visitors, site.domain, 0)) %></b> visitors in last 24h</span></span></div>diff --git a/test/plausible_web/controllers/site_controller_test.exs b/test/plausible_web/controllers/site_controller_test.exsindex c944ff65f2..003eca460d 100644--- a/test/plausible_web/controllers/site_controller_test.exs+++ b/test/plausible_web/controllers/site_controller_test.exs@@ -12,6 +12,23 @@ defmodule PlausibleWeb.SiteControllerTest doendend+ describe "GET /sites" do+ setup [:create_user, :log_in]++ test "shows empty screen if no sites", %{conn: conn} do+ conn = get(conn, "/sites")+ assert html_response(conn, 200) =~ "You don't have any sites yet"+ end++ test "lists all of your sites with last 24h visitors", %{conn: conn, user: user} do+ insert(:site, members: [user], domain: "test-site.com")+ conn = get(conn, "/sites")++ assert html_response(conn, 200) =~ "test-site.com"+ assert html_response(conn, 200) =~ "<b>3</b> visitors in last 24h"+ end+ end+describe "POST /sites" dosetup [:create_user, :log_in]