-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ENHC0010037] Member search component (#668)
* starting to create a new member search component * adding search component to project members table page * adding member search component tests * making the member search component usable for group links * moving the search component out of the members folder * adding a preview for search component * resolving a warning with filters controller * removing rendering the component within a turbo frame * making tab optional * adding the search component to the tabs component * renaming turbo_frame_tag
- Loading branch information
Showing
12 changed files
with
115 additions
and
60 deletions.
There are no files selected for viewing
This file contains 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,20 @@ | ||
<%= search_form_for @q, url: @url, html: {"data-controller": "filters"} do |f| %> | ||
<input type="hidden" name="format" value="turbo_stream"/> | ||
<input type="hidden" name="tab" value="<%=@tab%>"/> | ||
<%= f.label @search_attribute, @placeholder, class: "sr-only" %> | ||
<div class="relative lg:w-72"> | ||
<div | ||
class=" | ||
absolute inset-y-0 left-0 flex items-center pl-3 pointer-events-none | ||
" | ||
> | ||
<%= viral_icon(name: "magnifying_glass", classes: "h-5 w-5") %> | ||
</div> | ||
<%= helpers.turbo_frame_tag "ransack_hidden_values" %> | ||
<%= f.search_field @search_attribute, | ||
"data-action": "filters#submit", | ||
class: | ||
"block w-full p-2.5 pl-10 text-sm text-slate-900 border border-slate-300 rounded-lg bg-slate-50 focus:ring-primary-500 focus:border-primary-500 dark:bg-slate-700 dark:border-slate-600 dark:placeholder-slate-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500", | ||
placeholder: @placeholder %> | ||
</div> | ||
<% end %> |
This file contains 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,16 @@ | ||
# frozen_string_literal: true | ||
|
||
# Component for rendering the search box | ||
class SearchComponent < Component | ||
include Ransack::Helpers::FormHelper | ||
|
||
# rubocop:disable Naming/MethodParameterName | ||
def initialize(q:, url:, search_attribute:, placeholder:, tab: '') | ||
@q = q | ||
@url = url | ||
@search_attribute = search_attribute | ||
@placeholder = placeholder | ||
@tab = tab | ||
end | ||
# rubocop:enable Naming/MethodParameterName | ||
end |
This file contains 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 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 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 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 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 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 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 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,36 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'test_helper' | ||
|
||
class SearchComponentTest < ViewComponent::TestCase | ||
test 'Should render a searchbox' do | ||
url = '/-/groups/group-1/-/members' | ||
search_attribute = :user_email_cont | ||
placeholder = 'a placeholder' | ||
|
||
render_inline SearchComponent.new(q: Member.ransack, url:, search_attribute:, | ||
placeholder:) | ||
|
||
assert_selector "input[type='hidden'][name='tab'][value='']", visible: false, count: 1 | ||
assert_selector "form[action='#{url}']", count: 1 | ||
assert_selector "label[for='q_#{search_attribute}']", count: 1 | ||
assert_selector "input[id='q_#{search_attribute}']", count: 1 | ||
assert_text placeholder | ||
end | ||
|
||
test 'Should render a searchbox with a tab' do | ||
url = '/-/groups/group-1/-/members' | ||
search_attribute = :user_email_cont | ||
placeholder = 'a placeholder' | ||
tab = 'invited_groups' | ||
|
||
render_inline SearchComponent.new(q: Member.ransack, url:, search_attribute:, | ||
placeholder:, tab:) | ||
|
||
assert_selector "input[type='hidden'][name='tab'][value='#{tab}']", visible: false, count: 1 | ||
assert_selector "form[action='#{url}']", count: 1 | ||
assert_selector "label[for='q_#{search_attribute}']", count: 1 | ||
assert_selector "input[id='q_#{search_attribute}']", count: 1 | ||
assert_text placeholder | ||
end | ||
end |
This file contains 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,9 @@ | ||
# frozen_string_literal: true | ||
|
||
class SearchComponentPreview < ViewComponent::Preview | ||
def default | ||
render_with_template(locals: { | ||
url: group_members_url(Group.first) | ||
}) | ||
end | ||
end |
6 changes: 6 additions & 0 deletions
6
test/components/previews/search_component_preview/default.html.erb
This file contains 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,6 @@ | ||
<%= render SearchComponent.new( | ||
Member.ransack, | ||
url, | ||
:user_email_cont, | ||
"a placeholder", | ||
) %> |