Skip to content

Commit cdfbff6

Browse files
committed
Fix Beacon admin sidebar links — use paths without site prefix
Beacon admin pages (/beacon/*) were generating sidebar links with the site prefix (e.g., /admin/dockyard_com/beacon/users) because maybe_link always called beacon_live_admin_path with the site. Now build_link_path/3 detects /beacon/* paths and generates links without the site prefix (e.g., /admin/beacon/users). Added beacon_live_admin_path/2 (socket, path) for generating platform-level paths without a site segment.
1 parent 539d094 commit cdfbff6

2 files changed

Lines changed: 29 additions & 2 deletions

File tree

lib/beacon/live_admin/live/page_live.ex

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ defmodule Beacon.LiveAdmin.PageLive do
311311
end
312312

313313
defp maybe_link(socket, page, {:current, text, icon, path}) do
314-
path = Beacon.LiveAdmin.Router.beacon_live_admin_path(socket, page.site, path)
314+
path = build_link_path(socket, page, path)
315315
assigns = %{text: text, icon: icon, path: path}
316316

317317
# use href to force redirecting to re-execute plug to fecth current url
@@ -329,7 +329,7 @@ defmodule Beacon.LiveAdmin.PageLive do
329329
end
330330

331331
defp maybe_link(socket, page, {:enabled, text, icon, path}) do
332-
path = Beacon.LiveAdmin.Router.beacon_live_admin_path(socket, page.site, path)
332+
path = build_link_path(socket, page, path)
333333
assigns = %{text: text, icon: icon, path: path}
334334

335335
# force redirect to re-execute plug to fecth current url
@@ -355,4 +355,14 @@ defmodule Beacon.LiveAdmin.PageLive do
355355
</span>
356356
"""
357357
end
358+
359+
# Beacon admin pages (/beacon/*) don't need the site prefix
360+
defp build_link_path(socket, _page, "/beacon" <> _ = path) do
361+
Beacon.LiveAdmin.Router.beacon_live_admin_path(socket, path)
362+
end
363+
364+
# Site-scoped pages get the site prefix
365+
defp build_link_path(socket, page, path) do
366+
Beacon.LiveAdmin.Router.beacon_live_admin_path(socket, page.site, path)
367+
end
358368
end

lib/beacon/live_admin/router.ex

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,23 @@ defmodule Beacon.LiveAdmin.Router do
398398
Phoenix.VerifiedRoutes.unverified_path(conn_or_socket, router, path, %{})
399399
end
400400

401+
@doc """
402+
Generates a path without a site prefix (for platform-level pages).
403+
404+
## Example
405+
406+
iex> Beacon.LiveAdmin.Router.beacon_live_admin_path(@socket, "/beacon/users")
407+
"/my_admin/beacon/users"
408+
409+
"""
410+
@spec beacon_live_admin_path(conn_or_socket, String.t()) :: String.t()
411+
def beacon_live_admin_path(conn_or_socket, path) when is_binary(path) do
412+
router = router(conn_or_socket)
413+
prefix = router.__beacon_live_admin_prefix__()
414+
path = sanitize_path("#{prefix}#{path}")
415+
Phoenix.VerifiedRoutes.unverified_path(conn_or_socket, router, path, %{})
416+
end
417+
401418
@doc """
402419
Generate the path to serve files in `priv/static`.
403420

0 commit comments

Comments
 (0)