From bcce0568bef687ad7052248ac120999f3248b736 Mon Sep 17 00:00:00 2001 From: kraleppa Date: Wed, 28 May 2025 10:12:12 +0200 Subject: [PATCH 01/16] Updated trace topics --- .../gen_servers/callback_tracing_server.ex | 4 ++-- lib/live_debugger/utils/pubsub.ex | 13 +++++++++-- .../helpers/tracing_helper.ex | 6 ++--- .../callback_tracing_server_test.exs | 4 ++-- test/utils/pubsub_test.exs | 22 +++++++++++++++---- 5 files changed, 36 insertions(+), 13 deletions(-) diff --git a/lib/live_debugger/gen_servers/callback_tracing_server.ex b/lib/live_debugger/gen_servers/callback_tracing_server.ex index eb4674a42..ee96ef8d6 100644 --- a/lib/live_debugger/gen_servers/callback_tracing_server.ex +++ b/lib/live_debugger/gen_servers/callback_tracing_server.ex @@ -211,7 +211,7 @@ defmodule LiveDebugger.GenServers.CallbackTracingServer do fun = trace.function pid - |> PubSubUtils.trace_topic(node_id, fun, :call) + |> PubSubUtils.trace_topic_per_node(node_id, fun, :call) |> PubSubUtils.broadcast({:new_trace, trace}) end @@ -227,7 +227,7 @@ defmodule LiveDebugger.GenServers.CallbackTracingServer do end pid - |> PubSubUtils.trace_topic(node_id, fun, :return) + |> PubSubUtils.trace_topic_per_node(node_id, fun, :return) |> PubSubUtils.broadcast({:updated_trace, trace}) end end diff --git a/lib/live_debugger/utils/pubsub.ex b/lib/live_debugger/utils/pubsub.ex index c2d2e5a2c..8d459ebf0 100644 --- a/lib/live_debugger/utils/pubsub.ex +++ b/lib/live_debugger/utils/pubsub.ex @@ -71,16 +71,25 @@ defmodule LiveDebugger.Utils.PubSub do Use `{:new_trace, trace}` or `{:updated_trace, trace}` for broadcasting. """ - @spec trace_topic( + @spec trace_topic_per_node( pid :: pid(), node_id :: TreeNode.id(), fun :: atom(), type :: :call | :return ) :: String.t() - def trace_topic(pid, node_id, fun, type \\ :call) do + def trace_topic_per_node(pid, node_id, fun, type \\ :call) do "#{inspect(pid)}/#{inspect(node_id)}/#{inspect(fun)}/#{inspect(type)}" end + @spec trace_topic_per_pid( + pid :: pid(), + fun :: atom(), + type :: :call | :return + ) :: String.t() + def trace_topic_per_pid(pid, fun, type \\ :call) do + "#{inspect(pid)}/#{inspect(fun)}/#{inspect(type)}" + end + @spec impl() :: module() defp impl() do Application.get_env( diff --git a/lib/live_debugger_web/helpers/tracing_helper.ex b/lib/live_debugger_web/helpers/tracing_helper.ex index 69578a585..d7a43a67c 100644 --- a/lib/live_debugger_web/helpers/tracing_helper.ex +++ b/lib/live_debugger_web/helpers/tracing_helper.ex @@ -142,13 +142,13 @@ defmodule LiveDebuggerWeb.Helpers.TracingHelper do |> Enum.filter(fn {_, active?} -> active? end) |> Enum.flat_map(fn {function, _} -> [ - PubSubUtils.trace_topic( + PubSubUtils.trace_topic_per_node( lv_process.pid, node_id, function, :call ), - PubSubUtils.trace_topic( + PubSubUtils.trace_topic_per_node( lv_process.pid, node_id, function, @@ -164,7 +164,7 @@ defmodule LiveDebuggerWeb.Helpers.TracingHelper do socket.assigns.current_filters.functions |> Enum.map(fn {function, _} -> - PubSubUtils.trace_topic( + PubSubUtils.trace_topic_per_node( lv_process.pid, node_id, function, diff --git a/test/gen_servers/callback_tracing_server_test.exs b/test/gen_servers/callback_tracing_server_test.exs index 10a07781e..18617a006 100644 --- a/test/gen_servers/callback_tracing_server_test.exs +++ b/test/gen_servers/callback_tracing_server_test.exs @@ -128,10 +128,10 @@ defmodule LiveDebugger.GenServers.CallbackTracingServerTest do table = :ets.new(:test_table, [:ordered_set, :public]) expected_trace_call_topic = - PubSubUtils.trace_topic(pid, pid, fun, :call) + PubSubUtils.trace_topic_per_node(pid, pid, fun, :call) expected_trace_return_topic = - PubSubUtils.trace_topic(pid, pid, fun, :return) + PubSubUtils.trace_topic_per_node(pid, pid, fun, :return) MockEtsTableServer |> expect(:table, 2, fn ^pid -> table end) diff --git a/test/utils/pubsub_test.exs b/test/utils/pubsub_test.exs index 8a8d0ec76..dd2cf19d5 100644 --- a/test/utils/pubsub_test.exs +++ b/test/utils/pubsub_test.exs @@ -20,19 +20,33 @@ defmodule LiveDebugger.Utils.PubSubTest do assert "lvdbg/process_status" = PubSubUtils.process_status_topic() end - test "trace_topic/4" do + test "trace_topic_per_node/4" do pid = :c.pid(0, 1, 0) node_id = :c.pid(0, 2, 0) fun = :handle_info assert "#PID<0.1.0>/#PID<0.2.0>/:handle_info/:call" = - PubSubUtils.trace_topic(pid, node_id, fun) + PubSubUtils.trace_topic_per_node(pid, node_id, fun) assert "#PID<0.1.0>/#PID<0.2.0>/:handle_info/:call" = - PubSubUtils.trace_topic(pid, node_id, fun, :call) + PubSubUtils.trace_topic_per_node(pid, node_id, fun, :call) assert "#PID<0.1.0>/#PID<0.2.0>/:handle_info/:return" = - PubSubUtils.trace_topic(pid, node_id, fun, :return) + PubSubUtils.trace_topic_per_node(pid, node_id, fun, :return) + end + + test "trace_topic_per_pid/3" do + pid = :c.pid(0, 1, 0) + fun = :handle_info + + assert "#PID<0.1.0>/:handle_info/:call" = + PubSubUtils.trace_topic_per_pid(pid, fun) + + assert "#PID<0.1.0>/:handle_info/:call" = + PubSubUtils.trace_topic_per_pid(pid, fun, :call) + + assert "#PID<0.1.0>/:handle_info/:return" = + PubSubUtils.trace_topic_per_pid(pid, fun, :return) end describe "mock" do From bfe7cdf44918e5f576652b4dbeb17f28bd509fcc Mon Sep 17 00:00:00 2001 From: kraleppa Date: Wed, 28 May 2025 11:43:17 +0200 Subject: [PATCH 02/16] Added basic global traces view and basic routing --- .../components/navigation_menu.ex | 19 +++++++++++++++---- .../helpers/routes_helper.ex | 5 +++++ .../live/channel_dashboard_live.ex | 3 ++- .../live/global_traces_live.ex | 12 ++++++++++++ lib/live_debugger_web/router.ex | 1 + 5 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 lib/live_debugger_web/live/global_traces_live.ex diff --git a/lib/live_debugger_web/components/navigation_menu.ex b/lib/live_debugger_web/components/navigation_menu.ex index 118acba23..9a0f238b1 100644 --- a/lib/live_debugger_web/components/navigation_menu.ex +++ b/lib/live_debugger_web/components/navigation_menu.ex @@ -5,8 +5,10 @@ defmodule LiveDebuggerWeb.Components.NavigationMenu do use LiveDebuggerWeb, :component alias LiveDebuggerWeb.LiveComponents.LiveDropdown + alias LiveDebuggerWeb.Helpers.RoutesHelper attr(:class, :any, default: nil, doc: "Additional classes to add to the navigation bar.") + attr(:pid, :any, required: true) def sidebar(assigns) do ~H""" @@ -14,14 +16,19 @@ defmodule LiveDebuggerWeb.Components.NavigationMenu do "flex flex-col gap-3 bg-sidebar-bg shadow-custom h-full p-2 border-r border-default-border" | List.wrap(@class) ]}> - <.nav_icon icon="icon-info" /> - <.nav_icon icon="icon-globe" /> + <.link navigate={RoutesHelper.channel_dashboard(@pid)}> + <.nav_icon icon="icon-info" /> + + <.link navigate={RoutesHelper.global_traces(@pid)}> + <.nav_icon icon="icon-globe" /> + """ 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(:lv_process, :any, required: true) def dropdown(assigns) do ~H""" @@ -39,8 +46,12 @@ defmodule LiveDebuggerWeb.Components.NavigationMenu do - - + <.link :if={@lv_process.ok?} navigate={RoutesHelper.channel_dashboard(@lv_process.result.pid)}> + + + <.link :if={@lv_process.ok?} navigate={RoutesHelper.global_traces(@lv_process.result.pid)}> + + """ diff --git a/lib/live_debugger_web/helpers/routes_helper.ex b/lib/live_debugger_web/helpers/routes_helper.ex index 7083d9f35..0c2e74d42 100644 --- a/lib/live_debugger_web/helpers/routes_helper.ex +++ b/lib/live_debugger_web/helpers/routes_helper.ex @@ -37,4 +37,9 @@ defmodule LiveDebuggerWeb.Helpers.RoutesHelper do def settings(return_to) do ~p"/settings?return_to=#{return_to}" end + + @spec global_traces(pid :: pid()) :: String.t() + def global_traces(pid) when is_pid(pid) do + ~p"/pid/#{Parsers.pid_to_string(pid)}/global_traces" + end end diff --git a/lib/live_debugger_web/live/channel_dashboard_live.ex b/lib/live_debugger_web/live/channel_dashboard_live.ex index 485c0f731..0bf010700 100644 --- a/lib/live_debugger_web/live/channel_dashboard_live.ex +++ b/lib/live_debugger_web/live/channel_dashboard_live.ex @@ -37,6 +37,7 @@ defmodule LiveDebuggerWeb.ChannelDashboardLive do /> @@ -70,7 +71,7 @@ defmodule LiveDebuggerWeb.ChannelDashboardLive do
-
""" end From 18d8cba0c43a5dbb60b6e7daa67319dcc95f4382 Mon Sep 17 00:00:00 2001 From: kraleppa Date: Thu, 29 May 2025 12:47:47 +0200 Subject: [PATCH 09/16] Updated `connected` tooltip --- lib/live_debugger_web/components/navbar.ex | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/lib/live_debugger_web/components/navbar.ex b/lib/live_debugger_web/components/navbar.ex index 3a0cef2dc..677f2f848 100644 --- a/lib/live_debugger_web/components/navbar.ex +++ b/lib/live_debugger_web/components/navbar.ex @@ -89,16 +89,7 @@ defmodule LiveDebuggerWeb.Components.Navbar do def connected(assigns) do ~H""" - <.tooltip - id={@id} - position="bottom" - content={ - if(@connected?, - do: "LiveView process is alive", - else: "LiveView process is dead. You can still debug the last state." - ) - } - > + <.tooltip id={@id} position="bottom" content={tooltip_content(@connected?)}>
<.status_icon connected?={@connected?} /> <%= if @connected? do %> @@ -128,4 +119,12 @@ defmodule LiveDebuggerWeb.Components.Navbar do
""" end + + defp tooltip_content(true) do + "LiveView process is alive" + end + + defp tooltip_content(false) do + "LiveView process is dead - you can still debug the last state" + end end From 633a456b64437141a53c71fcc90bd954307992f1 Mon Sep 17 00:00:00 2001 From: kraleppa Date: Thu, 29 May 2025 13:19:37 +0200 Subject: [PATCH 10/16] Changed loading of connected element --- lib/live_debugger_web/components/navbar.ex | 48 +++++++++++++------ .../live/channel_dashboard_live.ex | 14 +----- .../live/global_traces_live.ex | 15 +----- 3 files changed, 37 insertions(+), 40 deletions(-) diff --git a/lib/live_debugger_web/components/navbar.ex b/lib/live_debugger_web/components/navbar.ex index 677f2f848..f31538cc5 100644 --- a/lib/live_debugger_web/components/navbar.ex +++ b/lib/live_debugger_web/components/navbar.ex @@ -6,6 +6,7 @@ defmodule LiveDebuggerWeb.Components.Navbar do use LiveDebuggerWeb, :component alias LiveDebuggerWeb.Helpers.RoutesHelper + alias LiveDebugger.Utils.Parsers @doc """ Renders base navbar component. @@ -83,18 +84,22 @@ defmodule LiveDebuggerWeb.Components.Navbar do When button is clicked, it will trigger a `find-successor` event with the PID of the LiveView. """ attr(:id, :string, required: true) - attr(:connected?, :boolean, required: true, doc: "Whether LiveView is connected.") - attr(:pid, :string, required: true, doc: "The PID of the LiveView.") + attr(:lv_process, :map, required: true, doc: "The LiveView process.") attr(:rest, :global) - def connected(assigns) do + def connected(%{lv_process: %{ok?: true}} = assigns) do + connected? = assigns.lv_process.result.alive? + status = if(connected?, do: :connected, else: :disconnected) + + assigns = assign(assigns, status: status, connected?: connected?) + ~H""" <.tooltip id={@id} position="bottom" content={tooltip_content(@connected?)}>
- <.status_icon connected?={@connected?} /> + <.status_icon status={@status} /> <%= if @connected? do %> Monitored PID - <%= @pid %> + <%= Parsers.pid_to_string(@lv_process.result.pid) %> <% else %> Disconnected <.button phx-click="find-successor" variant="secondary" size="sm">Continue @@ -104,18 +109,33 @@ defmodule LiveDebuggerWeb.Components.Navbar do """ end - attr(:connected?, :boolean, required: true) + def connected(assigns) do + ~H""" +
+ <.status_icon status={:loading} /> + Loading LiveView process... +
+ """ + end + + attr(:status, :atom, required: true, values: [:connected, :disconnected, :loading]) defp status_icon(assigns) do + assigns = + case(assigns.status) do + :connected -> + assign(assigns, icon: "icon-check-small", class: "bg-[--swm-green-100]") + + :disconnected -> + assign(assigns, icon: "icon-cross-small", class: "bg-[--swm-pink-100]") + + :loading -> + assign(assigns, icon: nil, class: "bg-[--swm-yellow-100] animate-pulse") + end + ~H""" -
- <.icon - name={if(@connected?, do: "icon-check-small", else: "icon-cross-small")} - class="bg-white w-4 h-4" - /> +
+ <.icon :if={@icon} name={@icon} class="bg-white w-4 h-4" />
""" end diff --git a/lib/live_debugger_web/live/channel_dashboard_live.ex b/lib/live_debugger_web/live/channel_dashboard_live.ex index cf69477b2..8da54d763 100644 --- a/lib/live_debugger_web/live/channel_dashboard_live.ex +++ b/lib/live_debugger_web/live/channel_dashboard_live.ex @@ -16,7 +16,6 @@ defmodule LiveDebuggerWeb.ChannelDashboardLive do alias LiveDebuggerWeb.TracesLive alias LiveDebuggerWeb.SidebarLive alias LiveDebugger.Utils.PubSub, as: PubSubUtils - alias LiveDebugger.Utils.Parsers alias LiveDebuggerWeb.Components.NavigationMenu @impl true @@ -41,18 +40,7 @@ defmodule LiveDebuggerWeb.ChannelDashboardLive do class="sm:hidden" /> -
- Loading... -
- +
diff --git a/lib/live_debugger_web/live/global_traces_live.ex b/lib/live_debugger_web/live/global_traces_live.ex index ce3ba9d31..5ede0e3c6 100644 --- a/lib/live_debugger_web/live/global_traces_live.ex +++ b/lib/live_debugger_web/live/global_traces_live.ex @@ -5,7 +5,6 @@ defmodule LiveDebuggerWeb.GlobalTracesLive do alias LiveDebuggerWeb.Components.Navbar alias LiveDebuggerWeb.Components.NavigationMenu alias LiveDebuggerWeb.Helpers.RoutesHelper - alias LiveDebugger.Utils.Parsers @impl true def render(assigns) do @@ -22,18 +21,8 @@ defmodule LiveDebuggerWeb.GlobalTracesLive do class="sm:hidden" /> -
- Loading... -
- + +
From f0ac5d9d7640028f8a7f7c8d0f062b2b2ec47281 Mon Sep 17 00:00:00 2001 From: kraleppa Date: Thu, 29 May 2025 13:37:35 +0200 Subject: [PATCH 11/16] Fixed bug with redirecting with query params --- lib/live_debugger/utils/url.ex | 5 +++++ lib/live_debugger_web/components/navigation_menu.ex | 3 +++ 2 files changed, 8 insertions(+) diff --git a/lib/live_debugger/utils/url.ex b/lib/live_debugger/utils/url.ex index 4dda678e2..676217b28 100644 --- a/lib/live_debugger/utils/url.ex +++ b/lib/live_debugger/utils/url.ex @@ -48,6 +48,11 @@ defmodule LiveDebugger.Utils.URL do modify_query_params(url, &Map.drop(&1, keys)) end + @spec remove_query_params(url :: String.t()) :: String.t() + def remove_query_params(url) when is_binary(url) do + modify_query_params(url, fn _ -> %{} end) + end + @spec modify_query_params(url :: String.t(), fun :: (map() -> map())) :: String.t() def modify_query_params(url, fun) when is_binary(url) and is_function(fun) do uri = URI.parse(url) diff --git a/lib/live_debugger_web/components/navigation_menu.ex b/lib/live_debugger_web/components/navigation_menu.ex index 4c952d263..dc0603712 100644 --- a/lib/live_debugger_web/components/navigation_menu.ex +++ b/lib/live_debugger_web/components/navigation_menu.ex @@ -6,6 +6,7 @@ defmodule LiveDebuggerWeb.Components.NavigationMenu do alias LiveDebuggerWeb.LiveComponents.LiveDropdown alias LiveDebuggerWeb.Helpers.RoutesHelper + alias LiveDebugger.Utils.URL attr(:class, :any, default: nil, doc: "Additional classes to add to the navigation bar.") attr(:current_url, :any, required: true) @@ -93,12 +94,14 @@ defmodule LiveDebuggerWeb.Components.NavigationMenu do defp get_current_view(url) do url + |> URL.remove_query_params() |> String.split("/") |> Enum.at(3, "node_inspector") end defp get_pid(url) do url + |> URL.remove_query_params() |> String.split("/") |> Enum.at(2) end From 23d20242108884b520edc538fe904653ad1762a0 Mon Sep 17 00:00:00 2001 From: kraleppa Date: Thu, 29 May 2025 13:38:41 +0200 Subject: [PATCH 12/16] Added test --- test/utils/url_test.exs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/utils/url_test.exs b/test/utils/url_test.exs index 81acfc5ee..141126f2b 100644 --- a/test/utils/url_test.exs +++ b/test/utils/url_test.exs @@ -97,6 +97,13 @@ defmodule LiveDebugger.Utils.URLTest do end end + describe "remove_query_params/1" do + test "removes all query parameters from a URL" do + assert URL.remove_query_params("http://example.com/foo?key1=value1&key2=value2") == + "http://example.com/foo" + end + end + describe "modify_query_params/2" do test "modifies query parameters in a URL using a function" do assert URL.modify_query_params("http://example.com/foo?key=value", fn params -> From 10a9a29ec99aab667f0d0d26635eecacf413f8de Mon Sep 17 00:00:00 2001 From: kraleppa Date: Thu, 29 May 2025 17:49:07 +0200 Subject: [PATCH 13/16] Changed tooltip designs --- assets/css/app.css | 10 +--------- assets/css/themes/dark.css | 4 ++++ assets/css/themes/light.css | 4 ++++ assets/tailwind.config.js | 2 ++ lib/live_debugger_web/layout.ex | 3 +-- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/assets/css/app.css b/assets/css/app.css index f60047e6d..e5cd0392e 100644 --- a/assets/css/app.css +++ b/assets/css/app.css @@ -40,17 +40,9 @@ body::-webkit-scrollbar { } .tooltip-primary { - background-color: var(--button-primary-bg); - color: var(--button-primary-content); - padding: 0.5rem; - border-radius: 0.25rem; font-weight: 600; } .tooltip-secondary { - background-color: var(--button-secondary-bg); - color: var(--button-secondary-content); - padding: 0.5rem; - border-radius: 0.25rem; - font-weight: 600; + font-weight: 400; } diff --git a/assets/css/themes/dark.css b/assets/css/themes/dark.css index 4fbc98321..f23f83426 100644 --- a/assets/css/themes/dark.css +++ b/assets/css/themes/dark.css @@ -44,6 +44,10 @@ --button-secondary-content: var(--gray-200); --button-secondary-content-hover: var(--gray-200); + /* Tooltip */ + --tooltip-text: var(--gray-900); + --tooltip-bg: var(--swm-sea-blue-60); + /* Icons */ --accent-icon: var(--swm-sea-blue-60); diff --git a/assets/css/themes/light.css b/assets/css/themes/light.css index 371efa974..773d289cd 100644 --- a/assets/css/themes/light.css +++ b/assets/css/themes/light.css @@ -44,6 +44,10 @@ --button-secondary-content: var(--swm-brand); --button-secondary-content-hover: var(--swm-brand); + /* Tooltip */ + --tooltip-text: var(--neutrals-white); + --tooltip-bg: var(--swm-brand); + /* Icons */ --accent-icon: var(--swm-brand); diff --git a/assets/tailwind.config.js b/assets/tailwind.config.js index 63bf4727f..28b217841 100644 --- a/assets/tailwind.config.js +++ b/assets/tailwind.config.js @@ -52,6 +52,8 @@ module.exports = { 'button-secondary-content': 'var(--button-secondary-content)', 'button-secondary-content-hover': 'var(--button-secondary-content-hover)', + 'tooltip-text': 'var(--tooltip-text)', + 'tooltip-bg': 'var(--tooltip-bg)', 'accent-icon': 'var(--accent-icon)', 'sidebar-bg': 'var(--sidebar-bg)', 'code-1': 'var(--code-1)', diff --git a/lib/live_debugger_web/layout.ex b/lib/live_debugger_web/layout.ex index ce569e06b..24a169211 100644 --- a/lib/live_debugger_web/layout.ex +++ b/lib/live_debugger_web/layout.ex @@ -55,8 +55,7 @@ defmodule LiveDebuggerWeb.Layout do window.liveSocket = liveSocket; - + <%= @inner_content %> From 878ab128d9905906d6760d227a49d22333d33755 Mon Sep 17 00:00:00 2001 From: kraleppa Date: Thu, 29 May 2025 17:52:21 +0200 Subject: [PATCH 14/16] Added `take_nth` function --- lib/live_debugger/utils/url.ex | 8 ++++++++ lib/live_debugger_web/components/navigation_menu.ex | 10 ++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/live_debugger/utils/url.ex b/lib/live_debugger/utils/url.ex index 676217b28..a4d2ebe45 100644 --- a/lib/live_debugger/utils/url.ex +++ b/lib/live_debugger/utils/url.ex @@ -53,6 +53,14 @@ defmodule LiveDebugger.Utils.URL do modify_query_params(url, fn _ -> %{} end) end + @spec take_nth_segment(url :: String.t(), n :: integer()) :: String.t() | nil + def take_nth_segment(url, n) when is_binary(url) and is_integer(n) do + url + |> remove_query_params() + |> String.split("/") + |> Enum.at(n) + end + @spec modify_query_params(url :: String.t(), fun :: (map() -> map())) :: String.t() def modify_query_params(url, fun) when is_binary(url) and is_function(fun) do uri = URI.parse(url) diff --git a/lib/live_debugger_web/components/navigation_menu.ex b/lib/live_debugger_web/components/navigation_menu.ex index dc0603712..c6e36be64 100644 --- a/lib/live_debugger_web/components/navigation_menu.ex +++ b/lib/live_debugger_web/components/navigation_menu.ex @@ -93,16 +93,10 @@ defmodule LiveDebuggerWeb.Components.NavigationMenu do end defp get_current_view(url) do - url - |> URL.remove_query_params() - |> String.split("/") - |> Enum.at(3, "node_inspector") + URL.take_nth_segment(url, 3) end defp get_pid(url) do - url - |> URL.remove_query_params() - |> String.split("/") - |> Enum.at(2) + URL.take_nth_segment(url, 2) end end From b1660b9ef4fd6b0f063613b343bc892fed7f6709 Mon Sep 17 00:00:00 2001 From: kraleppa Date: Thu, 29 May 2025 17:54:50 +0200 Subject: [PATCH 15/16] Added tests for take_nth_segment --- lib/live_debugger/utils/url.ex | 1 + test/utils/url_test.exs | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/lib/live_debugger/utils/url.ex b/lib/live_debugger/utils/url.ex index a4d2ebe45..5f8b3c11c 100644 --- a/lib/live_debugger/utils/url.ex +++ b/lib/live_debugger/utils/url.ex @@ -56,6 +56,7 @@ defmodule LiveDebugger.Utils.URL do @spec take_nth_segment(url :: String.t(), n :: integer()) :: String.t() | nil def take_nth_segment(url, n) when is_binary(url) and is_integer(n) do url + |> to_relative() |> remove_query_params() |> String.split("/") |> Enum.at(n) diff --git a/test/utils/url_test.exs b/test/utils/url_test.exs index 141126f2b..32f09f200 100644 --- a/test/utils/url_test.exs +++ b/test/utils/url_test.exs @@ -104,6 +104,28 @@ defmodule LiveDebugger.Utils.URLTest do end end + describe "take_nth_segment/2" do + test "takes the nth segment of a URL" do + assert URL.take_nth_segment("http://example.com/foo/bar/baz", 2) == "bar" + end + + test "returns nil if the URL has no segments" do + assert URL.take_nth_segment("http://example.com", 2) == nil + end + + test "returns nil if the nth segment is out of bounds" do + assert URL.take_nth_segment("http://example.com/foo/bar/baz", 4) == nil + end + + test "returns the nth segment of a relative URL" do + assert URL.take_nth_segment("/foo/bar/baz", 2) == "bar" + end + + test "returns nil if the relative URL has no segments" do + assert URL.take_nth_segment("/", 2) == nil + end + end + describe "modify_query_params/2" do test "modifies query parameters in a URL using a function" do assert URL.modify_query_params("http://example.com/foo?key=value", fn params -> From 00933ce03ae221802b8ce8a9eea30ed702e401f8 Mon Sep 17 00:00:00 2001 From: kraleppa Date: Thu, 29 May 2025 17:59:13 +0200 Subject: [PATCH 16/16] Fixed bug with switching font-weight of tooltips --- assets/css/app.css | 8 -------- assets/js/hooks/tooltip.js | 3 ++- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/assets/css/app.css b/assets/css/app.css index e5cd0392e..e5e7fd69a 100644 --- a/assets/css/app.css +++ b/assets/css/app.css @@ -38,11 +38,3 @@ body::-webkit-scrollbar { ::-webkit-scrollbar-corner { background: transparent; } - -.tooltip-primary { - font-weight: 600; -} - -.tooltip-secondary { - font-weight: 400; -} diff --git a/assets/js/hooks/tooltip.js b/assets/js/hooks/tooltip.js index c486add0d..7f6361e2e 100644 --- a/assets/js/hooks/tooltip.js +++ b/assets/js/hooks/tooltip.js @@ -2,7 +2,8 @@ const Tooltip = { mounted() { this.handleMouseEnter = () => { tooltipEl.style.display = 'block'; - tooltipEl.classList.add(`tooltip-${this.el.dataset.variant}`); + tooltipEl.style.fontWeight = + this.el.dataset.variant === 'primary' ? '600' : '400'; tooltipEl.innerHTML = this.el.dataset.tooltip; const tooltipRect = tooltipEl.getBoundingClientRect();