Skip to content

Commit

Permalink
Merge e958b68 into 06642fb
Browse files Browse the repository at this point in the history
  • Loading branch information
tmeyer2115 authored Dec 14, 2021
2 parents 06642fb + e958b68 commit 9494f2b
Show file tree
Hide file tree
Showing 51 changed files with 669 additions and 694 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/version-update.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Update package version for release & hotfix branches

on:
push:
branches: [release/*, hotfix/*]

permissions:
contents: write
pull-requests: write

jobs:
update-version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- name: update package version
id: vars
run: |
BRANCH_NAME="${GITHUB_REF#refs/heads/}"
PACKAGE_VERSION="${GITHUB_REF##*/}"
echo ::set-output name=branch::${BRANCH_NAME}
if [[ $PACKAGE_VERSION =~ ^v[0-9]+\.[0-9]+(\.[0-9]+)?$ ]]
then
if [[ $PACKAGE_VERSION =~ ^v[0-9]+\.[0-9]+$ ]]
then
PACKAGE_VERSION="${PACKAGE_VERSION}.0"
fi
echo ::set-output name=version::${PACKAGE_VERSION}
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
if npm version ${PACKAGE_VERSION} | tee >( grep -q 'npm ERR! Version not changed' )
then
echo "Package version is already in sync with branch name."
echo ::set-output name=should_create_pr::0
exit 0
fi
echo ::set-output name=should_create_pr::1
git push -u origin HEAD:"dev/update-version-${PACKAGE_VERSION}"
else
echo "Branch name ${BRANCH_NAME} does not have the correct format with package version."
exit 1
fi
- name: create version update pr
if: steps.vars.outputs.should_create_pr == 1
uses: repo-sync/pull-request@v2
with:
source_branch: "dev/update-version-${{ steps.vars.outputs.version }}"
destination_branch: "${{ steps.vars.outputs.branch }}"
pr_title: "Update Package Version to ${{ steps.vars.outputs.version }}"
pr_body: "*An automated PR which updates the version number in package.json and package-lock.json files*"
github_token: ${{ secrets.GITHUB_TOKEN }}
8 changes: 4 additions & 4 deletions directanswercards/card_component.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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
});

Expand All @@ -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
Expand All @@ -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
};
Expand Down
1 change: 1 addition & 0 deletions global_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// "token": "<REPLACE ME>", // The auth token to access Answers experience.
// "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
// "environment": "production", // The environment to run on for this Answers Experience. (i.e. 'production' or 'sandbox')
// "businessId": "<REPLACE ME>", // The business ID of the account. This will be provided automatically by the Yext CI system
// "initializeManually": true, // If true, the experience must be started by calling AnswersExperience.init() or AnswersExperienceFrame.init() for iframe integrations.
// "useJWT": true, // Whether or not to enable JWT. If true, the apiKey will be hidden from the build output and the token must be specified through manual initialization.
Expand Down
27 changes: 27 additions & 0 deletions hbshelpers/getDefaultUniversalLimit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Generates a default result limit for each vertical on the universal page. The
* default is taken from the vertical's `universalLimit`, specified in the related
* page's VTC. If there is no such `universalLimit`, the back-end default of 10 will
* be used.
*
* @param {Object} pageConfigs - The configurations for each page.
* @returns {Object} The partial of the search configuration related to universal limits.
*/
module.exports = function getDefaultUniversalLimit(pageConfigs) {
const universalLimit = Object.entries(pageConfigs)
.filter(([pageName, _]) => pageName != 'index')
.reduce((limit, [_, pageConfig]) => {
const verticalKey = pageConfig.verticalKey;
const hasUniversalLimit =
pageConfig.verticalsToConfig &&
pageConfig.verticalsToConfig[verticalKey] &&
pageConfig.verticalsToConfig[verticalKey].universalLimit;
if (hasUniversalLimit) {
limit[verticalKey] = pageConfig.verticalsToConfig[verticalKey].universalLimit;
}

return limit;
}, {});

return { universalLimit };
}
15 changes: 15 additions & 0 deletions hbshelpers/wrapJsPartial.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* This is a block helper for injecting inline JS using handlebars.
*
* First, it wraps the statement in an iife to prevent namespacing issues.
*
* Then, it adds an extra new line to the end of the iife.
* This is necesssary because handlebars removes the first new line it sees after a partial invocation,
* which can result in certain js parsing issues, for example if the last line of the partial is a
* single line js comment, the line immediately after the partial will be included in the comment.
*
* @param {import('handlebars').HelperOptions} opts
*/
module.exports = function wrapJsPartial(opts) {
return `(() => { \n${opts.fn()}\n })()\n`;
}
11 changes: 9 additions & 2 deletions layouts/html.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
if (window.name == 'overlay') {
window.isOverlay = true;
}
{{> script/translations}}
{{#wrapJsPartial}}
{{> script/translations}}
{{/wrapJsPartial}}
{{/babel}}
</script>
{{> layouts/headincludes }}
Expand Down Expand Up @@ -72,10 +74,15 @@
<script>
{{#babel}}
document.addEventListener('DOMContentLoaded', () => {
{{> script/on-document-load}}
{{#if global_config.initializeManually}}
new HitchhikerJS.ManualInitializer(initAnswers).setup();
{{#wrapJsPartial}}
{{> script/on-document-load}}
{{/wrapJsPartial}}
{{else}}
{{#wrapJsPartial}}
{{> script/on-document-load}}
{{/wrapJsPartial}}
initAnswers();
{{/if}}
});
Expand Down
8 changes: 4 additions & 4 deletions layouts/preload-fonts.hbs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!-- Preload the SourceSans fonts used by default in the Theme -->
<link rel="preload" as="font" href="{{relativePath}}/static/assets/fonts/source-sans-pro-v14-latin-300.woff" type="font/woff" crossorigin="anonymous">
<link rel="preload" as="font" href="{{relativePath}}/static/assets/fonts/source-sans-pro-v14-latin-600.woff" type="font/woff" crossorigin="anonymous">
<link rel="preload" as="font" href="{{relativePath}}/static/assets/fonts/source-sans-pro-v14-latin-700.woff" type="font/woff" crossorigin="anonymous">
<link rel="preload" as="font" href="{{relativePath}}/static/assets/fonts/source-sans-pro-v14-latin-regular.woff" type="font/woff" crossorigin="anonymous">
<link rel="preload" as="font" href="{{relativePath}}/source-sans-pro-v14-latin-300.woff" type="font/woff" crossorigin="anonymous">
<link rel="preload" as="font" href="{{relativePath}}/source-sans-pro-v14-latin-600.woff" type="font/woff" crossorigin="anonymous">
<link rel="preload" as="font" href="{{relativePath}}/source-sans-pro-v14-latin-700.woff" type="font/woff" crossorigin="anonymous">
<link rel="preload" as="font" href="{{relativePath}}/source-sans-pro-v14-latin-regular.woff" type="font/woff" crossorigin="anonymous">
3 changes: 2 additions & 1 deletion package-lock.json

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

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "answers-hitchhiker-theme",
"version": "1.26.0",
"version": "1.27.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 @@ -32,6 +32,7 @@
"comment-json": "^4.1.1",
"cross-env": "^7.0.2",
"currency-symbol-map": "^5.0.1",
"escape-html": "^1.0.3",
"express": "^4.17.1",
"file-system": "^2.2.2",
"full-icu": "^1.3.1",
Expand Down Expand Up @@ -75,6 +76,7 @@
"/fixtures/",
"/test-utils/",
"/test-site/",
"/browser-automation/",
"/percy/",
"/wcag/",
"/acceptance/"
Expand Down
18 changes: 15 additions & 3 deletions script/core.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@
...{{{ json search }}}
},
{{/if}}
{{#unless ../verticalKey}}
search: {
...{{{ json (getDefaultUniversalLimit ../verticalConfigs) }}},
...{{{ json search }}}
},
{{/unless}}
{{/with}}
};
const token = window.AnswersExperience.runtimeConfig?.get('token');
Expand Down Expand Up @@ -64,7 +70,9 @@
{{> @partial-block }}
{{> script/on-ready}}
{{#wrapJsPartial}}
{{> script/on-ready}}
{{/wrapJsPartial}}
{{#if global_config.conversionTrackingEnabled}}
ANSWERS.setConversionsOptIn(true);
Expand Down Expand Up @@ -120,14 +128,18 @@
});
window.iframeLoaded.then(() => {
{{> script/iframe-messaging}}
{{#wrapJsPartial}}
{{> script/iframe-messaging}}
{{/wrapJsPartial}}
});
}
}).catch(err => {
console.error(err);
window.AnswersExperience.AnswersInitializedPromise.reject('Answers failed to initialized.');
});
{{> script/after-init}}
{{#wrapJsPartial}}
{{> script/after-init}}
{{/wrapJsPartial}}
}
{{/babel}}
</script>
Expand Down
4 changes: 4 additions & 0 deletions static/js/answers-experience.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export default class AnswersExperience {
this._registerRuntimeConfigListeners();
}

init() {
console.error('AnswersExperience.init was called before an init method was set. This is a no-op.')
}

/**
* Registers runtime config listeners and ensures that they execute
* after Answers has initialized
Expand Down
Loading

0 comments on commit 9494f2b

Please sign in to comment.