Skip to content

Commit 86aafb6

Browse files
committed
Squashed merge commit with 359-create-form-for-filtering-by-execution-time:
Merge branch 'main' into 359-create-form-for-filtering-by-execution-time Change micro symbol rendering Chore: update shields in README.md (#375) Refactor Chore: update GitHub workflows (#374) Bug: allowed iframe in LiveDebugger router (#372) Bug: fixed callback tracing after components switching (#373) Rename Add form inputs for filtering by execution time Add input component
1 parent b949d91 commit 86aafb6

8 files changed

Lines changed: 102 additions & 27 deletions

File tree

.github/workflows/assets.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
push:
55
branches:
66
- main
7+
- "v*.*"
78

89
jobs:
910
build:

.github/workflows/elixir-ci.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@ name: Elixir CI
77

88
on:
99
push:
10-
branches: ["main"]
10+
branches:
11+
- main
12+
- "v*.*"
1113
pull_request:
12-
branches: ["main"]
14+
branches:
15+
- main
1316

1417
permissions:
1518
contents: read

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
<div align="center">
44

5-
[![Version Badge](https://img.shields.io/badge/version-v0.2.0-%23b5e1f1)](https://hexdocs.pm/live_debugger)
6-
[![Hex.pm Downloads](https://img.shields.io/hexpm/dw/live_debugger?style=flat&label=downloads&color=%23b5e1f1)](https://hex.pm/packages/live_debugger)
7-
[![GitHub License](https://img.shields.io/github/license/software-mansion/live-debugger?color=%23b5e1f1)](https://github.com/software-mansion/live-debugger/blob/main/LICENSE)
5+
[![Version Badge](https://img.shields.io/github/v/release/software-mansion/live-debugger?color=lawn-green)](https://hexdocs.pm/live_debugger)
6+
[![Hex.pm Downloads](https://img.shields.io/hexpm/dw/live_debugger?style=flat&label=downloads&color=blue)](https://hex.pm/packages/live_debugger)
7+
[![GitHub License](https://img.shields.io/github/license/software-mansion/live-debugger)](https://github.com/software-mansion/live-debugger/blob/main/LICENSE)
88

99
</div>
1010

lib/live_debugger_web/components.ex

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,43 @@ defmodule LiveDebuggerWeb.Components do
7272
"""
7373
end
7474

75+
@doc """
76+
Renders an input with label.
77+
"""
78+
attr(:field, Phoenix.HTML.FormField, required: true)
79+
attr(:label_text, :string, default: nil)
80+
attr(:type, :string, default: "text")
81+
82+
attr(:wrapper_class, :any, default: nil)
83+
attr(:input_class, :any, default: nil)
84+
attr(:label_class, :any, default: nil)
85+
attr(:rest, :global, include: ~w(min max))
86+
87+
slot(:label)
88+
89+
def input(assigns) do
90+
~H"""
91+
<div phx-feedback-for={@field.name} class={["" | List.wrap(@wrapper_class)]}>
92+
<label for={@field.id} class={["block font-medium text-xs" | List.wrap(@label_class)]}>
93+
<%= if @label != [], do: render_slot(@label), else: @label_text %>
94+
</label>
95+
<input
96+
type={@type}
97+
name={@field.name}
98+
id={@field.id}
99+
value={Phoenix.HTML.Form.normalize_value(@type, @field.value)}
100+
class={[
101+
"mt-2 block w-full rounded-lg bg-surface-1-bg focus:ring-0 text-xs",
102+
"phx-no-feedback:border-zinc-300 phx-no-feedback:focus:border-zinc-400",
103+
"border-default-border focus:border-secondary-text"
104+
| List.wrap(@input_class)
105+
]}
106+
{@rest}
107+
/>
108+
</div>
109+
"""
110+
end
111+
75112
@doc """
76113
Renders a button.
77114

lib/live_debugger_web/helpers/tracing_helper.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ defmodule LiveDebuggerWeb.Helpers.TracingHelper do
138138
lv_process = socket.assigns.lv_process
139139
node_id = socket.assigns.node_id
140140

141-
socket.assigns.current_filters
141+
socket.assigns.current_filters.functions
142142
|> Enum.filter(fn {_, active?} -> active? end)
143143
|> Enum.flat_map(fn {function, _} ->
144144
[
@@ -164,7 +164,7 @@ defmodule LiveDebuggerWeb.Helpers.TracingHelper do
164164
lv_process = socket.assigns.lv_process
165165
node_id = socket.assigns.node_id
166166

167-
socket.assigns.current_filters
167+
socket.assigns.current_filters.functions
168168
|> Enum.map(fn {function, _} ->
169169
PubSubUtils.tsnf_topic(
170170
lv_process.socket_id,

lib/live_debugger_web/live/traces_live.ex

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,8 @@ defmodule LiveDebuggerWeb.TracesLive do
263263
default_filters = default_filters(node_id)
264264

265265
socket
266-
|> assign(node_id: node_id)
267266
|> TracingHelper.disable_tracing()
267+
|> assign(node_id: node_id)
268268
|> assign(current_filters: default_filters)
269269
|> assign(default_filters: default_filters)
270270
|> assign_async_existing_traces()
@@ -400,17 +400,26 @@ defmodule LiveDebuggerWeb.TracesLive do
400400
end
401401

402402
defp default_filters(node_id) do
403-
node_id
404-
|> TreeNode.type()
405-
|> case do
406-
:live_view -> UtilsCallbacks.live_view_callbacks()
407-
:live_component -> UtilsCallbacks.live_component_callbacks()
408-
end
409-
|> Enum.map(fn {function, _} -> {function, true} end)
403+
functions =
404+
node_id
405+
|> TreeNode.type()
406+
|> case do
407+
:live_view -> UtilsCallbacks.live_view_callbacks()
408+
:live_component -> UtilsCallbacks.live_component_callbacks()
409+
end
410+
|> Enum.map(fn {function, _} -> {function, true} end)
411+
412+
%{
413+
functions: functions,
414+
execution_time: [
415+
{:exec_time_max, ""},
416+
{:exec_time_min, "0"}
417+
]
418+
}
410419
end
411420

412421
defp get_active_functions(socket) do
413-
socket.assigns.current_filters
422+
socket.assigns.current_filters.functions
414423
|> Enum.filter(fn {_, active?} -> active? end)
415424
|> Enum.map(fn {function, _} -> function end)
416425
end

lib/live_debugger_web/live_components/filters_form.ex

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ defmodule LiveDebuggerWeb.LiveComponents.FiltersForm do
2121

2222
@impl true
2323
def render(assigns) do
24-
assigns = assign(assigns, :selected_filters_number, calculate_selected_filters(assigns.form))
24+
assigns =
25+
assign(assigns, :selected_filters_number, calculate_selected_filters(assigns.form))
2526

2627
~H"""
2728
<div id={@id <> "-wrapper"}>
@@ -34,6 +35,15 @@ defmodule LiveDebuggerWeb.LiveComponents.FiltersForm do
3435
<.checkbox field={@form[function]} label={"#{function}/#{arity}"} />
3536
<% end %>
3637
</div>
38+
<p class="font-medium mb-4 mt-6">Callback execution time</p>
39+
<div class="flex flex-col gap-3">
40+
<.input field={@form[:exec_time_max]} type="number" min="0">
41+
<:label>max [&micro;s]</:label>
42+
</.input>
43+
<.input field={@form[:exec_time_min]} type="number" min="0">
44+
<:label>min [&micro;s]</:label>
45+
</.input>
46+
</div>
3747
</div>
3848
<div class="flex py-3 px-4 border-t border-default-border items-center justify-between">
3949
<button
@@ -82,11 +92,11 @@ defmodule LiveDebuggerWeb.LiveComponents.FiltersForm do
8292
|> noreply()
8393
end
8494

85-
def assign_form(socket, filters) do
95+
def assign_form(socket, %{functions: functions, execution_time: execution_time}) do
8696
form =
87-
filters
88-
|> Enum.reduce(%{}, fn {function, active}, acc ->
89-
Map.put(acc, Atom.to_string(function), active)
97+
(functions ++ execution_time)
98+
|> Enum.reduce(%{}, fn {filter, value}, acc ->
99+
Map.put(acc, Atom.to_string(filter), value)
90100
end)
91101
|> to_form()
92102

@@ -103,15 +113,28 @@ defmodule LiveDebuggerWeb.LiveComponents.FiltersForm do
103113
end
104114

105115
defp update_filters(active_filters, params) do
106-
active_filters
107-
|> Enum.map(fn {function, _} ->
108-
{function, Map.has_key?(params, Atom.to_string(function))}
109-
end)
116+
functions =
117+
active_filters.functions
118+
|> Enum.map(fn {function, _} ->
119+
{function, Map.has_key?(params, Atom.to_string(function))}
120+
end)
121+
122+
execution_time =
123+
active_filters.execution_time
124+
|> Enum.map(fn {filter, value} ->
125+
{filter, Map.get(params, Atom.to_string(filter), value)}
126+
end)
127+
128+
%{functions: functions, execution_time: execution_time}
110129
end
111130

112131
defp calculate_selected_filters(form) do
132+
callbacks =
133+
UtilsCallbacks.callbacks_functions()
134+
|> Enum.map(&Atom.to_string/1)
135+
113136
form.params
114-
|> Map.values()
137+
|> Enum.filter(fn {name, value} -> Enum.member?(callbacks, name) && value end)
115138
|> Enum.count(&Function.identity/1)
116139
end
117140
end

lib/live_debugger_web/plugs/allow_iframe.ex

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ defmodule LiveDebuggerWeb.Plugs.AllowIframe do
99

1010
@spec call(Plug.Conn.t(), any) :: Plug.Conn.t()
1111
def call(conn, _opts) do
12-
delete_resp_header(conn, "x-frame-options")
12+
conn
13+
|> delete_resp_header("x-frame-options")
14+
|> delete_resp_header("content-security-policy")
1315
end
1416
end

0 commit comments

Comments
 (0)