Skip to content

Commit

Permalink
Merge 6bd66b8 into 1ac89a7
Browse files Browse the repository at this point in the history
  • Loading branch information
cea2aj committed Oct 13, 2021
2 parents 1ac89a7 + 6bd66b8 commit 4e3a8f5
Show file tree
Hide file tree
Showing 41 changed files with 537 additions and 225 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/sync_develop_and_main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: create PR from main to develop

on:
push:
branches: [main, master]

permissions:
contents: read
pull-requests: write

jobs:
createPullRequest:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: extract package version
id: vars
run: |
PACKAGE_VERSION="v$(cat ./package.json | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[",]//g' | tr -d '[[:space:]]')"
echo ::set-output name=tag::${PACKAGE_VERSION}
- uses: repo-sync/pull-request@v2
with:
source_branch: "${{ github.event.repository.default_branch }}"
destination_branch: "develop"
pr_title: "Merge ${{ github.event.repository.default_branch }} (${{ steps.vars.outputs.tag }}) into develop"
pr_body: "Merge ${{ github.event.repository.default_branch }} (${{ steps.vars.outputs.tag }}) into develop"
github_token: ${{ secrets.GITHUB_TOKEN }}
4 changes: 3 additions & 1 deletion directanswercards/allfields-standard/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
{{> cta CTA linkTarget=linkTarget}}
</div>
{{/if}}
{{> footer }}
{{#if feedbackEnabled}}
{{> footer }}
{{/if}}
</div>

{{#*inline 'icon'}}
Expand Down
1 change: 1 addition & 0 deletions directanswercards/card_component.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ BaseDirectAnswerCard["{{componentName}}"] = class extends ANSWERS.Component {

return super.setState({
...cardData,
feedbackEnabled: ANSWERS.getAnalyticsOptIn(),
feedbackSubmitted: data.feedbackSubmitted,
isArray: Array.isArray(this.answer.value),
cardName: `{{componentName}}`,
Expand Down
4 changes: 3 additions & 1 deletion directanswercards/documentsearch-standard/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
{{> cta CTA linkTarget=linkTarget}}
</div>
</div>
{{> footer}}
{{#if feedbackEnabled}}
{{> footer }}
{{/if}}
</div>

{{#*inline 'title'}}
Expand Down
4 changes: 3 additions & 1 deletion directanswercards/multilang-allfields-standard/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
{{> cta CTA linkTarget=linkTarget}}
</div>
{{/if}}
{{> footer }}
{{#if feedbackEnabled}}
{{> footer }}
{{/if}}
</div>

{{#*inline 'icon'}}
Expand Down
2 changes: 1 addition & 1 deletion global_config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"sdkVersion": "1.10", // The version of the Answers SDK to use
"sdkVersion": "1.11", // The version of the Answers SDK to use
// "apiKey": "<REPLACE ME>", // The answers api key found on the experiences page. This will be provided automatically by the Yext CI system
// "experienceVersion": "<REPLACE ME>", // the Answers Experience version to use for API requests. This will be provided automatically by the Yext CI system
// "businessId": "<REPLACE ME>", // The business ID of the account. This will be provided automatically by the Yext CI system
Expand Down
46 changes: 42 additions & 4 deletions hooks/templatedatavalidator.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const path = require('path');
const { parseJamboConfig } = require('../commands/helpers/utils/jamboconfigutils');
const { error } = require('../commands/helpers/utils/logger');
const { error, warn } = require('../commands/helpers/utils/logger');

/**
* Validates the template data and partials used during jambo build.
Expand All @@ -13,8 +13,9 @@ const { error } = require('../commands/helpers/utils/logger');
*/
module.exports = function (pageData, partials) {
const jamboConfig = parseJamboConfig();
const { JAMBO_INJECTED_DATA } = pageData.env;
const validatorResults = [
isGlobalConfigValid(pageData.global_config),
isGlobalConfigValid(pageData.global_config, JAMBO_INJECTED_DATA),
isPageVerticalConfigValid(pageData, jamboConfig, partials)
];
const isValid = validatorResults.every(result => result);
Expand All @@ -25,13 +26,50 @@ module.exports = function (pageData, partials) {
* Validates global config for the page template
*
* @param {Object} globalConfig
* @param {Object} JAMBO_INJECTED_DATA
* @returns {boolean}
*/
function isGlobalConfigValid(globalConfig) {
if (!globalConfig.experienceKey) {
function isGlobalConfigValid(globalConfig, JAMBO_INJECTED_DATA) {
const { experienceKey } = globalConfig;
if (!experienceKey) {
error('Missing Info: no experienceKey found.');
return false;
}
if (globalConfig.useJWT || globalConfig.apiKey) {
return true;
}

const injectedDataForExperience = JAMBO_INJECTED_DATA.answers.experiences[experienceKey];
if (!injectedDataForExperience) {
error(`No JAMBO_INJECTED_DATA found for experience key: "${experienceKey}"`);
error(`Found JAMBO_INJECTED_DATA: "${JSON.stringify(JAMBO_INJECTED_DATA, null, 2)}.`);
return false;
}

const productionApiKey = injectedDataForExperience.configByLabel.PRODUCTION.apiKey;
const deprecatedApiKey = injectedDataForExperience.apiKey;
if (!productionApiKey) {
if (!deprecatedApiKey) {
error(`No injected production api key found for experience key: "${experienceKey}"`);
} else {
warn('No injected production api key found, using the default apiKey instead.');
}
}

const stagingApiKey = injectedDataForExperience.configByLabel.STAGING.apiKey;
if (!stagingApiKey) {
if (!deprecatedApiKey) {
error(`No injected staging api key found for experience key: "${experienceKey}"`);
} else {
warn('No injected staging api key found, using the default apiKey instead.');
}
}

if ((!productionApiKey || !stagingApiKey) && !deprecatedApiKey) {
error(`JAMBO_INJECTED_DATA is missing an api key.`);
error(`Found JAMBO_INJECTED_DATA: "${JSON.stringify(JAMBO_INJECTED_DATA, null, 2)}.`);
return false;
}
return true;
}

Expand Down
37 changes: 14 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "answers-hitchhiker-theme",
"version": "1.24.1",
"version": "1.25.0",
"description": "A starter answers theme for hitchhikers",
"scripts": {
"test": "cross-env NODE_ICU_DATA=node_modules/full-icu jest --verbose",
Expand Down Expand Up @@ -34,7 +34,7 @@
"file-system": "^2.2.2",
"full-icu": "^1.3.1",
"handlebars": "^4.7.6",
"jambo": "^1.12.0",
"jambo": "^1.12.1",
"jest": "^25.5.2",
"libphonenumber-js": "^1.9.6",
"loader-utils": "^2.0.0",
Expand Down
1 change: 1 addition & 0 deletions script/core.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
});
}
}).catch(err => {
console.error(err);
window.AnswersExperience.AnswersInitializedPromise.reject('Answers failed to initialized.');
});
{{> script/after-init}}
Expand Down
18 changes: 11 additions & 7 deletions static/js/formatters-internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,19 @@ export function toLocalizedDistance(profile, key = 'd_distance', displayUnits) {
return this.toMiles(profile, undefined, undefined, locale);
}

export function _getLocaleWithDashes(locale) {
return locale && locale.replace(/_/g, '-');
}

export function _getDocumentLocale() {
return document.documentElement.lang.replace('_', '-');
return _getLocaleWithDashes(document.documentElement.lang);
}

export function toKilometers(profile, key = 'd_distance', displayUnits = 'km', locale) {
if (!profile[key]) {
return '';
}
locale = locale || _getDocumentLocale()
locale = _getLocaleWithDashes(locale) || _getDocumentLocale();
const distanceInKilometers = profile[key] / 1000; // Convert meters to kilometers
return new Intl.NumberFormat(locale,
{ style: 'decimal', maximumFractionDigits: 1, minimumFractionDigits: 1})
Expand All @@ -101,7 +105,7 @@ export function toMiles(profile, key = 'd_distance', displayUnits = 'mi', locale
if (!profile[key]) {
return '';
}
locale = locale || _getDocumentLocale()
locale = _getLocaleWithDashes(locale) || _getDocumentLocale();
const distanceInMiles = profile[key] / 1609.344; // Convert meters to miles
return new Intl.NumberFormat(locale,
{ style: 'decimal', maximumFractionDigits: 1, minimumFractionDigits: 1 })
Expand Down Expand Up @@ -234,7 +238,7 @@ export function snakeToTitle(snake) {
* @returns {string} The pretty printed value.
*/
export function prettyPrintObject(obj, locale) {
locale = locale || _getDocumentLocale();
locale = _getLocaleWithDashes(locale) || _getDocumentLocale();

switch (typeof obj) {
case 'string':
Expand Down Expand Up @@ -459,7 +463,7 @@ export function openStatus(profile, key = 'hours', isTwentyFourHourClock, locale
}

const hoursLocalizer = new HoursStringsLocalizer(
locale || _getDocumentLocale(), isTwentyFourHourClock);
_getLocaleWithDashes(locale) || _getDocumentLocale(), isTwentyFourHourClock);
return new OpenStatusMessageFactory(hoursLocalizer)
.create(hours.openStatus);
}
Expand Down Expand Up @@ -501,7 +505,7 @@ export function hoursList(profile, opts = {}, key = 'hours', locale) {
};

const hoursLocalizer = new HoursStringsLocalizer(
locale || _getDocumentLocale(), opts.isTwentyFourHourClock);
_getLocaleWithDashes(locale) || _getDocumentLocale(), opts.isTwentyFourHourClock);
return new HoursTableBuilder(hoursLocalizer).build(hours, standardizedOpts);
}

Expand All @@ -515,7 +519,7 @@ export { generateCTAFieldTypeLink };
* returns the price value without formatting
*/
export function price(fieldValue = {}, locale) {
const localeForFormatting = locale || _getDocumentLocale() || 'en';
const localeForFormatting = _getLocaleWithDashes(locale) || _getDocumentLocale() || 'en';
const price = fieldValue.value && parseFloat(fieldValue.value);
const currencyCode = fieldValue.currencyCode && fieldValue.currencyCode.split('-')[0];
if (!price || isNaN(price) || !currencyCode) {
Expand Down

0 comments on commit 4e3a8f5

Please sign in to comment.