Skip to content

Commit

Permalink
Merge pull request #1142 from yext/fix-faq-answer
Browse files Browse the repository at this point in the history
Update FAQ card to support answerV2 instead of answer
  • Loading branch information
likimmy authored Aug 14, 2023
2 parents e1e7dab + d627612 commit 9212bc9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
11 changes: 10 additions & 1 deletion cards/faq-accordion/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,20 @@ class faq_accordionCardComponent extends BaseCard['faq-accordion'] {
*/
dataForRender(profile) {
const linkTarget = AnswersExperience.runtimeConfig.get('linkTarget') || '_top';
let profileAnswer = '';
if (profile.answerV2 && profile.answerV2.html) {
profileAnswer = profile.answerV2.html;
} else if (profile.answerV2 && profile.answerV2.json) {
console.warn('JSON is not supported, please convert to HTML.')
} else if (profile.answer) {
profileAnswer = ANSWERS.formatRichText(profile.answer, "answer", linkTarget);
}

return {
title: profile.question || profile.name, // The header text of the card
// subtitle: '', // The sub-header text of the card
details: profile.answer ? ANSWERS.formatRichText(profile.answer, "answer", linkTarget) : null, // The text in the body of the card
details: profileAnswer ? profileAnswer : null, // The text in the body
// of the card
// If the card's details are longer than a certain character count, you can truncate the
// text. A toggle will be supplied that can show or hide the truncated text.
// showMoreDetails: {
Expand Down
11 changes: 10 additions & 1 deletion cards/multilang-faq-accordion/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,20 @@ class multilang_faq_accordionCardComponent extends BaseCard['multilang-faq-accor
*/
dataForRender(profile) {
const linkTarget = AnswersExperience.runtimeConfig.get('linkTarget') || '_top';
let profileAnswer = '';
if (profile.answerV2 && profile.answerV2.html) {
profileAnswer = profile.answerV2.html;
} else if (profile.answerV2 && profile.answerV2.json) {
console.warn('JSON is not supported, please convert to HTML.')
} else if (profile.answer) {
profileAnswer = ANSWERS.formatRichText(profile.answer, "answer", linkTarget);
}

return {
title: profile.question || profile.name, // The header text of the card
// subtitle: '', // The sub-header text of the card
details: profile.answer ? ANSWERS.formatRichText(profile.answer, "answer", linkTarget) : null, // The text in the body of the card
details: profileAnswer ? profileAnswer : null, // The text in the body
// of the card
// If the card's details are longer than a certain character count, you can truncate the
// text. A toggle will be supplied that can show or hide the truncated text.
// showMoreDetails: {
Expand Down

0 comments on commit 9212bc9

Please sign in to comment.