Add an Explore nav dropdown for instance-wide facets

1550621 · Gabriel Morell · 2026-09-09 21:34

2 files +53 -0
Message
{commit_body(@commit)}

Files changed

modified lib/git_gud_web/components/layouts.ex
+37 −0
@@ -49,6 +49,35 @@ defmodule GitGudWeb.Layouts do
49 49 </.link>
50 50 </li>
51 51
52 + <%!-- Facets: instance-wide ways to browse. Public, like the
53 + pages behind it. Hidden entirely when nothing is on. --%>
54 + <li :if={facets() != []}>
55 + <div class="dropdown dropdown-end">
56 + <div
57 + tabindex="0"
58 + role="button"
59 + class="btn btn-ghost btn-sm"
60 + id="nav-explore"
61 + aria-label="Explore"
62 + >
63 + <.icon name="hero-squares-2x2-micro" class="size-4" />
64 + <span class="hidden sm:inline">Explore</span>
65 + <.icon name="hero-chevron-down-micro" class="size-3 opacity-60" />
66 + </div>
67 + <ul
68 + tabindex="0"
69 + class="dropdown-content menu bg-base-200 border border-base-300 rounded-box z-10 mt-1 w-44 p-1 shadow-lg"
70 + >
71 + <li :for={{label, path, icon} <- facets()}>
72 + <.link navigate={path} class="flex items-center gap-2">
73 + <.icon name={icon} class="size-4" />
74 + <span>{label}</span>
75 + </.link>
76 + </li>
77 + </ul>
78 + </div>
79 + </li>
80 +
52 81 <%= if @current_scope && @current_scope.user do %>
53 82 <li>
54 83 <.link navigate={~p"/orgs"} class="btn btn-ghost btn-sm" id="nav-orgs">
@@ -196,6 +225,14 @@ defmodule GitGudWeb.Layouts do
196 225
197 226 defp user_label(_), do: "Account"
198 227
228 + # Instance-wide browse facets, as {label, path, icon}. Add future ones
229 + # here; the dropdown hides itself when the list comes back empty.
230 + defp facets do
231 + if GitGud.Syms.enabled?(),
232 + do: [{"Syms", ~p"/syms", "hero-sparkles-micro"}],
233 + else: []
234 + end
235 +
199 236 defp admin?(%{user: %{is_admin: true}}), do: true
200 237 defp admin?(_), do: false
201 238
modified test/git_gud_web/live/syms_live/top_test.exs
+16 −0
@@ -100,6 +100,22 @@ defmodule GitGudWeb.SymsLive.TopTest do
100 100 assert {:error, {:live_redirect, %{to: "/syms"}}} = live(build_conn(), ~p"/syms/#{"🍕"}")
101 101 end
102 102
103 + describe "the Explore nav dropdown" do
104 + test "carries a link to /syms, for anonymous visitors too" do
105 + {:ok, lv, _html} = live(build_conn(), ~p"/syms")
106 +
107 + assert lv |> element("#nav-explore") |> has_element?()
108 + assert lv |> element(~s{#nav-explore ~ ul a[href="/syms"]}) |> has_element?()
109 + end
110 +
111 + test "hides entirely when no facet is enabled" do
112 + Application.put_env(:git_gud, :syms, [])
113 +
114 + {:ok, lv, _html} = live(build_conn(), ~p"/repositories")
115 + refute lv |> element("#nav-explore") |> has_element?()
116 + end
117 + end
118 +
103 119 test "no configured symbols disables the page" do
104 120 Application.put_env(:git_gud, :syms, [])
105 121

Parents: 34f99c6