-
Notifications
You must be signed in to change notification settings - Fork 20
Enhancement: applied new designs to filters form #488
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
4c104fe
Filters working in a rough way
kraleppa b716154
Fixed applied filters number
kraleppa 0b3eb69
Improved styling of form
kraleppa 3e678ed
Removed unused function
kraleppa f2585be
Fixed errors
kraleppa 1c207ae
Added filters headers
kraleppa 8f4b6ca
Reset group button added
kraleppa ff2ba65
Reset button added
kraleppa 5e96583
Fixed split button
kraleppa f420a54
Fixed tests
kraleppa c015532
Added test
kraleppa 6eaa079
Fixed test
kraleppa bcf94d3
Deleted filters dropdown
kraleppa bcc3e75
Deleted `nth-child`
kraleppa 9a6b75c
Made functions private
kraleppa 3eeaa13
Removed obsolete argument in `assign_form`
kraleppa 2404392
Resetting form
kraleppa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 0 additions & 67 deletions
67
lib/live_debugger_web/live/traces/components/filters_dropdown.ex
This file was deleted.
Oops, something went wrong.
130 changes: 130 additions & 0 deletions
130
lib/live_debugger_web/live/traces/components/filters_fullscreen.ex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| defmodule LiveDebuggerWeb.Live.Traces.Components.FiltersFullscreen do | ||
| @moduledoc """ | ||
| Set of components that are used to display the filters in a fullscreen. | ||
| """ | ||
|
|
||
| use LiveDebuggerWeb, :hook_component | ||
|
|
||
| alias LiveDebuggerWeb.Live.Traces.Hooks.ExistingTraces | ||
|
|
||
| @required_assigns [:node_id, :current_filters, :default_filters] | ||
|
|
||
| @doc """ | ||
| Initializes the component by checking the assigns and streams and attaching the hook to the socket. | ||
| The hook is used to handle the `filters_updated` event. | ||
| """ | ||
| @spec init(Phoenix.LiveView.Socket.t()) :: Phoenix.LiveView.Socket.t() | ||
| def init(socket) do | ||
| socket | ||
| |> check_hook!(:existing_traces) | ||
| |> check_assigns!(@required_assigns) | ||
| |> attach_hook(:filters, :handle_info, &handle_info/2) | ||
| |> attach_hook(:filters, :handle_event, &handle_event/3) | ||
| |> register_hook(:filters) | ||
| end | ||
|
|
||
| attr(:node_id, :map, required: true) | ||
| attr(:current_filters, :map, required: true) | ||
| attr(:default_filters, :map, required: true) | ||
|
|
||
| @doc """ | ||
| Renders the filters fullscreen component. | ||
| It produces the `filters_updated` event that can be handled by the hook provided in the `init/1` function. | ||
| """ | ||
| def filters_fullscreen(assigns) do | ||
| ~H""" | ||
| <.fullscreen id="filters-fullscreen" title="Filters" class="max-w-112 min-w-[20rem]"> | ||
| <.live_component | ||
| module={LiveDebuggerWeb.LiveComponents.FiltersForm} | ||
| id="filters-fullscreen-form" | ||
| node_id={@node_id} | ||
| filters={@current_filters} | ||
| default_filters={@default_filters} | ||
| /> | ||
| </.fullscreen> | ||
| """ | ||
| end | ||
|
|
||
| @doc """ | ||
| Renders the filters button. | ||
| It produces the `open-filters` and `reset-filters` events that can be handled by the hook provided in the `init/1` function. | ||
| """ | ||
|
|
||
| attr(:current_filters, :map, required: true) | ||
| attr(:default_filters, :map, required: true) | ||
| attr(:label_class, :string, default: "") | ||
|
|
||
| def filters_button(assigns) do | ||
| filters_number = calculate_selected_filters(assigns.current_filters, assigns.default_filters) | ||
| assigns = assign(assigns, :applied_filters_number, filters_number) | ||
|
|
||
| ~H""" | ||
| <div class="flex"> | ||
| <.button | ||
| variant="secondary" | ||
| size="sm" | ||
| class={["flex gap-1", if(@applied_filters_number > 0, do: "rounded-r-none")]} | ||
| phx-click="open-filters" | ||
| > | ||
| <.icon name="icon-filters" class="w-4 h-4" /> | ||
| <span class={["ml-1", @label_class]}>Filters</span> | ||
| <span :if={@applied_filters_number > 0}> | ||
| (<%= @applied_filters_number %>) | ||
| </span> | ||
| </.button> | ||
| <.icon_button | ||
| :if={@applied_filters_number > 0} | ||
| icon="icon-cross" | ||
| variant="secondary" | ||
| phx-click="reset-filters" | ||
| class="rounded-l-none border-l-0 h-[30px]! w-[30px]!" | ||
| /> | ||
| </div> | ||
| """ | ||
| end | ||
|
|
||
| defp handle_info({:filters_updated, filters}, socket) do | ||
| socket | ||
| |> assign(:current_filters, filters) | ||
| |> assign(:traces_empty?, true) | ||
| |> push_event("filters-fullscreen-close", %{}) | ||
| |> ExistingTraces.assign_async_existing_traces() | ||
| |> halt() | ||
| end | ||
|
|
||
| defp handle_info(_, socket), do: {:cont, socket} | ||
|
|
||
| defp handle_event("open-filters", _, socket) do | ||
| send_update(LiveDebuggerWeb.LiveComponents.FiltersForm, | ||
| id: "filters-fullscreen-form", | ||
| reset_form?: true | ||
| ) | ||
|
|
||
| socket | ||
| |> push_event("filters-fullscreen-open", %{}) | ||
| |> halt() | ||
| end | ||
|
|
||
| defp handle_event("reset-filters", _, socket) do | ||
| socket | ||
| |> assign(:current_filters, socket.assigns.default_filters) | ||
| |> ExistingTraces.assign_async_existing_traces() | ||
| |> halt() | ||
| end | ||
|
|
||
| defp handle_event(_, _, socket), do: {:cont, socket} | ||
|
|
||
| defp calculate_selected_filters(current_filters, default_filters) do | ||
| flat_current_filters = | ||
| current_filters | ||
| |> Enum.flat_map(fn {_key, value} -> value end) | ||
| |> Enum.reject(fn {key, _val} -> key in [:min_unit, :max_unit] end) | ||
|
|
||
| flat_default_filters = | ||
| default_filters | ||
| |> Enum.flat_map(fn {_key, value} -> value end) | ||
| |> Enum.reject(fn {key, _val} -> key in [:min_unit, :max_unit] end) | ||
|
|
||
| Enum.count(flat_current_filters, fn {key, value} -> value != flat_default_filters[key] end) | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.