From 0fa9314d3b8c8b2e3e25248956a47beb2c5df26d Mon Sep 17 00:00:00 2001 From: Yen Truong <36055303+yen-tt@users.noreply.github.com> Date: Thu, 4 Nov 2021 12:52:37 -0400 Subject: [PATCH 01/19] DirectAnswers on Vertical: Templates + Analytics (#994) - move directanswers markup and script to common-partials folder - update vertical standard templates to include direct answer - update direct answer base card component to include the correct searcher (Universal or Vertical) - add and comment out directanswer config for vertical standard page NOTE: this requires [changes in SDK](https://github.com/yext/answers-search-ui/pull/1596) to work J=SLAP-1674 T=manual change people vertical page to vertical-standard with directanswer configs/templates uncommented. serve test-site, and perform 'bryan phone number' on universal page and people page. See that direct answers appear for both page. When click thumbs up, see that the appropriate analytics payload is send in the request. --- directanswercards/card_component.js | 8 ++++---- templates/common-partials/markup/directanswer.hbs | 1 + templates/common-partials/script/directanswer.hbs | 9 +++++++++ templates/universal-standard/markup/directanswer.hbs | 2 +- templates/universal-standard/script/directanswer.hbs | 10 +--------- templates/vertical-standard/markup/directanswer.hbs | 1 + templates/vertical-standard/page-config.json | 12 ++++++++++++ templates/vertical-standard/page.html.hbs | 3 +++ templates/vertical-standard/script/directanswer.hbs | 1 + tests/templates/script/fixtures/directanswer.hbs.js | 2 ++ 10 files changed, 35 insertions(+), 14 deletions(-) create mode 100644 templates/common-partials/markup/directanswer.hbs create mode 100644 templates/common-partials/script/directanswer.hbs create mode 100644 templates/vertical-standard/markup/directanswer.hbs create mode 100644 templates/vertical-standard/script/directanswer.hbs create mode 100644 tests/templates/script/fixtures/directanswer.hbs.js diff --git a/directanswercards/card_component.js b/directanswercards/card_component.js index 5593bf584..0fadc0462 100644 --- a/directanswercards/card_component.js +++ b/directanswercards/card_component.js @@ -23,9 +23,9 @@ BaseDirectAnswerCard["{{componentName}}"] = class extends ANSWERS.Component { setState(data) { let cardData = this.dataForRender(this.type, this.answer, this.relatedItem, this.snippet); this.validateDataForRender(cardData); - return super.setState({ ...cardData, + searcher: data.searcher, feedbackEnabled: ANSWERS.getAnalyticsOptIn(), feedbackSubmitted: data.feedbackSubmitted, isArray: Array.isArray(this.answer.value), @@ -97,7 +97,7 @@ BaseDirectAnswerCard["{{componentName}}"] = class extends ANSWERS.Component { .addOptions({ directAnswer: true, verticalKey: this.verticalConfigId, - searcher: 'UNIVERSAL', + searcher: this.getState('searcher'), entityId: this.associatedEntityId }); @@ -120,7 +120,7 @@ BaseDirectAnswerCard["{{componentName}}"] = class extends ANSWERS.Component { */ addDefaultEventOptions(eventOptions = {}) { return Object.assign({}, { - searcher: "UNIVERSAL", + searcher: this.getState('searcher'), verticalConfigId: this.verticalConfigId, entityId: this.associatedEntityId, ...eventOptions @@ -144,7 +144,7 @@ BaseDirectAnswerCard["{{componentName}}"] = class extends ANSWERS.Component { verticalKey: this.verticalConfigId, directAnswer: true, fieldName: this.answer.fieldApiName, - searcher: 'UNIVERSAL', + searcher: this.getState('searcher'), entityId: this.associatedEntityId, url: event.target.href }; diff --git a/templates/common-partials/markup/directanswer.hbs b/templates/common-partials/markup/directanswer.hbs new file mode 100644 index 000000000..5f000c6a7 --- /dev/null +++ b/templates/common-partials/markup/directanswer.hbs @@ -0,0 +1 @@ +
\ No newline at end of file diff --git a/templates/common-partials/script/directanswer.hbs b/templates/common-partials/script/directanswer.hbs new file mode 100644 index 000000000..7d383bd9a --- /dev/null +++ b/templates/common-partials/script/directanswer.hbs @@ -0,0 +1,9 @@ +ANSWERS.addComponent("DirectAnswer", +{{#shallowMergeConfig}}[ + { + "container": "#js-answersDirectAnswer" + }, + {{{json componentSettings.DirectAnswer}}} +] +{{/shallowMergeConfig}} +); diff --git a/templates/universal-standard/markup/directanswer.hbs b/templates/universal-standard/markup/directanswer.hbs index 5f000c6a7..e22487a72 100644 --- a/templates/universal-standard/markup/directanswer.hbs +++ b/templates/universal-standard/markup/directanswer.hbs @@ -1 +1 @@ - \ No newline at end of file +{{> templates/common-partials/markup/directanswer }} \ No newline at end of file diff --git a/templates/universal-standard/script/directanswer.hbs b/templates/universal-standard/script/directanswer.hbs index 7d383bd9a..b9007a58e 100644 --- a/templates/universal-standard/script/directanswer.hbs +++ b/templates/universal-standard/script/directanswer.hbs @@ -1,9 +1 @@ -ANSWERS.addComponent("DirectAnswer", -{{#shallowMergeConfig}}[ - { - "container": "#js-answersDirectAnswer" - }, - {{{json componentSettings.DirectAnswer}}} -] -{{/shallowMergeConfig}} -); +{{> templates/common-partials/script/directanswer }} \ No newline at end of file diff --git a/templates/vertical-standard/markup/directanswer.hbs b/templates/vertical-standard/markup/directanswer.hbs new file mode 100644 index 000000000..e22487a72 --- /dev/null +++ b/templates/vertical-standard/markup/directanswer.hbs @@ -0,0 +1 @@ +{{> templates/common-partials/markup/directanswer }} \ No newline at end of file diff --git a/templates/vertical-standard/page-config.json b/templates/vertical-standard/page-config.json index 7286a26f5..b2d9a4bac 100644 --- a/templates/vertical-standard/page-config.json +++ b/templates/vertical-standard/page-config.json @@ -32,6 +32,18 @@ "clearSearchText": "clear search" // Text when there are no results, conducts an empty search }, **/ + /** + "DirectAnswer": { + "types": { + "FEATURED_SNIPPET": { + "cardType": "documentsearch-standard" + }, + "FIELD_VALUE": { + "cardType": "allfields-standard" + } + } + }, + **/ "AppliedFilters": { "removable": true }, diff --git a/templates/vertical-standard/page.html.hbs b/templates/vertical-standard/page.html.hbs index d2a4ee93e..a018e1879 100644 --- a/templates/vertical-standard/page.html.hbs +++ b/templates/vertical-standard/page.html.hbs @@ -1,12 +1,14 @@ {{#> layouts/html }} {{#> script/core }} {{> cards/all }} + {{!-- {{> directanswercards/all }} --}} {{!-- {{> templates/vertical-standard/collapsible-filters/page-setup }} --}} {{> templates/vertical-standard/script/appliedfilters }} {{> templates/vertical-standard/script/verticalresultscount }} {{> templates/vertical-standard/script/searchbar }} {{> templates/vertical-standard/script/spellcheck }} {{> templates/vertical-standard/script/navigation }} + {{!-- {{> templates/vertical-standard/script/directanswer }} --}} {{> templates/vertical-standard/script/verticalresults }} {{> templates/vertical-standard/script/pagination }} {{> templates/vertical-standard/script/locationbias }} @@ -27,6 +29,7 @@ partial for this page, you should not use it on any other page. --> {{!-- {{> layouts/overlay-suggestions }} --}}