Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions sites/platform/static/scripts/xss/src/components/Suggestions.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,25 @@ import DOMPurify from 'dompurify';
const Suggestions = ({ hits }) => {
const results = hits.map((r) => (
<li className="mb-4 border-b border-grey-dark" key={r.relurl}>
<h3 className="my-2" dangerouslySetInnerHTML={{ __html: DOMPurify.sanitize(r.section) }} />
<h3 className="my-2">
{DOMPurify.sanitize(r.section)}
</h3>
<p className="mb-4">
<a className="text-skye-dark hover:underline" href={r.url}>
<span dangerouslySetInnerHTML={{ __html: `${DOMPurify.sanitize(r.title)}` }} />
<span>{DOMPurify.sanitize(r.title)}</span>
</a>
</p>
</li>
))
));

return (
<div>
<div className="hits"><ul>{results}</ul></div>
{' '}
<div className="hits">
<ul>{results}</ul>
</div>
</div>
)
}
);
};

Suggestions.propTypes = {
hits: PropTypes.arrayOf(
Expand Down
6 changes: 4 additions & 2 deletions sites/platform/static/scripts/xss/src/containers/Search.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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({
Expand All @@ -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(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,21 @@
// 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) => (
<li className="mb-4 border-b border-grey-dark" key={r.relurl}>
<h3 className="mb-2">
<a className="text-skye-dark hover:underline" onClick={`dataLayer.push({'event': 'click_search_result', 'click_name': ${r.title}, 'link_url': ${r.url})`} href={r.url}>
<a className="text-skye-dark hover:underline" href={r.url} onClick={() => pushSearchResult(r.title, r.url)}>
<b dangerouslySetInnerHTML={{ __html: `${DOMPurify.sanitize(r.section)} | ` }} />

Check warning on line 22 in sites/upsun/static/scripts/xss/src/components/SuggestionsPrimary.js

View workflow job for this annotation

GitHub Actions / Check internal links (upsun)

Dangerous property 'dangerouslySetInnerHTML' found

Check warning on line 22 in sites/upsun/static/scripts/xss/src/components/SuggestionsPrimary.js

View workflow job for this annotation

GitHub Actions / Check internal links (upsun)

Dangerous property 'dangerouslySetInnerHTML' found
<span dangerouslySetInnerHTML={{ __html: `${DOMPurify.sanitize(r.title)}` }} />

Check warning on line 23 in sites/upsun/static/scripts/xss/src/components/SuggestionsPrimary.js

View workflow job for this annotation

GitHub Actions / Check internal links (upsun)

Dangerous property 'dangerouslySetInnerHTML' found

Check warning on line 23 in sites/upsun/static/scripts/xss/src/components/SuggestionsPrimary.js

View workflow job for this annotation

GitHub Actions / Check internal links (upsun)

Dangerous property 'dangerouslySetInnerHTML' found
</a>
</h3>
{/* Add keywords if they match */}
Expand Down
3 changes: 2 additions & 1 deletion sites/upsun/static/scripts/xss/src/containers/Search.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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(() => {
Expand Down
Loading