Skip to content

Commit 068df0f

Browse files
committed
Add configurable :logo_path option for dashboard
Allow users to customize where the Oban logo links to by passing a `:logo_path` option to the `oban_dashboard/1` router helper. When provided, the logo will link to the specified path instead of the default jobs page. Closes #149
1 parent c99771b commit 068df0f

4 files changed

Lines changed: 26 additions & 10 deletions

File tree

lib/oban/web/components/layouts.ex

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ defmodule Oban.Web.Layouts do
1717
)
1818
end
1919

20+
attr :path, :string, default: nil
21+
2022
def logo(assigns) do
2123
~H"""
22-
<a href={oban_path(:jobs)} title="Oban Web">
24+
<a href={@path || oban_path(:jobs)} title="Oban Web">
2325
<svg class="h-10 overflow-visible" viewBox="0 0 227 64">
2426
<path
2527
class="text-violet-950 dark:text-violet-50"

lib/oban/web/components/layouts/live.html.heex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
<header class="flex items-center">
1010
<div class="md:w-84 mr-3">
11-
<.logo />
11+
<.logo path={@logo_path} />
1212
</div>
1313

1414
<.nav socket={@socket} page={@page.name} />

lib/oban/web/dashboard_live.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ defmodule Oban.Web.DashboardLive do
88
%{"prefix" => prefix, "resolver" => resolver} = session
99
%{"live_path" => live_path, "live_transport" => live_transport} = session
1010
%{"user" => user, "access" => access, "csp_nonces" => csp_nonces} = session
11-
%{"refresh" => refresh} = session
11+
%{"refresh" => refresh, "logo_path" => logo_path} = session
1212

1313
refresh = restore_state(socket, "refresh", refresh)
1414
theme = restore_state(socket, "theme", "system")
@@ -24,7 +24,7 @@ defmodule Oban.Web.DashboardLive do
2424
socket =
2525
socket
2626
|> assign(conf: conf, params: params, page: page, init_state: init_state(socket))
27-
|> assign(live_path: live_path, live_transport: live_transport)
27+
|> assign(live_path: live_path, live_transport: live_transport, logo_path: logo_path)
2828
|> assign(access: access, csp_nonces: csp_nonces, resolver: resolver, user: user)
2929
|> assign(original_refresh: nil, refresh: refresh, timer: nil, theme: theme)
3030
|> assign(sidebar_width: sidebar_width)

lib/oban/web/router.ex

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,13 @@ defmodule Oban.Web.Router do
144144
145145
* `:as` — override the route name; otherwise defaults to `:oban_dashboard`
146146
147+
* `:csp_nonce_assign_key` — CSP (Content Security Policy) keys used to authenticate image,
148+
style, and script assets by pulling a generated nonce out of the connection's `assigns` map. May
149+
be `nil`, a single atom, or a map of atoms. Defaults to `nil`.
150+
151+
* `:logo_path` — a custom path for the logo link in the header, allowing the logo to link to
152+
another page in your application instead of the Oban dashboard root. Defaults to the jobs page.
153+
147154
* `:on_mount` — declares additional module callbacks to be invoked when the dashboard mounts
148155
149156
* `:oban_name` — name of the Oban instance the dashboard will use for configuration and
@@ -157,10 +164,6 @@ defmodule Oban.Web.Router do
157164
* `:transport` — a phoenix socket transport, either `"websocket"` or `"longpoll"`, defaults to
158165
`"websocket"`.
159166
160-
* `:csp_nonce_assign_key` — CSP (Content Security Policy) keys used to authenticate image,
161-
style, and script assets by pulling a generated nonce out of the connection's `assigns` map. May
162-
be `nil`, a single atom, or a map of atoms. Defaults to `nil`.
163-
164167
## Examples
165168
166169
Mount an `oban` dashboard at the path "/oban":
@@ -225,7 +228,8 @@ defmodule Oban.Web.Router do
225228
opts[:resolver],
226229
opts[:socket_path],
227230
opts[:transport],
228-
opts[:csp_nonce_assign_key]
231+
opts[:csp_nonce_assign_key],
232+
opts[:logo_path]
229233
]
230234

231235
session_opts = [
@@ -240,7 +244,7 @@ defmodule Oban.Web.Router do
240244
end
241245

242246
@doc false
243-
def __session__(conn, prefix, oban, resolver, live_path, live_transport, csp_key) do
247+
def __session__(conn, prefix, oban, resolver, live_path, live_transport, csp_key, logo_path) do
244248
user = Resolver.call_with_fallback(resolver, :resolve_user, [conn])
245249

246250
csp_keys = expand_csp_nonce_keys(csp_key)
@@ -254,6 +258,7 @@ defmodule Oban.Web.Router do
254258
"refresh" => Resolver.call_with_fallback(resolver, :resolve_refresh, [user]),
255259
"live_path" => live_path,
256260
"live_transport" => live_transport,
261+
"logo_path" => logo_path,
257262
"csp_nonces" => %{
258263
img: conn.assigns[csp_keys[:img]],
259264
style: conn.assigns[csp_keys[:style]],
@@ -275,6 +280,15 @@ defmodule Oban.Web.Router do
275280
end
276281
end
277282

283+
defp validate_opt!({:logo_path, path}) do
284+
unless is_nil(path) or (is_binary(path) and byte_size(path) > 0) do
285+
raise ArgumentError, """
286+
invalid :logo_path, expected nil or a non-empty binary path,
287+
got: #{inspect(path)}
288+
"""
289+
end
290+
end
291+
278292
defp validate_opt!({:oban_name, name}) do
279293
unless is_atom(name) do
280294
raise ArgumentError, """

0 commit comments

Comments
 (0)