-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add tooltip to search #2758
base: main
Are you sure you want to change the base?
Add tooltip to search #2758
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,3 +61,15 @@ button, | |
.button--nav { | ||
margin-bottom: $base-spacing; | ||
} | ||
|
||
.button--tooltip { | ||
background: none; | ||
border: none; | ||
color: inherit; | ||
cursor: pointer; | ||
padding: 0; | ||
|
||
&:hover { | ||
background-color: unset !important; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The linter doesn't like |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,3 +44,38 @@ $search-icon-size: 1rem; | |
fill: $action-color; | ||
} | ||
} | ||
|
||
.search__tooltip { | ||
anchor-name: --tooltip-anchor; | ||
margin-right: 2rem; | ||
|
||
svg { | ||
fill: $grey-5; | ||
height: 24px; | ||
width: 24px; | ||
|
||
&:hover { | ||
fill: $action-color; | ||
} | ||
} | ||
} | ||
|
||
.search__tooltip-popover { | ||
left: anchor(center); | ||
margin: 1rem; | ||
position: fixed; | ||
position-anchor: --tooltip-anchor; | ||
top: anchor(bottom); | ||
transform: translateX(-50%); | ||
|
||
background-color: $blue; | ||
border-color: $blue; | ||
border-radius: $base-border-radius; | ||
color: $white; | ||
padding: 2rem; | ||
width: max-content; | ||
Comment on lines
+64
to
+76
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The first set of styles is all to do with positioning the popover, the second set (after the gap) is all to do with the visual style of the popover. The linter doesn't like the gap and the non alphabetical between them. It feels useful to separate the styles as I have. Shall I created 2 separate classes? |
||
} | ||
|
||
.search__tooltip-popover-value { | ||
opacity: 0.5; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,12 +10,14 @@ def index | |
resources = order.apply(resources) | ||
resources = paginate_resources(resources) | ||
page = Administrate::Page::Collection.new(dashboard, order: order) | ||
filters = Administrate::Search.new(scoped_resource, dashboard, search_term).valid_filters | ||
|
||
render locals: { | ||
resources: resources, | ||
search_term: search_term, | ||
page: page, | ||
show_search_bar: show_search_bar? | ||
show_search_bar: show_search_bar?, | ||
filters: filters | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want an option to disable the tooltip even if there are collection |
||
} | ||
end | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,16 @@ | |
<%= display_resource_name(page.resource_name) %> | ||
<% end %> | ||
|
||
<%# | ||
TODO: Move where this polyfill lives. Where? | ||
Also, do we want to import the polyfill js directly instead of linking to unpkg.com? | ||
%> | ||
<script type="module"> | ||
if (!("anchorName" in document.documentElement.style)) { | ||
import("https://unpkg.com/@oddbird/css-anchor-positioning"); | ||
} | ||
Comment on lines
+6
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
</script> | ||
|
||
<header class="main-content__header"> | ||
<h1 class="main-content__page-title" id="page-title"> | ||
<%= content_for(:title) %> | ||
|
@@ -15,6 +25,23 @@ | |
search_term: search_term, | ||
resource_name: display_resource_name(page.resource_name) | ||
) %> | ||
|
||
<% if filters.any? %> | ||
<button popovertarget="search-tooltip" class="button--tooltip search__tooltip"> | ||
<svg role="img"> | ||
<use xlink:href="#icon-question-mark" /> | ||
</svg> | ||
</button> | ||
|
||
<div popover id="search-tooltip" role="tooltip" class="search__tooltip-popover"> | ||
<p><strong>Use filters to refine your search</strong></p> | ||
<ul> | ||
<% filters.keys.each do |filter_key| %> | ||
<li><%= filter_key %>:<span class="search__tooltip-popover-value"><value></span></li> | ||
<% end %> | ||
</ul> | ||
</div> | ||
<% end %> | ||
<% end %> | ||
|
||
<div> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,54 @@ def have_a_search_bar | |
end | ||
end | ||
|
||
describe "search bar tooltip" do | ||
def have_a_search_tooltip | ||
have_css("button[popovertarget=search-tooltip]") | ||
end | ||
|
||
def search_tooltip_icon | ||
find("button[popovertarget=search-tooltip]") | ||
end | ||
|
||
it "is visible when the current dashboard has collection filters" do | ||
visit admin_customers_path | ||
|
||
expect(page).to have_a_search_tooltip | ||
end | ||
|
||
context "when clicked" do | ||
it "shows a popover with the available filters" do | ||
visit admin_customers_path | ||
|
||
search_tooltip_icon.click | ||
|
||
expect(page).to have_content("Use filters to refine your search") | ||
expect(page).to have_content("vip:<value>") | ||
expect(page).to have_content("kind:<value>") | ||
end | ||
end | ||
|
||
it "is hidden when the current dashboard has no collection filters" do | ||
stub_const("CustomerDashboard::COLLECTION_FILTERS", {}) | ||
|
||
visit admin_customers_path | ||
|
||
expect(page).not_to have_a_search_tooltip | ||
end | ||
|
||
it "is hidden when nothing is searchable in the current dashboard" do | ||
CustomerDashboard::ATTRIBUTE_TYPES.each do |_name, field_class| | ||
allow(field_class).to( | ||
receive(:searchable?).and_return(false) | ||
) | ||
end | ||
|
||
visit admin_customers_path | ||
|
||
expect(page).not_to have_a_search_tooltip | ||
end | ||
end | ||
|
||
scenario "admin searches for customer by email", :js do | ||
query = "[email protected]" | ||
perfect_match = create(:customer, email: "[email protected]") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure why this doesn't work after navigating to another page and back. Is it something to do with Turbo page loads?