Add Entity search to Unified Dashboard Header
See original GitHub issueFeature Description
The “Entity Search” should be added to the Unified Dashboard Header, implemented in #4048.
Not expanded:

Expanded:

Expanded with search results:

Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
- These features should all be implemented behind the
unifiedDashboard
feature flag. - A new component for the Entity Search Input can be created in
assets/js/components/EntitySearchInput
. - The Entity Search Input implemented in the header should behave similarly to the existing
URLSearchWidget
’sPostSearcherAutoSuggest
—that component can likely serve as the basis for this component. Key difference between that component and this new one are:- Styling as per the Figma files for both desktop and mobile views:
- The desktop Figma file is here: https://www.figma.com/file/kKYqiUL7Fj3yAF8HHBRUhz/Custom-Dashboard?node-id=1944%3A17087 (under the “Single Search: Full frames” section).
- The mobile versions are available here: https://www.figma.com/file/VILRieNSLg2DOVyEgFBkXe/[MVP]-Generic-Dashboard?node-id=382%3A1699
- There are no dedicated tablet styles, so the mobile styles should be used for tablet sizes, essentially until all header content can fit alongside the input (as seen in the Desktop styles).
- A “Loading” state should be added to this component featuring preview blocks, instead of the current behaviour when shows “No results” when first searching, and then later shows the previous results while searching. It’s clear that whatever the past results were are being shown in the search results; they should be cleared when the input changes in this new widget and “No results” should only be shown once the result is complete and empty. Essentially, where it currently says “No results” in this screencast, should be preview/loading lines instead.
- There should be no “View data” submit button like in the
URLSearchWidget
. Instead, clicking on an item in the search results should navigate to the Entity Dashboard immediately.- Before this navigation occurs, the GA event
open_urldetails
(currently also exists in the widget) should be triggered. The event category for this new event should be “${viewContext}_headerbar” (using the current view context for theviewContext
placeholder). The code to create this event would be:
- Before this navigation occurs, the GA event
- Styling as per the Figma files for both desktop and mobile views:
const viewContext = useContext( ViewContextContext );
trackEvent( `${ viewContext }_headerbar`, 'open_urldetails' );
Implementation Brief
- Using
assets/js/components/PostSearcherAutoSuggest.js
,- Add 3 new props:
placeholder
: empty string by default, used to display placeholder text for the input.setIsLoading
: optional function. This should be provided from the parent component to set a loading flag.onKeyDown
: optional function for keyboard events for the input.
- In the
useEffect
hook which calls the API passing ondebouncedValue
, callsetIsLoading
if defined, withtrue
. When we have a response, then setsetIsLoading
tofalse
. - Using
useEffect
, check ifsearchTerm
is empty to clear the results, by settingsetResults
to[]
. This is to clear previous search results when the user starts typing a new term. - Add
placeholder
andonKeyDown
props to theComboboxInput
, and calling the namesake props if they are defined. - Using the
useFeature
hook, passingunifiedDashboard
as parameter, displayComboboxOption
renderingnoResultsMessage
only if they flag is not enabled. This means that current functionality will remain the same, but for the unified dashboard, it will not be displayed. Instead the loading state will be displayed in the parent component.
- Add 3 new props:
- Create
assets/js/components/EntitySearchInput.js
which exports theEntitySearchInput
functional component.EntitySearchInput
uses most of the code fromassets/js/googlesitekit/widgets/components/URLSearchWidget.js
with the following changes:- Remove the
Widget
component,Title or URL
label and allmdc-layout-*
markup. - Primarily the
PostSearcherAutoSuggest
andButton
will be used. - The class name for the main parent container should be
googlesitekit-entity-search
instead ofgooglesitekit-post-searcher
.
- Remove the
- Add 2 new state variables:
isOpen
:boolean
withfalse
as default value.isLoading
:boolean
withfalse
as default value.
- Using the
useEffect
hook, withmatch
as dependency, check if there’s a permalink to navigate the user to the details URL and track the necessary event. It’s the same logic used in theonClick
function. - For the tracking, refer to the AC for the new event category to be used.
- Update the
onClick
callback function to toggleisOpen
. - Update the
Button
component used:- Add the
trailingIcon
prop to render the appropriate icon using the following logic:- If
isOpen
istrue
, display theclose
icon. Refer to the mobile designs in Figma which contains the close icon, compared to the desktop one where the incorrect icon is displayed when the search is in the expanded state. - If
isOpen
isfalse
, then display the search icon. - The icon SVGs should be placed in
assets/svg/
.
- If
- The label should be
URL Search
. The latter should be visible only whenisOpen
istrue
, meaning when the input is displayed, only the icon is displayed and the label is hidden.
- Add the
- Update
PostSearcherAutoSuggest
to:- add the
placeholder
prop, passingEnter title or URL…
as value. - set the
setCanSubmit
to an anonymous function which does nothing. - add the
setIsLoading
prop, passing the function to change theisLoading
state variable. - update the
id
prop toentity-urlsearch-autocomplete
. - add the
onKeyDown
prop which the callback function will check if theESCAPE
key (imported from@wordpress/keycodes
) has been pressed andisOpen
istrue
to setisOpen
tofalse
.
- add the
PostSearcherAutoSuggest
should be visible only whenisLoading
isfalse
.- If
isLoading
istrue
, then render theProgressBar
component, withsmall
andcompress
as props within thegooglesitekit-entity-search
container. - Using the
useRef
hook, attach a ref to thegooglesitekit-entity-search
container. - Using the
useEffect
hook, listen whenisOpen
changes. IfisOpen
istrue
, set the focus to the input text, else set the focus to thebutton
. This means when the user clicks on button to display the input text, the focus is already set on the input for the user to start typing. - The
googlesitekit-entity-search--is-open
class name is added to the parent container rendering the markup whenisOpen
istrue
.
- Create
assets/js/components/EntitySearchInput.stories.js
which contains the story forEntitySearchInput
. - Create
assets/sass/components/entity-search/_googlesitekit-entity-search.scss
which will contain the styles forEntitySearchInput
as per the designs in Figma.- When the search is in expanded state, i.e
isOpen
istrue
and thus having thegooglesitekit-entity-search--is-open
class name, set the button to useposition: absolute
so that the button is now displayed within the input. - The
ProgressBar
component should be absolutely positioned within the input text, below the close icon, having the same width as the icon. Refer to this comment for an example: https://github.com/google/site-kit-wp/issues/4049#issuecomment-935725206
- When the search is in expanded state, i.e
UPDATE: when working on the new entity search component, add the event tracking defined in for the URLSearchWidget
component.
Test Coverage
- No new tests to be added.
QA Brief
- The Entity Search component in the Unified Dashboard should look and behave as per AC/IB.
- Should work on all screen sizes.
- Some design elements are incorrect in the Screenshot/Figma, see discussion below.
- Desktop View shows
search
icon instead ofclose
icon when search is expended/open. - See comment for the loaders’ appearance hint (not available on Figma).
- Desktop View shows
- Check for Keyboard navigation that was added in the Code Review Phase.
- Press
ESC
to close the expended search. - Press
Up
/Down
to to select result from the list. Should have visual feedback.- Pressing
Enter
should navigate to the selected entity page.
- Pressing
- Pressing
Enter
when the search term is a (case insensitive) match should result in navigating to the entity page. If it’s not ma match, pressingEnter
should do nothing.
- Press
- The appropriate tracking even should be sent to GA on navigating to an entity page. (Use Google Analytics Debugger to verify this).
Changelog entry
- Add Entity search to Unified Dashboard Header
Issue Analytics
- State:
- Created 2 years ago
- Comments:20 (3 by maintainers)
Top Results From Across the Web
Add entity context component to render in the header's “extra ...
The component should be displayed in the "sub-header" container from Add a content area to the Header in the Unified Dashboard for Entity...
Read more >Customize interactive dashboards that are based on Unified ...
Go to Settings > Customizations. · Select Customize the System. · Under Components, expand Entities and select the entity you want. · In...
Read more >Configuring search in Next Experience
Administrators can customize Next Experience search settings. Add new searchable tables, modify the fields displayed for search results from ...
Read more >Adding and editing user-defined dashboard filters | Looker
Understand how to create and edit dashboard filters. ... Explores pre-populated in the Add Filter window appear below the Filter by search.
Read more >Cisco Unified Contact Center Enterprise Reporting User ...
Displays an existing report on the Dashboard. Click the Report View icon. In the Add Report View dialog box, select the Report and...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@wpdarren Creating a new issue to review the loading indicator placement sounds good to me. Let’s focus on your QA feedback points 1.-3. in this issue here as @tofumatt mentioned.
I definitely prefer the subtle loading indicator (option 1), especially for mobile screens where the autocomplete will really dominate the whole screen. I think it’s visible enough and it’s fine that it’s subtle. Let’s go with that option where it’s below the icon, I think that’s really slick. 👍🏻