Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions extra/lib/plausible_web/live/customer_support/live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule PlausibleWeb.CustomerSupport.Live do

Provides:
- Standard mount/3 and handle_info/2 implementations
- Tab navigation components and routing utilities
- Tab navigation components and routing utilities
- Common aliases and imports for Customer Support LiveViews
- Convenience API for flashes and redirects
"""
Expand Down Expand Up @@ -84,7 +84,7 @@ defmodule PlausibleWeb.CustomerSupport.Live do
patch={"?tab=#{@to}"}
class={[
@link_class,
"group relative min-w-0 flex-1 overflow-hidden bg-white dark:bg-gray-800 py-4 px-6 text-center text-sm font-medium hover:bg-gray-50 dark:hover:bg-gray-750 focus:z-10 first:rounded-l-lg last:rounded-r-lg"
"group relative min-w-0 flex-1 overflow-hidden bg-white dark:bg-gray-800 py-4 px-6 text-center text-sm font-medium hover:bg-gray-50 dark:hover:bg-gray-700 focus:z-10 first:rounded-l-lg last:rounded-r-lg"
]}
>
{render_slot(@inner_block)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ defmodule PlausibleWeb.CustomerSupport.Team.Components.ConsolidatedViews do
<.th>Domain</.th>
<.th>Timezone</.th>
<.th invisible>Dashboard</.th>
<.th invisible>Settings</.th>
<.th invisible>Delete</.th>
</:thead>

Expand All @@ -43,6 +44,21 @@ defmodule PlausibleWeb.CustomerSupport.Team.Components.ConsolidatedViews do
Dashboard
</.styled_link>
</.td>
<.td>
<.styled_link
new_tab={true}
href={
Routes.site_path(
PlausibleWeb.Endpoint,
:settings_general,
consolidated_view.domain,
[]
)
}
>
Settings
</.styled_link>
</.td>
<.td>
<.delete_button
phx-click="delete-consolidated-view"
Expand All @@ -63,8 +79,8 @@ defmodule PlausibleWeb.CustomerSupport.Team.Components.ConsolidatedViews do
success("Consolidated view created")
{:noreply, assign(socket, consolidated_views: [consolidated_view])}

{:error, _} ->
failure("Could not create consolidated view")
{:error, reason} ->
failure("Could not create consolidated view. Reason: #{inspect(reason)}")
{:noreply, socket}
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/plausible_web/components/generic.ex
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ defmodule PlausibleWeb.Components.Generic do

def tile(assigns) do
~H"""
<div class="shadow-sm bg-white dark:bg-gray-800 rounded-md mb-6">
<div data-test-id="settings-tile" class="shadow-sm bg-white dark:bg-gray-800 rounded-md mb-6">
<header class="relative py-4 px-6">
<.title>
{render_slot(@title)}
Expand Down
5 changes: 4 additions & 1 deletion lib/plausible_web/live/goal_settings.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ defmodule PlausibleWeb.Live.GoalSettings do
socket
|> assign_new(:site, fn %{current_user: current_user} ->
current_user
|> Plausible.Sites.get_for_user!(domain, roles: [:owner, :admin, :editor, :super_admin])
|> Plausible.Sites.get_for_user!(domain,
roles: [:owner, :admin, :editor, :super_admin],
include_consolidated?: true
)
end)
|> assign_new(:site_role, fn %{site: site, current_user: current_user} ->
if Plausible.Auth.is_super_admin?(current_user) do
Expand Down
4 changes: 2 additions & 2 deletions lib/plausible_web/templates/site/settings_general.html.heex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<.settings_tiles>
<.tile docs="change-domain-name">
<.tile :if={Plausible.Sites.regular?(@site)} docs="change-domain-name">
<:title>
Site domain
</:title>
Expand Down Expand Up @@ -30,7 +30,7 @@
</.button>
</.form>
</.tile>
<.tile docs="plausible-script">
<.tile :if={Plausible.Sites.regular?(@site)} docs="plausible-script">
<:title>Site installation</:title>
<:subtitle>
Control what data is collected and verify your installation.
Expand Down
2 changes: 1 addition & 1 deletion lib/plausible_web/templates/site/settings_goals.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<p>
Define actions that you want your users to take, like visiting a certain page, submitting a form, etc.
</p>
<p :if={ee?()}>
<p :if={ee?() and Plausible.Sites.regular?(@site)} data-test-id="setup-funnels-cta">
You can also
<.styled_link href={Routes.site_path(@conn, :settings_funnels, @site.domain)}>
compose goals into funnels.
Expand Down
42 changes: 27 additions & 15 deletions lib/plausible_web/views/layout_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -52,29 +52,41 @@ defmodule PlausibleWeb.LayoutView do
end

def site_settings_sidebar(conn) do
regular_site? = Plausible.Sites.regular?(conn.assigns.site)

[
%{key: "General", value: "general", icon: :rocket_launch},
%{key: "People", value: "people", icon: :users},
%{key: "Visibility", value: "visibility", icon: :eye},
if regular_site? do
%{key: "People", value: "people", icon: :users}
end,
if regular_site? do
%{key: "Visibility", value: "visibility", icon: :eye}
end,
%{key: "Goals", value: "goals", icon: :check_circle},
on_ee do
%{key: "Funnels", value: "funnels", icon: :funnel}
if regular_site? do
%{key: "Funnels", value: "funnels", icon: :funnel}
end
end,
%{key: "Custom properties", value: "properties", icon: :document_text},
%{key: "Integrations", value: "integrations", icon: :puzzle_piece},
%{key: "Imports & exports", value: "imports-exports", icon: :arrow_down_tray},
%{
key: "Shields",
icon: :shield_exclamation,
value: [
%{key: "IP addresses", value: "shields/ip_addresses"},
%{key: "Countries", value: "shields/countries"},
%{key: "Pages", value: "shields/pages"},
%{key: "Hostnames", value: "shields/hostnames"}
]
},
if regular_site? do
%{key: "Imports & exports", value: "imports-exports", icon: :arrow_down_tray}
end,
if regular_site? do
%{
key: "Shields",
icon: :shield_exclamation,
value: [
%{key: "IP addresses", value: "shields/ip_addresses"},
%{key: "Countries", value: "shields/countries"},
%{key: "Pages", value: "shields/pages"},
%{key: "Hostnames", value: "shields/hostnames"}
]
}
end,
%{key: "Email reports", value: "email-reports", icon: :envelope},
if conn.assigns[:site_role] in [:owner, :admin] do
if regular_site? and conn.assigns[:site_role] in [:owner, :admin] do
%{key: "Danger zone", value: "danger-zone", icon: :exclamation_triangle}
end
]
Expand Down
47 changes: 47 additions & 0 deletions test/plausible_web/controllers/site_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,16 @@ defmodule PlausibleWeb.SiteControllerTest do
assert resp =~ "Site installation"
end

@tag :ee_only
test "renders only timezone section for a consolidated site", %{conn: conn, user: user} do
consolidated_view = user |> team_of() |> new_consolidated_view()
conn = get(conn, "/#{consolidated_view.domain}/settings/general")
resp = html_response(conn, 200)

assert [tile_element] = find(resp, ~s|div[data-test-id="settings-tile"]|)
assert text(tile_element) =~ "Site timezone"
end

@tag :ee_only
test "all site settings sidebar items are working links", %{
conn: conn,
Expand Down Expand Up @@ -575,6 +585,30 @@ defmodule PlausibleWeb.SiteControllerTest do
]
end

@tag :ee_only
test "consolidated view settings sidebar items", %{
conn: conn,
user: user
} do
team = user |> team_of()
site = new_consolidated_view(team)
conn = get(conn, "/#{site.domain}/settings/general")
resp = html_response(conn, 200)

items =
resp
|> find("[data-testid=site_settings_sidebar] a")
|> Enum.map(fn a -> {text(a), text_of_attr(a, "href")} end)

assert items == [
{"General", "/#{site.domain}/settings/general"},
{"Goals", "/#{site.domain}/settings/goals"},
{"Custom properties", "/#{site.domain}/settings/properties"},
{"Integrations", "/#{site.domain}/settings/integrations"},
{"Email reports", "/#{site.domain}/settings/email-reports"}
]
end

test "header and footer are shown", %{conn: conn, site: site, user: user} do
conn = get(conn, "/#{site.domain}/settings/general")
resp = html_response(conn, 200)
Expand Down Expand Up @@ -1861,6 +1895,19 @@ defmodule PlausibleWeb.SiteControllerTest do
end
end

describe "/:domain/settings/general" do
setup [:create_user, :log_in]

test "shows domain change in the settings form", %{conn: conn, site: site} do
conn = get(conn, Routes.site_path(conn, :settings_general, site.domain))
resp = html_response(conn, 200)

assert resp =~ "Site domain"
assert resp =~ "Change domain"
assert resp =~ Routes.site_path(conn, :change_domain, site.domain)
end
end

describe "domain change" do
setup [:create_user, :log_in, :create_site]

Expand Down
1 change: 1 addition & 0 deletions test/plausible_web/live/customer_support/teams_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ defmodule PlausibleWeb.Live.CustomerSupport.TeamsTest do

assert table_text =~ team.identifier
assert table_text =~ "Dashboard"
assert table_text =~ "Settings"

assert element_exists?(html, @delete_consolidated_view_button)
end
Expand Down
99 changes: 97 additions & 2 deletions test/plausible_web/live/goal_settings_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ defmodule PlausibleWeb.Live.GoalSettingsTest do
import Phoenix.LiveViewTest
import Plausible.Test.Support.HTML

@funnels_cta ~s|p[data-test-id="setup-funnels-cta"]|

describe "GET /:domain/settings/goals" do
setup [:create_user, :log_in, :create_site]

Expand All @@ -14,8 +16,11 @@ defmodule PlausibleWeb.Live.GoalSettingsTest do

resp = html_response(conn, 200)
assert resp =~ "Define actions that you want your users to take"
assert resp =~ "compose goals into funnels"
assert resp =~ "/#{URI.encode_www_form(site.domain)}/settings/funnels"
assert text_of_element(resp, @funnels_cta) =~ "compose goals into funnels"

assert text_of_element(resp, @funnels_cta) =~
"/#{URI.encode_www_form(site.domain)}/settings/funnels"

assert element_exists?(resp, ~s|a[href="https://plausible.io/docs/goal-conversions"]|)

assert resp =~ to_string(g1)
Expand Down Expand Up @@ -98,6 +103,51 @@ defmodule PlausibleWeb.Live.GoalSettingsTest do
end
end

on_ee do
describe "GET /:domain/settings/goals - consolidated views" do
setup [:create_user, :create_team, :log_in]

setup %{team: team} = context do
new_site(team: team)
new_site(team: team)

{:ok, Map.put(context, :consolidated_view, new_consolidated_view(team))}
end

test "no goals exist", %{conn: conn, consolidated_view: consolidated_view} do
conn = get(conn, "/#{consolidated_view.domain}/settings/goals")

assert resp = html_response(conn, 200)
assert resp =~ "Define actions that you want your users to take"
assert resp =~ "No goals configured for this site"
assert element_exists?(resp, ~s|a[href="https://plausible.io/docs/goal-conversions"]|)
end

test "lists goals", %{conn: conn, consolidated_view: consolidated_view} do
{:ok, g1} = Plausible.Goals.create(consolidated_view, %{"page_path" => "/go/to/blog/**"})
{:ok, g2} = Plausible.Goals.create(consolidated_view, %{"event_name" => "Register"})

conn = get(conn, "/#{consolidated_view.domain}/settings/goals")

assert resp = html_response(conn, 200)
assert resp =~ "Define actions that you want your users to take"
assert element_exists?(resp, ~s|a[href="https://plausible.io/docs/goal-conversions"]|)

assert resp =~ to_string(g1)
assert resp =~ "Pageview"
assert resp =~ to_string(g2)
assert resp =~ "Custom Event"
end

test "does not render funnels cta", %{conn: conn, consolidated_view: consolidated_view} do
conn = get(conn, "/#{consolidated_view.domain}/settings/goals")

assert resp = html_response(conn, 200)
refute element_exists?(resp, @funnels_cta)
end
end
end

describe "GoalSettings live view" do
setup [:create_user, :log_in, :create_site]

Expand Down Expand Up @@ -213,6 +263,51 @@ defmodule PlausibleWeb.Live.GoalSettingsTest do
end
end

describe "GoalSettings live view - consolidated views" do
setup [:create_user, :create_team, :log_in]

setup %{team: team} = context do
new_site(team: team)
new_site(team: team)

{:ok, Map.put(context, :consolidated_view, new_consolidated_view(team))}
end

test "allows goal deletion", %{conn: conn, consolidated_view: consolidated_view} do
{:ok, g1} = Plausible.Goals.create(consolidated_view, %{"page_path" => "/go/to/blog/**"})
{:ok, g2} = Plausible.Goals.create(consolidated_view, %{"event_name" => "Register"})

{lv, html} = get_liveview(conn, consolidated_view, with_html?: true)

assert html =~ to_string(g1)
assert html =~ to_string(g2)

html = lv |> element(~s/button#delete-goal-#{g1.id}/) |> render_click()

refute html =~ to_string(g1)
assert html =~ to_string(g2)

html = get(conn, "/#{consolidated_view.domain}/settings/goals") |> html_response(200)

refute html =~ to_string(g1)
assert html =~ to_string(g2)
end

test "allows list filtering / search", %{conn: conn, consolidated_view: consolidated_view} do
{:ok, g1} = Plausible.Goals.create(consolidated_view, %{"page_path" => "/go/to/blog/**"})
{:ok, g2} = Plausible.Goals.create(consolidated_view, %{"event_name" => "Register"})
{lv, html} = get_liveview(conn, consolidated_view, with_html?: true)

assert html =~ to_string(g1)
assert html =~ to_string(g2)

html = type_into_search(lv, to_string(g2))

refute html =~ to_string(g1)
assert html =~ to_string(g2)
end
end

defp setup_goals(site) do
{:ok, g1} = Plausible.Goals.create(site, %{"page_path" => "/go/to/blog/**"})
{:ok, g2} = Plausible.Goals.create(site, %{"event_name" => "Register"})
Expand Down
Loading