-
Notifications
You must be signed in to change notification settings - Fork 20
Enhancement: Search in assigns #755
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
d16b109
add search in assigns
srzeszut fae496a
Update components.ex
srzeszut dd088db
Update assigns_body_search_highlight.js
srzeszut 8e7bf24
Update assigns_body_search_highlight.js
srzeszut 255d7e8
Update assigns_search.ex
srzeszut 9ac334e
Update components.ex
srzeszut 095bd77
add search to fullscreen mode
srzeszut 524af47
Add assigns search test
srzeszut f737320
Update assigns_search_highlight_test.exs
srzeszut 588d1a6
update assets
srzeszut 9a73c96
add debounce to input
srzeszut cca017d
add id to input and add test for fullscreen
srzeszut 4b815e3
fix assigns highlighting
srzeszut aaa54cb
Update components.ex
srzeszut a37f906
refactor
srzeszut 60427d2
move create search_bar component
srzeszut 7edf4f7
Update assigns_body_search_highlight.js
srzeszut 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import { findRanges } from '../utils/dom'; | ||
|
|
||
| function highlightSearchRanges(allRanges) { | ||
| if (allRanges.length === 0) { | ||
| CSS.highlights.clear(); | ||
| return; | ||
| } | ||
|
|
||
| const highlight = new Highlight(...allRanges); | ||
| CSS.highlights.set('search-highlight', highlight); | ||
| } | ||
|
|
||
| function handleHighlight(phrase) { | ||
| if (phrase === undefined || phrase === '') { | ||
| CSS.highlights.clear(); | ||
| return; | ||
| } | ||
|
|
||
| const allRanges = []; | ||
| const assignsFullscreenContainer = document.getElementById( | ||
| 'assigns-display-fullscreen-container' | ||
| ); | ||
| const assignsContainer = document.getElementById('assigns-display-container'); | ||
|
|
||
| [assignsContainer, assignsFullscreenContainer].forEach((el) => { | ||
| if (el && el.dataset.search_phrase === phrase) { | ||
| const ranges = findRanges(el, phrase); | ||
| allRanges.push(...ranges); | ||
| } | ||
| }); | ||
|
|
||
| highlightSearchRanges(allRanges); | ||
| } | ||
|
|
||
| const AssignsBodySearchHighlight = { | ||
| mounted() { | ||
| this.handleEvent('search_in_assigns', ({ search_phrase }) => { | ||
| handleHighlight(search_phrase); | ||
| }); | ||
| }, | ||
| }; | ||
|
|
||
| export default AssignsBodySearchHighlight; |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| defmodule LiveDebugger.App.Debugger.Components do | ||
| @moduledoc """ | ||
| UI components used in the Debugger | ||
| """ | ||
| use LiveDebugger.App.Web, :component | ||
|
|
||
| attr(:placeholder, :string, default: "Search...") | ||
| attr(:disabled?, :boolean, default: false) | ||
| attr(:search_phrase, :string, default: "", doc: "The current search query") | ||
| attr(:input_id, :string, default: "", doc: "The ID of the input element") | ||
| attr(:debounce, :integer, default: 250, doc: "The debounce time in milliseconds") | ||
| attr(:class, :string, default: "", doc: "Additional CSS classes for the input element") | ||
|
|
||
| def search_bar(assigns) do | ||
| ~H""" | ||
| <div class={[ | ||
| "flex shrink items-center rounded-[7px] outline outline-1 -outline-offset-1", | ||
| "has-[input:focus-within]:outline-2 has-[input:focus-within]:-outline-offset-2", | ||
| "outline-default-border has-[input:focus-within]:outline-ui-accent", | ||
| @class | ||
| ]}> | ||
| <form phx-change="search" phx-submit="search-submit" class="flex items-center w-full h-full"> | ||
| <.icon | ||
| name="icon-search" | ||
| class={[ | ||
| "h-4 w-4 ml-3", | ||
| (@disabled? && "text-gray-400") || "text-primary-icon" | ||
| ]} | ||
| /> | ||
| <input | ||
| id={@input_id} | ||
| disabled={@disabled?} | ||
| placeholder={@placeholder} | ||
| value={@search_phrase} | ||
| phx-debounce={@debounce} | ||
| type="text" | ||
| name="search_phrase" | ||
| class="block remove-arrow w-16 sm:w-64 min-w-32 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 disabled:!text-gray-500 disabled:placeholder-gray-300" | ||
| /> | ||
| </form> | ||
| </div> | ||
| """ | ||
| 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
48 changes: 48 additions & 0 deletions
48
lib/live_debugger/app/debugger/node_state/web/hook_components/assigns_search.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,48 @@ | ||
| defmodule LiveDebugger.App.Debugger.NodeState.Web.AssignsSearch do | ||
srzeszut marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| @moduledoc """ | ||
| This component is used to add search functionality for assigns. | ||
| It produces `search` and `search-submit` events handled by hook added via `init/1`. | ||
| """ | ||
|
|
||
| use LiveDebugger.App.Web, :hook_component | ||
|
|
||
| alias LiveDebugger.App.Debugger.Components | ||
|
|
||
| @required_assigns [:assigns_search_phrase] | ||
|
|
||
| @impl true | ||
| def init(socket) do | ||
| socket | ||
| |> check_assigns!(@required_assigns) | ||
| |> attach_hook(:search_input, :handle_event, &handle_event/3) | ||
| |> register_hook(:search_input) | ||
| end | ||
|
|
||
| attr(:placeholder, :string, default: "Search...") | ||
| attr(:disabled?, :boolean, default: false) | ||
| attr(:assigns_search_phrase, :string, default: "", doc: "The current search query for assigns") | ||
| attr(:input_id, :string, default: "", doc: "The ID of the input element") | ||
|
|
||
| @impl true | ||
| def render(assigns) do | ||
| ~H""" | ||
| <Components.search_bar | ||
| placeholder={@placeholder} | ||
| search_phrase={@assigns_search_phrase} | ||
| input_id={@input_id} | ||
| debounce={250} | ||
| class="h-7!" | ||
| /> | ||
| """ | ||
| end | ||
|
|
||
| defp handle_event("search", %{"search_phrase" => search_phrase}, socket) do | ||
| socket | ||
| |> assign(assigns_search_phrase: search_phrase) | ||
| |> push_event("search_in_assigns", %{search_phrase: search_phrase}) | ||
| |> halt() | ||
| end | ||
|
|
||
| defp handle_event("search-submit", _params, socket), do: {:halt, socket} | ||
| defp handle_event(_, _, socket), do: {:cont, socket} | ||
| end | ||
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.