Skip to content

Commit bf477e5

Browse files
authored
Improve monthly usage breakdown component (#6134)
* Improve monthly usage breakdown component - Remove progress bar when pageview limit is unlimited. - Change default state to be collapsed when more than 1 site is present - Remove "/ Unlimited" from usage breakdown when pageview limit is unlimited. * Fix test failures
1 parent 4c8446b commit bf477e5

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

lib/plausible_web/components/billing/billing.ex

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ defmodule PlausibleWeb.Components.Billing do
6262
usage={@usage.last_30_days}
6363
limit={@limit}
6464
period={:last_30_days}
65-
expanded={true}
65+
expanded={Enum.count(@usage.last_30_days.per_site) <= 1}
6666
total_pageview_usage_domain={@total_pageview_usage_domain}
6767
/>
6868
"""
@@ -82,7 +82,7 @@ defmodule PlausibleWeb.Components.Billing do
8282
usage={@usage.current_cycle}
8383
limit={@limit}
8484
period={:current_cycle}
85-
expanded={not @show_all and Enum.empty?(@usage.current_cycle.per_site)}
85+
expanded={not @show_all and Enum.count(@usage.current_cycle.per_site) <= 1}
8686
total_pageview_usage_domain={@total_pageview_usage_domain}
8787
/>
8888
<%= if @show_all do %>
@@ -129,7 +129,12 @@ defmodule PlausibleWeb.Components.Billing do
129129
{PlausibleWeb.TextHelpers.format_date_range(@usage.date_range)}
130130
<span :if={@period in [:current_cycle, :last_30_days]}>{cycle_label(@period)}</span>
131131
</p>
132-
<.usage_progress_bar id={"total_pageviews_#{@period}"} usage={@usage.total} limit={@limit} />
132+
<.usage_progress_bar
133+
:if={@limit != :unlimited}
134+
id={"total_pageviews_#{@period}"}
135+
usage={@usage.total}
136+
limit={@limit}
137+
/>
133138
</div>
134139
<button
135140
class="flex justify-between items-center flex-wrap w-full text-left"
@@ -156,7 +161,6 @@ defmodule PlausibleWeb.Components.Billing do
156161
<span class="ml-5 text-sm font-medium text-gray-900 dark:text-gray-100">
157162
{PlausibleWeb.TextHelpers.number_format(@usage.total)}
158163
{if is_number(@limit), do: "/ #{PlausibleWeb.TextHelpers.number_format(@limit)}"}
159-
{if @limit == :unlimited, do: "/ Unlimited"}
160164
</span>
161165
</button>
162166
<div x-show="open" class="flex flex-col gap-3 text-sm text-gray-900 dark:text-gray-100">

test/plausible_web/controllers/settings_controller_test.exs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -396,16 +396,18 @@ defmodule PlausibleWeb.SettingsControllerTest do
396396

397397
assert_usage = fn doc ->
398398
refute element_exists?(doc, "#total_pageviews_current_cycle")
399-
assert element_exists?(doc, "#total_pageviews_last_30_days")
400399
assert text_of_element(doc, "#pageviews_last_30_days") =~ "Pageviews 1"
401400
assert text_of_element(doc, "#custom_events_last_30_days") =~ "Custom events 2"
402401
end
403402

404403
# for a trial user
405-
conn
406-
|> get(Routes.settings_path(conn, :subscription))
407-
|> html_response(200)
408-
|> assert_usage.()
404+
trial_html =
405+
conn
406+
|> get(Routes.settings_path(conn, :subscription))
407+
|> html_response(200)
408+
409+
assert_usage.(trial_html)
410+
refute element_exists?(trial_html, "#total_pageviews_last_30_days")
409411

410412
subscribe_to_plan(user, @v4_plan_id,
411413
status: :deleted,

0 commit comments

Comments
 (0)