defmodule LiveDebuggerWeb.Components.NavigationMenu do
@moduledoc """
Set of components used in the navigation menu.
"""
use LiveDebuggerWeb, :component
alias LiveDebuggerWeb.LiveComponents.LiveDropdown
alias LiveDebuggerWeb.Helpers.RoutesHelper
alias LiveDebugger.Utils.URL
alias Phoenix.LiveView.JS
attr(:class, :any, default: nil, doc: "Additional classes to add to the navigation bar.")
attr(:current_url, :any, required: true)
def sidebar(assigns) do
assigns =
assign(assigns,
pid: get_pid(assigns.current_url),
current_view: get_current_view(assigns.current_url)
)
~H"""
<.tooltip id="node-inspector-tooltip" position="right" content="Node Inspector">
<.link patch={RoutesHelper.channel_dashboard(@pid)}>
<.nav_icon icon="icon-info" selected?={@current_view == "node_inspector"} />
<.tooltip id="global-traces-tooltip" position="right" content="Global Callbacks">
<.link patch={RoutesHelper.global_traces(@pid)}>
<.nav_icon icon="icon-globe" selected?={@current_view == "global_traces"} />
"""
end
attr(:class, :any, default: nil, doc: "Additional classes to add to the navigation bar.")
attr(:return_link, :any, required: true, doc: "Link to navigate to.")
attr(:current_url, :any, required: true)
def dropdown(assigns) do
assigns =
assign(assigns,
pid: get_pid(assigns.current_url),
current_view: get_current_view(assigns.current_url)
)
~H"""
<.live_component
module={LiveDropdown}
id="navigation-bar-dropdown"
class={@class}
direction="right"
>
<:button>
<.nav_icon icon="icon-menu-hamburger" />
<.link patch={@return_link}>
"""
end
# We do it to make sure that the dropdown is closed when the item is clicked.
defp dropdown_item_click(url) do
url
|> JS.patch()
|> JS.push("close", target: "#navigation-bar-dropdown-live-dropdown-container")
end
defp get_current_view(url) do
URL.take_nth_segment(url, 3) || "node_inspector"
end
defp get_pid(url) do
URL.take_nth_segment(url, 2)
end
end