diff --git a/sites/platform/static/scripts/xss/src/components/Suggestions.js b/sites/platform/static/scripts/xss/src/components/Suggestions.js index 1d25a88ab9..a61ed44aa4 100644 --- a/sites/platform/static/scripts/xss/src/components/Suggestions.js +++ b/sites/platform/static/scripts/xss/src/components/Suggestions.js @@ -10,22 +10,25 @@ import DOMPurify from 'dompurify'; const Suggestions = ({ hits }) => { const results = hits.map((r) => (
  • -

    +

    + {DOMPurify.sanitize(r.section)} +

    - + {DOMPurify.sanitize(r.title)}

  • - )) + )); return (
    -
    - {' '} +
    + +
    - ) -} + ); +}; Suggestions.propTypes = { hits: PropTypes.arrayOf( diff --git a/sites/platform/static/scripts/xss/src/containers/Search.js b/sites/platform/static/scripts/xss/src/containers/Search.js index 38c147aff7..356cde7b2f 100644 --- a/sites/platform/static/scripts/xss/src/containers/Search.js +++ b/sites/platform/static/scripts/xss/src/containers/Search.js @@ -38,7 +38,7 @@ const Search = ({ fullPage }) => { const url = new URL(window.location.href) urlQuery = url.pathname.replace('.html', '').replaceAll('/', ' ').replaceAll('-', ' ') } - + const [setError] = useState(null) const limit = fullPage ? maxResults : 7 const getInfo = (infoConfig, infoQuery) => { @@ -48,6 +48,8 @@ const Search = ({ fullPage }) => { setConfig(value) }) } + + axios.get(`${infoConfig.url}indexes/${infoConfig.index}/search?attributesToCrop=text&cropLength=200&attributesToHighlight=text,keywords&q=${infoQuery}&limit=${limit}&attributesToRetrieve=title,keywords,text,url,site,section`, { params: {}, headers: { Authorization: `Bearer ${infoConfig.public_api_key}` } }) .then(({ data }) => { setHits({ @@ -58,7 +60,7 @@ const Search = ({ fullPage }) => { apidocs: data.hits.filter((hit) => hit.site === 'apidocs'), }) }) - .catch((err) => console.error(err)) + .catch((err) => setError(err.message)) } useEffect(() => { diff --git a/sites/upsun/static/scripts/xss/src/components/SuggestionsPrimary.js b/sites/upsun/static/scripts/xss/src/components/SuggestionsPrimary.js index 4b930f5f7c..46ac438caa 100644 --- a/sites/upsun/static/scripts/xss/src/components/SuggestionsPrimary.js +++ b/sites/upsun/static/scripts/xss/src/components/SuggestionsPrimary.js @@ -6,11 +6,19 @@ import React from 'react'; // which in this case are documents coming from the public documentation. // These results are presented in a separate section in the dropdown, // and prioritized as primary results via the index's `rank` attribute. +function pushSearchResult(title, url) { + window.dataLayer.push({ + event: 'click_search_result', + click_name: title, + link_url: url + }) +} + const SuggestionsPrimary = ({ hits, title }) => { const results = hits.map((r) => (
  • - + pushSearchResult(r.title, r.url)}> diff --git a/sites/upsun/static/scripts/xss/src/containers/Search.js b/sites/upsun/static/scripts/xss/src/containers/Search.js index 488309d93e..63b8b88815 100644 --- a/sites/upsun/static/scripts/xss/src/containers/Search.js +++ b/sites/upsun/static/scripts/xss/src/containers/Search.js @@ -39,6 +39,7 @@ const Search = ({ fullPage }) => { urlQuery = url.pathname.replace('.html', '').replaceAll('/', ' ').replaceAll('-', ' ') } + const [setError] = useState(null) const limit = fullPage ? maxResults : 7 const getInfo = (infoConfig, infoQuery) => { @@ -61,7 +62,7 @@ const Search = ({ fullPage }) => { apidocs: data.hits.filter((hit) => hit.site === 'apidocs'), }) }) - .catch((err) => console.error(err)) + .catch((err) => setError(err.message)) } useEffect(() => {