Skip to content

Commit

Permalink
console warn for no render markdown support (#305)
Browse files Browse the repository at this point in the history
Per product's request: "good with displaying rich text direct answer as unrendered markdown for now, with the accompanying console warning." This pr added console warn in field value and featured snippet direct answer dealing with rich text field type. Also use JSON.stringify() on result of rich text and hours to avoid potential React errors such as `Objects are not valid as a React child`
  • Loading branch information
yen-tt committed Sep 8, 2022
1 parent 1e077a2 commit e37168f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/components/FeaturedSnippetDirectAnswer.tsx
Expand Up @@ -36,6 +36,9 @@ export function FeaturedSnippetDirectAnswer({
}: FeaturedSnippetDirectAnswerProps): JSX.Element {
const answer = result.fieldType === 'multi_line_text' && result.value;
// TODO: SLAP-2340, update rich text snippets to convert the markdown
if (result.fieldType === 'rich_text') {
console.warn('Rendering markdown for rich text direct answer is currently not supported. Displaying the unrendered markdown string as is.');
}
const snippet = renderHighlightedValue(result.snippet, { highlighted: cssClasses.highlighted });
const link = result.relatedResult.link || result.relatedResult.rawData.landingPageUrl as string;
const name = result.relatedResult.name;
Expand Down
8 changes: 6 additions & 2 deletions src/components/FieldValueDirectAnswer.tsx
Expand Up @@ -105,9 +105,13 @@ function getResultContent(
case BuiltInFieldType.Address:
return getAddressJsxElement(result.value);
case BuiltInFieldType.RichText:
return <div>{result.value}</div>; //TODO: SLAP-2340
//TODO: SLAP-2340
console.warn('Rendering markdown for rich text direct answer is currently not supported. Displaying the unrendered markdown string(s) as is.');
return Array.isArray(result.value)
? getListJsxElement(result.value, val => getTextJsxElement(val))
: getTextJsxElement(result.value);
case BuiltInFieldType.Hours:
return <div>{result.value}</div>;
return <div>{JSON.stringify(result.value)}</div>;
case 'unknown':
return <UnknownFieldTypeDisplay result={result}/>;
default:
Expand Down

0 comments on commit e37168f

Please sign in to comment.