diff --git a/packages/gatsby-theme-newrelic/src/components/GlobalSearch.js b/packages/gatsby-theme-newrelic/src/components/GlobalSearch.js index 6302c56e7..a8dd70a99 100644 --- a/packages/gatsby-theme-newrelic/src/components/GlobalSearch.js +++ b/packages/gatsby-theme-newrelic/src/components/GlobalSearch.js @@ -1,4 +1,5 @@ import React, { useEffect, useRef, useState } from 'react'; +import PropTypes from 'prop-types'; import { navigate } from '@reach/router'; import { css } from '@emotion/react'; import { useThrottle } from 'react-use'; @@ -23,6 +24,7 @@ const GlobalSearch = ({ onClose }) => { let recentQueries = []; try { recentQueries = JSON.parse(localStorage.getItem(SAVED_SEARCH_KEY) ?? '[]'); + // eslint-disable-next-line no-empty } catch (err) {} // `null` when we're just in the searchbar and nothing is selected // otherwise, `selected` is an integer. @@ -199,12 +201,23 @@ const GlobalSearch = ({ onClose }) => { ); }; +GlobalSearch.propTypes = { + onClose: PropTypes.func.isRequired, +}; + const SAVED_SEARCH_KEY = 'gatsby-theme-newrelic:saved-searches'; const saveSearch = (value) => { + value = value.trim(); const savedSearches = JSON.parse( localStorage.getItem(SAVED_SEARCH_KEY) ?? '[]' ); + const set = new Set(savedSearches); + + if (set.has(value)) { + return; + } + savedSearches.push(value); // only save the four most recent searches const updated = savedSearches.slice(-4); diff --git a/packages/gatsby-theme-newrelic/src/components/GlobalStyles/themes.js b/packages/gatsby-theme-newrelic/src/components/GlobalStyles/themes.js index e93ef27f6..0cb722403 100644 --- a/packages/gatsby-theme-newrelic/src/components/GlobalStyles/themes.js +++ b/packages/gatsby-theme-newrelic/src/components/GlobalStyles/themes.js @@ -37,6 +37,7 @@ export default css` --search-dropdown-background: #fff; --search-dropdown-border: #e7e9ea; --search-dropdown-hover: rgba(0, 0, 0, 0.06); + --search-input-border: none; input::placeholder { color: var(--primary-text-color); @@ -82,6 +83,7 @@ export default css` --search-dropdown-background: #1a2125; --search-dropdown-border: #eaecec; --search-dropdown-hover: rgba(255, 255, 255, 0.1); + --search-input-border: 1px solid #eaecec; input::placeholder { color: var(--primary-text-color); diff --git a/packages/gatsby-theme-newrelic/src/components/SearchDropdown/Results.js b/packages/gatsby-theme-newrelic/src/components/SearchDropdown/Results.js index 44508e2d3..2e54eeb6b 100644 --- a/packages/gatsby-theme-newrelic/src/components/SearchDropdown/Results.js +++ b/packages/gatsby-theme-newrelic/src/components/SearchDropdown/Results.js @@ -75,9 +75,9 @@ const Results = ({ onResultClick, onViewMore, results, selected }) => { const List = styled.ul` list-style: none; margin: 0 calc(-1 * var(--outer-padding)); - max-height: 31.5rem; + max-height: 32rem; overflow-y: scroll; - padding: 0; + padding: 0.25rem 0 0; & em { color: var(--search-dropdown-emphasis); @@ -123,13 +123,17 @@ const ViewMore = styled.button` `; export const ResultType = PropTypes.shape({ - breadcrumb: PropTypes.string.isRequired, - title: PropTypes.string.isRequired, - blurb: PropTypes.string.isRequired, + highlight: PropTypes.shape({ + body: PropTypes.string.isRequired, + title: PropTypes.string.isRequired, + }).isRequired, url: PropTypes.string.isRequired, }); Results.propTypes = { + onViewMore: PropTypes.func.isRequired, + onResultClick: PropTypes.func.isRequired, + selected: PropTypes.number, results: PropTypes.arrayOf(ResultType), }; @@ -146,7 +150,7 @@ const breadcrumbify = (str) => { const DESIRED_LENGTH = 80; str = str.replace(/\/$/, ''); - let parts = str.split('/'); + const parts = str.split('/'); let result = parts.join(' / '); if (result.length <= DESIRED_LENGTH) return result; diff --git a/packages/gatsby-theme-newrelic/src/components/SearchDropdown/SearchDropdown.js b/packages/gatsby-theme-newrelic/src/components/SearchDropdown/SearchDropdown.js index 050465817..381ce327a 100644 --- a/packages/gatsby-theme-newrelic/src/components/SearchDropdown/SearchDropdown.js +++ b/packages/gatsby-theme-newrelic/src/components/SearchDropdown/SearchDropdown.js @@ -13,7 +13,6 @@ const SearchDropdown = ({ onClose, onRecentClick, onResultClick, - query, recentQueries, results, selected, @@ -25,18 +24,22 @@ const SearchDropdown = ({ return ( <> - Recent search terms {recentQueries.length > 0 && ( - - {recentQueries.map((query, i) => ( -
  • onRecentClick(query, i)} - > - {query} -
  • - ))} -
    + <> + Recent search terms + + {recentQueries.map((query, i) => ( +
  • + onRecentClick(query, i)} + > + {query} + +
  • + ))} +
    + )} All searches @@ -44,7 +47,11 @@ const SearchDropdown = ({ {loading && !error && } {!loading && !error && ( `; +exports[`nr-arrow-down icon matches its snapshot 1`] = ` +.emotion-0 { + width: 1em; + height: 1em; +} + + + + +`; + +exports[`nr-arrow-go-to icon matches its snapshot 1`] = ` +.emotion-0 { + width: 1em; + height: 1em; +} + + + + +`; + +exports[`nr-arrow-up icon matches its snapshot 1`] = ` +.emotion-0 { + width: 1em; + height: 1em; +} + + + + +`; + exports[`nr-dark-mode-toggle icon matches its snapshot 1`] = ` .emotion-0 { width: 1em; diff --git a/packages/gatsby-theme-newrelic/src/icons/newrelic/arrow-down.js b/packages/gatsby-theme-newrelic/src/icons/newrelic/arrow-down.js index b99ec2604..090790259 100644 --- a/packages/gatsby-theme-newrelic/src/icons/newrelic/arrow-down.js +++ b/packages/gatsby-theme-newrelic/src/icons/newrelic/arrow-down.js @@ -1,7 +1,7 @@ import React from 'react'; import SVG from '../../components/SVG'; -const ArrowUp = ({ props }) => ( +const ArrowUp = (props) => ( ( xmlns="http://www.w3.org/2000/svg" > diff --git a/packages/gatsby-theme-newrelic/src/icons/newrelic/arrow-go-to.js b/packages/gatsby-theme-newrelic/src/icons/newrelic/arrow-go-to.js index f7d2fccac..0d42e5d47 100644 --- a/packages/gatsby-theme-newrelic/src/icons/newrelic/arrow-go-to.js +++ b/packages/gatsby-theme-newrelic/src/icons/newrelic/arrow-go-to.js @@ -1,7 +1,7 @@ import React from 'react'; import SVG from '../../components/SVG'; -const ArrowGoTo = ({ props }) => ( +const ArrowGoTo = (props) => ( ( xmlns="http://www.w3.org/2000/svg" > diff --git a/packages/gatsby-theme-newrelic/src/icons/newrelic/arrow-up.js b/packages/gatsby-theme-newrelic/src/icons/newrelic/arrow-up.js index d31ee8364..add75f4b6 100644 --- a/packages/gatsby-theme-newrelic/src/icons/newrelic/arrow-up.js +++ b/packages/gatsby-theme-newrelic/src/icons/newrelic/arrow-up.js @@ -1,8 +1,9 @@ import React from 'react'; import SVG from '../../components/SVG'; -const ArrowUp = ({ props }) => ( +const ArrowUp = (props) => ( ( xmlns="http://www.w3.org/2000/svg" >