Skip to content

Commit 539d094

Browse files
committed
Scope sidebar navigation: beacon admin shows only platform links
When viewing /beacon/* pages, the sidebar only shows Beacon admin links (Dashboard, Users, Global Settings, Template Types). Site-scoped links (Pages, Layouts, Components, etc.) are hidden. When viewing site-scoped pages (/:site/*), the sidebar only shows site links. Beacon admin links are hidden. Also fixed menu_link prefix matching on beacon admin pages — they need to match on "/beacon" prefix, not the full path.
1 parent d1b967e commit 539d094

4 files changed

Lines changed: 29 additions & 8 deletions

File tree

lib/beacon/live_admin/live/beacon_admin/global_template_types_live.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ defmodule Beacon.LiveAdmin.BeaconAdmin.GlobalTemplateTypesLive do
55
alias Beacon.LiveAdmin.Client.Content
66

77
@impl true
8-
def menu_link("/beacon/template_types", :index), do: {:submenu, "Global Template Types"}
8+
def menu_link("/beacon", :index), do: {:submenu, "Global Template Types"}
99
def menu_link(_, _), do: :skip
1010

1111
@impl true

lib/beacon/live_admin/live/beacon_admin/settings_live.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ defmodule Beacon.LiveAdmin.BeaconAdmin.SettingsLive do
44
use Beacon.LiveAdmin.PageBuilder
55

66
@impl true
7-
def menu_link("/beacon/settings", :settings), do: {:submenu, "Global Settings"}
7+
def menu_link("/beacon", :settings), do: {:submenu, "Global Settings"}
88
def menu_link(_, _), do: :skip
99

1010
@impl true

lib/beacon/live_admin/live/beacon_admin/users_live.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ defmodule Beacon.LiveAdmin.BeaconAdmin.UsersLive do
99
@roles ["super_admin", "site_admin", "site_editor", "site_viewer"]
1010

1111
@impl true
12-
def menu_link("/beacon/users", :index), do: {:submenu, "Users"}
12+
def menu_link("/beacon", :index), do: {:submenu, "Users"}
1313
def menu_link(_, _), do: :skip
1414

1515
@impl true

lib/beacon/live_admin/live/page_live.ex

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,25 @@ defmodule Beacon.LiveAdmin.PageLive do
172172

173173
# TODO subpath /pages/:id -> Pages menu
174174
defp assign_menu_links(socket, pages) do
175-
["", current_prefix | _] = String.split(socket.assigns.beacon_page.path, "/")
175+
current_path = socket.assigns.beacon_page.path
176+
["", current_prefix | _] = String.split(current_path, "/")
176177
current_prefix = "/" <> current_prefix
177178

179+
# When viewing /beacon/* pages, only show beacon admin links
180+
# When viewing site-scoped pages, only show site-scoped links
181+
is_beacon_admin = String.starts_with?(current_path, "/beacon")
182+
183+
filtered_pages =
184+
Enum.filter(pages, fn {path, _module, _live_action, _session} ->
185+
if is_beacon_admin do
186+
String.starts_with?(path, "/beacon")
187+
else
188+
not String.starts_with?(path, "/beacon")
189+
end
190+
end)
191+
178192
link_map =
179-
Enum.reduce(pages, %{}, fn {path, module, live_action, _session}, acc ->
193+
Enum.reduce(filtered_pages, %{}, fn {path, module, live_action, _session}, acc ->
180194
["", prefix | _] = String.split(path, "/")
181195
prefix = "/" <> prefix
182196

@@ -209,8 +223,15 @@ defmodule Beacon.LiveAdmin.PageLive do
209223
end
210224
end)
211225

226+
# Only show menu groups relevant to the current scope
227+
active_groups = if is_beacon_admin do
228+
Enum.filter(@menu_groups, fn {group_id, _, _} -> group_id == :beacon_admin end)
229+
else
230+
Enum.filter(@menu_groups, fn {group_id, _, _} -> group_id != :beacon_admin end)
231+
end
232+
212233
grouped_links =
213-
Enum.flat_map(@menu_groups, fn {_group_id, group_label, prefixes} ->
234+
Enum.flat_map(active_groups, fn {_group_id, group_label, prefixes} ->
214235
group_items =
215236
Enum.flat_map(prefixes, fn prefix ->
216237
case Map.get(link_map, prefix) do
@@ -225,8 +246,8 @@ defmodule Beacon.LiveAdmin.PageLive do
225246
end
226247
end)
227248

228-
# Append any links not in a predefined group
229-
known_prefixes = Enum.flat_map(@menu_groups, fn {_, _, prefixes} -> prefixes end)
249+
# Append any links not in a predefined group (only from filtered pages)
250+
known_prefixes = Enum.flat_map(active_groups, fn {_, _, prefixes} -> prefixes end)
230251

231252
extra_links =
232253
link_map

0 commit comments

Comments
 (0)