-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added DirectAnswer component to display featured snippet and field value direct answer in universal and vertical search page. J=SLAP-1725 TEST=manual search for 'bryan phone number' and 'where/who is joe exotic' and see that both snippet and filterValue direct answer appears in universal and vertical page.
- Loading branch information
Showing
5 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { useAnswersState } from "@yext/answers-headless-react"; | ||
import { DirectAnswerType } from '@yext/answers-headless'; | ||
import renderWithHighlighting from './utils/renderWithHighlighting'; | ||
import classNames from "classnames"; | ||
import '../sass/DirectAnswer.scss'; | ||
|
||
interface DirectAnswerProps { | ||
cssClasses?: { | ||
container?: string, | ||
containerLoading?: string, | ||
title?: string, | ||
content?: string, | ||
description?: string | ||
} | ||
} | ||
|
||
const defaultCSSClasses = { | ||
container: 'DirectAnswer', | ||
containerLoading: 'DirectAnswer--loading', | ||
title: 'DirectAnswer__title', | ||
content: 'DirectAnswer__content', | ||
description: 'DirectAnswer__contentDescription' | ||
}; | ||
|
||
export default function DirectAnswer(props: DirectAnswerProps): JSX.Element | null { | ||
const directAnswerResult = useAnswersState(state => state.directAnswer.result); | ||
const isLoading = useAnswersState(state => state.searchStatus.isLoading); | ||
if (!directAnswerResult) { | ||
return null; | ||
} | ||
const { cssClasses: customCssClasses } = props; | ||
const cssClasses = Object.assign(defaultCSSClasses, customCssClasses); | ||
const containerCssClasses = classNames(cssClasses.container, { [cssClasses.containerLoading]: isLoading }); | ||
|
||
return ( | ||
<div className={containerCssClasses}> | ||
<div className={cssClasses.title}> | ||
{directAnswerResult.type === DirectAnswerType.FeaturedSnippet | ||
? directAnswerResult.value | ||
: `${directAnswerResult.entityName} / ${directAnswerResult.fieldName}`} | ||
</div> | ||
<div className={cssClasses.content}> | ||
<div className={cssClasses.description}> | ||
{directAnswerResult.type === DirectAnswerType.FeaturedSnippet | ||
? renderWithHighlighting(directAnswerResult.snippet) | ||
: directAnswerResult.value} | ||
</div> | ||
{directAnswerResult.relatedResult.link | ||
&& <a href={directAnswerResult.relatedResult.link}>View More</a>} | ||
</div> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.DirectAnswer { | ||
|
||
border: 1px solid #dcdcdc; | ||
padding: 10px; | ||
|
||
&--loading { | ||
opacity: 0.5; | ||
} | ||
} |