refactor: removed he and added a util to decode html
Signed-off-by: Tommy Le <tommy_8786@hotmail.com>
This commit is contained in:
@@ -54,7 +54,6 @@
|
||||
"@testing-library/jest-dom": "^6.0.0",
|
||||
"@types/react": "^16.13.1 || ^17.0.0 || ^18.0.0",
|
||||
"cross-fetch": "^4.0.0",
|
||||
"he": "^1.2.0",
|
||||
"lodash": "^4.17.21",
|
||||
"qs": "^6.9.4",
|
||||
"react-use": "^17.2.4"
|
||||
@@ -70,7 +69,6 @@
|
||||
"@testing-library/dom": "^9.0.0",
|
||||
"@testing-library/react": "^14.0.0",
|
||||
"@testing-library/user-event": "^14.0.0",
|
||||
"@types/he": "^1.2.3",
|
||||
"msw": "^1.0.0"
|
||||
},
|
||||
"files": [
|
||||
|
||||
+6
-9
@@ -27,7 +27,7 @@ import {
|
||||
import { useAnalytics } from '@backstage/core-plugin-api';
|
||||
import type { ResultHighlight } from '@backstage/plugin-search-common';
|
||||
import { HighlightedSearchResultText } from '@backstage/plugin-search-react';
|
||||
import { decode } from 'he';
|
||||
import { decodeHtml } from '../../util';
|
||||
|
||||
/**
|
||||
* Props for {@link StackOverflowSearchResultListItem}
|
||||
@@ -45,13 +45,10 @@ export const StackOverflowSearchResultListItem = (
|
||||
props: StackOverflowSearchResultListItemProps,
|
||||
) => {
|
||||
const { result, highlight } = props;
|
||||
|
||||
const analytics = useAnalytics();
|
||||
|
||||
const handleClick = () => {
|
||||
if (!result) {
|
||||
return;
|
||||
}
|
||||
|
||||
analytics.captureEvent('discover', result.title, {
|
||||
attributes: { to: result.location },
|
||||
value: props.rank,
|
||||
@@ -73,12 +70,12 @@ export const StackOverflowSearchResultListItem = (
|
||||
<Link to={result.location} noTrack onClick={handleClick}>
|
||||
{highlight?.fields?.title ? (
|
||||
<HighlightedSearchResultText
|
||||
text={decode(highlight.fields.title)}
|
||||
text={decodeHtml(highlight.fields.title)}
|
||||
preTag={highlight.preTag}
|
||||
postTag={highlight.postTag}
|
||||
/>
|
||||
) : (
|
||||
decode(result.title)
|
||||
decodeHtml(result.title)
|
||||
)}
|
||||
</Link>
|
||||
}
|
||||
@@ -87,13 +84,13 @@ export const StackOverflowSearchResultListItem = (
|
||||
<>
|
||||
Author:{' '}
|
||||
<HighlightedSearchResultText
|
||||
text={decode(highlight.fields.text)}
|
||||
text={decodeHtml(highlight.fields.text)}
|
||||
preTag={highlight.preTag}
|
||||
postTag={highlight.postTag}
|
||||
/>
|
||||
</>
|
||||
) : (
|
||||
`Author: ${decode(result.text)}`
|
||||
`Author: ${decodeHtml(result.text)}`
|
||||
)
|
||||
}
|
||||
/>
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright 2024 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export function decodeHtml(input: string) {
|
||||
const textContainer = document.createElement('textarea');
|
||||
textContainer.innerHTML = input;
|
||||
return textContainer.value;
|
||||
}
|
||||
Reference in New Issue
Block a user