@@ -7,6 +7,7 @@ defmodule LiveDebuggerWeb.LiveComponents.FiltersForm do
77
88 alias LiveDebugger.Utils.Callbacks , as: UtilsCallbacks
99 alias LiveDebugger.Structs.TreeNode
10+ alias LiveDebugger.Utils.Parsers
1011
1112 @ impl true
1213 def update ( assigns , socket ) do
@@ -39,16 +40,18 @@ defmodule LiveDebuggerWeb.LiveComponents.FiltersForm do
3940 </ div >
4041 < p class = "font-medium mb-4 mt-6 " > Execution Time</ p >
4142 < div class = "mt-3 flex gap-3 items-center " >
42- < . time_input
43+ < . input_with_units
4344 value_field = { @ form [ :exec_time_min ] }
4445 unit_field = { @ form [ :min_unit ] }
46+ units = { Parsers . time_units ( ) }
4547 min = "0 "
4648 placeholder = "min "
4749 /> -
48- < . time_input
50+ < . input_with_units
4951 value_field = { @ form [ :exec_time_max ] }
5052 unit_field = { @ form [ :max_unit ] }
5153 min = "0 "
54+ units = { Parsers . time_units ( ) }
5255 placeholder = "max "
5356 />
5457 </ div >
@@ -78,44 +81,6 @@ defmodule LiveDebuggerWeb.LiveComponents.FiltersForm do
7881 """
7982 end
8083
81- attr ( :value_field , Phoenix.HTML.FormField , required: true )
82- attr ( :unit_field , Phoenix.HTML.FormField , required: true )
83- attr ( :rest , :global , include: ~w( min max placeholder) )
84-
85- defp time_input ( assigns ) do
86- assigns =
87- assigns
88- |> assign ( :errors , assigns . value_field . errors )
89-
90- ~H"""
91- < div class = "shadow-sm " >
92- < div class = { [
93- "flex items-center rounded-[4px] outline outline-1 -outline-offset-1 has-[input:focus-within]:outline has-[input:focus-within]:outline-2 has-[input:focus-within]:-outline-offset-2" ,
94- @ errors == [ ] && "outline-default-border has-[input:focus-within]:outline-ui-accent" ,
95- @ errors != [ ] && "outline-error-text has-[input:focus-within]:outline-error-text"
96- ] } >
97- < input
98- id = { @ value_field . id }
99- name = { @ value_field . name }
100- type = "number "
101- class = "block remove-arrow max-w-20 bg-surface-0-bg border-none py-2.5 pl-2 pr-3 text-xs text-primary-text placeholder:text-ui-muted focus:ring-0 "
102- value = { Phoenix.HTML.Form . normalize_value ( "number" , @ value_field . value ) }
103- { @ rest }
104- />
105- < div class = "grid shrink-0 grid-cols-1 focus-within:relative " >
106- < select
107- id = { @ unit_field . id }
108- name = { @ unit_field . name }
109- class = "border-none bg-surface-0-bg col-start-1 row-start-1 w-full appearance-none rounded-md py-1.5 pl-3 pr-7 text-xs text-secondary-text placeholder:text-gray-400 focus:outline focus:outline-2 focus:-outline-offset-2 focus:outline-ui-accent "
110- >
111- <%= Phoenix.HTML.Form . options_for_select ( [ "µs" , "ms" , "s" ] , @ unit_field . value ) %>
112- </ select >
113- </ div >
114- </ div >
115- </ div >
116- """
117- end
118-
11984 @ impl true
12085 def handle_event ( "submit" , params , socket ) do
12186 case update_filters ( socket . assigns . active_filters , params ) do
@@ -205,9 +170,10 @@ defmodule LiveDebuggerWeb.LiveComponents.FiltersForm do
205170 end
206171 end
207172
208- defp apply_unit_factor ( value , "µs" ) , do: String . to_integer ( value )
209- defp apply_unit_factor ( value , "ms" ) , do: String . to_integer ( value ) * 1000
210- defp apply_unit_factor ( value , "s" ) , do: String . to_integer ( value ) * 1_000_000
173+ defp apply_unit_factor ( value , unit ) do
174+ String . to_integer ( value )
175+ |> Parsers . time_to_microseconds ( unit )
176+ end
211177
212178 defp calculate_selected_filters ( form ) do
213179 callbacks =
0 commit comments