Skip to content

Commit db58c2d

Browse files
committed
Remove the /team/select page
- Topbar dropdown now lists all teams (scrolls after ~5 to be sure, though no users have more than 5 teams yet) - Empty-state "Go to team sites" now has a dropdown button that routes directly instead of via a separate page - Deleted the route, controller, template, and related tests
1 parent d7bf8e7 commit db58c2d

12 files changed

Lines changed: 52 additions & 160 deletions

File tree

lib/plausible_web/controllers/auth_controller.ex

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ defmodule PlausibleWeb.AuthController do
3838
:verify_2fa_setup,
3939
:disable_2fa,
4040
:generate_2fa_recovery_codes,
41-
:select_team,
4241
:switch_team
4342
]
4443
)
@@ -61,51 +60,6 @@ defmodule PlausibleWeb.AuthController do
6160
TwoFactor.Session.clear_2fa_user(conn)
6261
end
6362

64-
def select_team(conn, _params) do
65-
current_user = conn.assigns.current_user
66-
current_team = conn.assigns[:current_team]
67-
68-
owner_name_fn = fn owner ->
69-
if owner.id == current_user.id do
70-
"You"
71-
else
72-
owner.name
73-
end
74-
end
75-
76-
teams =
77-
current_user
78-
|> Teams.Users.teams()
79-
|> Enum.filter(& &1.setup_complete)
80-
|> Enum.map(fn team ->
81-
current_team? = current_team && team.id == current_team.id
82-
83-
owners =
84-
Enum.map_join(team.owners, ", ", &owner_name_fn.(&1))
85-
86-
many_owners? = length(team.owners) > 1
87-
88-
%{
89-
identifier: team.identifier,
90-
name: team.name,
91-
current?: current_team?,
92-
many_owners?: many_owners?,
93-
owners: owners
94-
}
95-
end)
96-
97-
case teams do
98-
[] ->
99-
redirect(conn, to: Routes.site_path(conn, :index))
100-
101-
[%{identifier: sole_team_identifier}] ->
102-
redirect(conn, to: Routes.site_path(conn, :index, __team: sole_team_identifier))
103-
104-
[_ | _] ->
105-
render(conn, "select_team.html", teams_selection: teams)
106-
end
107-
end
108-
10963
def activate_form(conn, params) do
11064
user = conn.assigns.current_user
11165
flow = params["flow"] || PlausibleWeb.Flows.register()

lib/plausible_web/live/auth_context.ex

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,9 @@ defmodule PlausibleWeb.Live.AuthContext do
8787

8888
%{current_user: user} ->
8989
user.team_memberships
90+
|> Enum.filter(& &1.team.setup_complete)
9091
|> Enum.sort_by(fn tm -> [tm.role != :owner, tm.team_id] end)
9192
|> Enum.map(&Map.fetch!(&1, :team))
92-
|> Enum.take(3)
93-
end)
94-
|> assign_new(:teams_count, fn
95-
%{current_user: nil} -> 0
96-
%{current_user: user} -> length(user.team_memberships)
97-
end)
98-
|> assign_new(:more_teams?, fn context ->
99-
context.teams_count > 3
10093
end)
10194

10295
{:cont, socket}

lib/plausible_web/live/sites.ex

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,13 +205,36 @@ defmodule PlausibleWeb.Live.Sites do
205205
<Heroicons.plus class="size-4" /> Add website
206206
</.button_link>
207207
<.button_link
208-
:if={not Teams.setup?(@current_team) and @has_sites?}
209-
href={Routes.auth_path(@socket, :select_team)}
208+
:if={not Teams.setup?(@current_team) and @has_sites? and length(@teams) == 1}
209+
href={Routes.site_path(@socket, :index, __team: hd(@teams).identifier)}
210210
theme="secondary"
211211
mt?={false}
212212
>
213213
Go to team sites
214214
</.button_link>
215+
216+
<PrimaDropdown.dropdown
217+
:if={not Teams.setup?(@current_team) and @has_sites? and length(@teams) > 1}
218+
id="go-to-team-dropdown"
219+
>
220+
<PrimaDropdown.dropdown_trigger id="go-to-team-dropdown-trigger" theme="secondary">
221+
Go to team sites
222+
<Heroicons.chevron_down mini class="size-4 mt-0.5" />
223+
</PrimaDropdown.dropdown_trigger>
224+
225+
<PrimaDropdown.dropdown_menu id="go-to-team-dropdown-menu">
226+
<div class="max-h-[200px] overflow-y-auto">
227+
<PrimaDropdown.dropdown_item
228+
:for={team <- @teams}
229+
as={&link/1}
230+
id={"go-to-team-dropdown-menuitem-#{team.identifier}"}
231+
href={Routes.site_path(@socket, :index, __team: team.identifier)}
232+
>
233+
{Teams.name(team)}
234+
</PrimaDropdown.dropdown_item>
235+
</div>
236+
</PrimaDropdown.dropdown_menu>
237+
</PrimaDropdown.dropdown>
215238
</div>
216239
</div>
217240

lib/plausible_web/plugs/auth_plug.ex

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,11 @@ defmodule PlausibleWeb.AuthPlug do
5454
|> Enum.find(%{}, &(&1.role == :owner and &1.team.setup_complete == false))
5555
|> Map.get(:team)
5656

57-
teams_count = length(user.team_memberships)
58-
5957
teams =
6058
user.team_memberships
6159
|> Enum.filter(& &1.team.setup_complete)
6260
|> Enum.sort_by(fn tm -> [tm.role != :owner, tm.team_id] end)
6361
|> Enum.map(&Map.fetch!(&1, :team))
64-
|> Enum.take(3)
6562

6663
Plausible.OpenTelemetry.add_user_attributes(user)
6764

@@ -80,9 +77,7 @@ defmodule PlausibleWeb.AuthPlug do
8077
|> assign(:my_team, my_team)
8178
|> assign(:current_team, current_team || my_team)
8279
|> assign(:current_team_role, current_team_role || (my_team && :owner))
83-
|> assign(:teams_count, teams_count)
8480
|> assign(:teams, teams)
85-
|> assign(:more_teams?, teams_count > 3)
8681

8782
{:error, :session_expired, user_session} ->
8883
assign(conn, :expired_session, user_session)

lib/plausible_web/plugs/require_account.ex

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ defmodule PlausibleWeb.RequireAccountPlug do
1212
@force_2fa_exceptions [
1313
["2fa", "setup", "force-initiate"],
1414
["2fa", "setup", "initiate"],
15-
["2fa", "setup", "verify"],
16-
["team", "select"]
15+
["2fa", "setup", "verify"]
1716
]
1817

1918
def init(options) do

lib/plausible_web/router.ex

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,6 @@ defmodule PlausibleWeb.Router do
540540
get "/sso/notice", SSOController, :provision_notice
541541
get "/sso/issue", SSOController, :provision_issue
542542
get "/logout", AuthController, :logout
543-
get "/team/select", AuthController, :select_team
544543
end
545544

546545
scope "/", PlausibleWeb do
@@ -557,7 +556,6 @@ defmodule PlausibleWeb.Router do
557556

558557
on_ce do
559558
get "/logout", AuthController, :logout
560-
get "/team/select", AuthController, :select_team
561559
end
562560

563561
delete "/me", AuthController, :delete_me

lib/plausible_web/templates/auth/select_team.html.heex

Lines changed: 0 additions & 29 deletions
This file was deleted.

lib/plausible_web/templates/layout/_header.html.heex

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@
8888
teams={@teams}
8989
my_team={@my_team}
9090
current_team={@current_team}
91-
more_teams?={@more_teams?}
9291
/>
9392
<.dropdown_divider />
9493
<.dropdown_item href={Routes.settings_path(@conn, :index)}>

lib/plausible_web/views/layout_view.ex

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ defmodule PlausibleWeb.LayoutView do
166166
attr :teams, :list, required: true
167167
attr :my_team, :any, default: nil
168168
attr :current_team, :any, default: nil
169-
attr :more_teams?, :boolean, required: true
170169

171170
def team_switcher(assigns) do
172171
teams = assigns[:teams]
@@ -202,26 +201,25 @@ defmodule PlausibleWeb.LayoutView do
202201
<.dropdown_item>
203202
<div class="text-xs text-gray-500 dark:text-gray-400">Teams</div>
204203
</.dropdown_item>
205-
<.dropdown_item
206-
:for={team <- @teams}
207-
href={Routes.site_path(@conn, :index, __team: team.identifier)}
208-
>
209-
<p
210-
class={[
211-
if(team.id == @selected_id,
212-
do: "border-r-4 border-indigo-400 font-bold",
213-
else: "font-medium"
214-
),
215-
"truncate text-gray-900 dark:text-gray-100 pr-4"
216-
]}
217-
role="none"
204+
<div class="max-h-[200px] overflow-y-auto">
205+
<.dropdown_item
206+
:for={team <- @teams}
207+
href={Routes.site_path(@conn, :index, __team: team.identifier)}
218208
>
219-
{Teams.name(team)}
220-
</p>
221-
</.dropdown_item>
222-
<.dropdown_item :if={@more_teams?} href={Routes.auth_path(@conn, :select_team)}>
223-
Switch to Another Team
224-
</.dropdown_item>
209+
<p
210+
class={[
211+
if(team.id == @selected_id,
212+
do: "border-r-4 border-indigo-400 font-bold",
213+
else: "font-medium"
214+
),
215+
"truncate text-gray-900 dark:text-gray-100 pr-4"
216+
]}
217+
role="none"
218+
>
219+
{Teams.name(team)}
220+
</p>
221+
</.dropdown_item>
222+
</div>
225223
"""
226224
else
227225
~H""

test/plausible_web/controllers/auth_controller_test.exs

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2095,48 +2095,6 @@ defmodule PlausibleWeb.AuthControllerTest do
20952095
end
20962096
end
20972097

2098-
describe "GET /team/select" do
2099-
setup [:create_user, :log_in]
2100-
2101-
test "redirects to /sites if no teams available", %{conn: conn} do
2102-
conn = get(conn, Routes.auth_path(conn, :select_team))
2103-
assert redirected_to(conn, 302) == Routes.site_path(conn, :index)
2104-
end
2105-
2106-
test "redirects to /sites?__team if one team set up available", %{conn: conn, user: user} do
2107-
new_site(owner: user)
2108-
team = team_of(user)
2109-
assert Plausible.Teams.complete_setup(team)
2110-
conn = get(conn, Routes.auth_path(conn, :select_team))
2111-
assert redirected_to(conn, 302) == Routes.site_path(conn, :index, __team: team.identifier)
2112-
end
2113-
2114-
test "displays team switcher if >1 teams available", %{conn: conn, user: user} do
2115-
t1 = new_site(owner: user).team
2116-
t2 = new_site().team
2117-
2118-
add_member(t2, user: user, role: :viewer)
2119-
2120-
Plausible.Teams.complete_setup(t1)
2121-
Plausible.Teams.complete_setup(t2)
2122-
2123-
conn = get(conn, Routes.auth_path(conn, :select_team))
2124-
assert html = html_response(conn, 200)
2125-
2126-
assert text(html) =~ "Switch your current team"
2127-
2128-
assert element_exists?(
2129-
html,
2130-
~s|a[href="#{Routes.site_path(conn, :index, __team: t1.identifier)}"]|
2131-
)
2132-
2133-
assert element_exists?(
2134-
html,
2135-
~s|a[href="#{Routes.site_path(conn, :index, __team: t2.identifier)}"]|
2136-
)
2137-
end
2138-
end
2139-
21402098
defp login_with_cookie(conn, email, password) do
21412099
conn
21422100
|> post(Routes.auth_path(conn, :login), %{

0 commit comments

Comments
 (0)