Skip to content

Commit

Permalink
Fix near me searches sometimes not triggering HTML5 geolocation (#1809
Browse files Browse the repository at this point in the history
)

This PR updates the SDK to the latest version of core, which has been updated to include `inputIntents`
on search-core's `AutocompleteResult` that were expected by the SDK but did not exist before.

search-core has been updated from v1.6 to v2.2, however none of the breaking changes affect the SDK's
external interfaces. The SDK's internal filter registry has been updated to support the breaking static filter changes from v2.0 of search-core.

T=TECHOPS-8462
TEST=auto,manual

hook local SDK up to affected techops site. see that geolocation now fires for edge case where a user
clicks on an autocomplete option for a "near me" search as opposed to typing it out manually.

see that selecting a single static filter works as expected
multiple static filters from the same field works as expected (are $or-ed together)
and multiple static filters from different fields works as expected (are $and-ed together)
  • Loading branch information
oshi97 authored Mar 24, 2023
1 parent 5cd4eb9 commit b4a6d5e
Show file tree
Hide file tree
Showing 28 changed files with 136 additions and 112 deletions.
2 changes: 1 addition & 1 deletion .size-limit.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = [
},
{
path: 'dist/answers-modern.min.js',
limit: '155 KB'
limit: '160 KB'
},
{
path: 'dist/answerstemplates.compiled.min.js',
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1469,7 +1469,7 @@ ANSWERS.addComponent('Facets', {

### Transforming Facets

The `transformFacets` option of the Facets component allows facets data to be fully customized. The function takes in and returns an array of the answers-core DisplayableFacet which is described [here](https://github.com/yext/answers-core/blob/master/docs/answers-core.displayablefacet.md). The function also has access to the Facets config as the second parameter.
The `transformFacets` option of the Facets component allows facets data to be fully customized. The function takes in and returns an array of the search-core DisplayableFacet which is described [here](https://github.com/yext/search-core/blob/master/docs/search-core.displayablefacet.md). The function also has access to the Facets config as the second parameter.

Here's an example of using this option to customize a boolean facet.

Expand Down
52 changes: 26 additions & 26 deletions THIRD-PARTY-NOTICES
Original file line number Diff line number Diff line change
Expand Up @@ -433,19 +433,13 @@ MIT License

The following NPM package may be included in this product:

- @yext/answers-core@1.6.0
- @yext/answers-storage@1.1.1

This package contains the following license and notice below:

The Answers Core files listed in this repository are licensed under the below license.  All other features and products are subject to separate agreements
and certain functionality requires paid subscriptions to Yext products.

Contains information from the language-subtag-registry JSON Database (https://github.com/mattcg/language-subtag-registry/tree/master/data/json)
which is made available under the ODC Attribution License (https://github.com/mattcg/language-subtag-registry/blob/master/LICENSE.md).

BSD 3-Clause License

Copyright (c) 2022, Yext
Copyright (c) 2020, Yext
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -477,13 +471,35 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

The following NPM package may be included in this product:

- @yext/[email protected]
- @yext/[email protected]

This package contains the following license and notice below:

# rtf-converter
Provides methods for converting Yext's flavor of Markdown into HTML or plain text

## Distribution
CDN
- unminified: https://assets.sitescdn.net/rtf-converter/rtf-converter.js
- minified: https://assets.sitescdn.net/rtf-converter/rtf-converter.min.js

-----------

The following NPM package may be included in this product:

- @yext/[email protected]

This package contains the following license and notice below:

The Search Core files listed in this repository are licensed under the below license.  All other features and products are subject to separate agreements
and certain functionality requires paid subscriptions to Yext products.

Contains information from the language-subtag-registry JSON Database (https://github.com/mattcg/language-subtag-registry/tree/master/data/json)
which is made available under the ODC Attribution License (https://github.com/mattcg/language-subtag-registry/blob/master/LICENSE.md).

BSD 3-Clause License

Copyright (c) 2020, Yext
Copyright (c) 2022, Yext
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -513,22 +529,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

-----------

The following NPM package may be included in this product:

- @yext/[email protected]

This package contains the following license and notice below:

# rtf-converter
Provides methods for converting Yext's flavor of Markdown into HTML or plain text

## Distribution
CDN
- unminified: https://assets.sitescdn.net/rtf-converter/rtf-converter.js
- minified: https://assets.sitescdn.net/rtf-converter/rtf-converter.min.js

-----------

The following NPM package may be included in this product:

- [email protected]
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion conf/gulp-tasks/bundle/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ exports.legacyBundle = function (
babel({
runtimeHelpers: true,
babelrc: false,
exclude: /node_modules\/(?!cross-fetch)(?!@yext\/answers-storage)(?!@yext\/answers-core).*/,
exclude: /node_modules\/(?!cross-fetch)(?!@yext\/answers-storage)(?!@yext\/search-core).*/,
presets: [
[
'@babel/preset-env',
Expand Down
44 changes: 22 additions & 22 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
],
"dependencies": {
"@mapbox/mapbox-gl-language": "^0.10.1",
"@yext/answers-core": "^1.6.0",
"@yext/answers-storage": "^1.1.0",
"@yext/rtf-converter": "^1.7.1",
"@yext/search-core": "^2.2.0",
"bowser": "^2.11.0",
"cross-fetch": "^3.1.5",
"css-vars-ponyfill": "^2.4.3",
Expand Down
6 changes: 3 additions & 3 deletions src/answers-umd.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,6 @@ class Answers {
this.components
.setCore(this.core)
.setRenderer(this.renderer);

this._setDefaultInitialSearch(parsedConfig.search);

if (parsedConfig.visitor) {
Expand Down Expand Up @@ -731,6 +730,7 @@ class Answers {
this.core.init({ visitor: visitor });
} else {
console.error(`Invalid visitor. Visitor was not set because "${JSON.stringify(visitor)}" does not have an id.`);
this.core.init();
}
}
}
Expand Down Expand Up @@ -788,5 +788,5 @@ function initScrollListener (reporter) {
});
}

const ANSWERS = new Answers();
export default ANSWERS;
const ANSWERS_SINGLETON = new Answers();
export default ANSWERS_SINGLETON;
10 changes: 5 additions & 5 deletions src/core/core.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** @module Core */
import { provideCore } from '@yext/answers-core/lib/commonjs';
import { provideCore } from '@yext/search-core/lib/commonjs';
import { generateUUID } from './utils/uuid';
import SearchDataTransformer from './search/searchdatatransformer';

Expand Down Expand Up @@ -119,7 +119,7 @@ export default class Core {
/** @type {ComponentManager} */
this._componentManager = config.componentManager;

/** @type {import('@yext/answers-core').AdditionalHttpHeaders} */
/** @type {import('@yext/search-core').AdditionalHttpHeaders} */
this._additionalHttpHeaders = mergeAdditionalHttpHeaders(config.additionalHttpHeaders);
}

Expand Down Expand Up @@ -259,7 +259,7 @@ export default class Core {
queryId: sendQueryId && this.storage.get(StorageKeys.QUERY_ID),
retrieveFacets: this._isDynamicFiltersEnabled,
facets: this.filterRegistry.getFacetsPayload(),
staticFilters: this.filterRegistry.getStaticFilterPayload(),
staticFilter: this.filterRegistry.getStaticFilterPayload(),
offset: this.storage.get(StorageKeys.SEARCH_OFFSET) || 0,
skipSpellCheck: this.storage.get(StorageKeys.SKIP_SPELL_CHECK),
queryTrigger: queryTriggerForApi,
Expand Down Expand Up @@ -718,9 +718,9 @@ export default class Core {
}

/**
* Gets the location object needed for answers-core
* Gets the location object needed for search-core
*
* @returns {LatLong|undefined} from answers-core
* @returns {LatLong|undefined} from search-core
*/
_getLocationPayload () {
const geolocation = this.storage.get(StorageKeys.GEOLOCATION);
Expand Down
38 changes: 22 additions & 16 deletions src/core/filters/filterregistry.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/** @module FilterRegistry */

import FilterCombinators from './filtercombinators';
import Facet from '../models/facet';
import StorageKeys from '../storage/storagekeys';
import FilterNodeFactory from './filternodefactory';
import { FilterCombinator } from '@yext/search-core';

/** @typedef {import('../storage/storage').default} Storage */

Expand Down Expand Up @@ -68,18 +68,18 @@ export default class FilterRegistry {
}

/**
* Gets the static filters as a {@link Filter|CombinedFilter} to send to the answers-core
* Gets the static filters as a {@link Filter|CombinedFilter} to send to the search-core
*
* @returns {CombinedFilter|Filter|null} Returns null if no filters with
* filtering logic are present.
* @returns {import('@yext/search-core').StaticFilter | null}
* Returns null if no filters with filtering logic are present.
*/
getStaticFilterPayload () {
const filterNodes = this.getStaticFilterNodes()
.filter(filterNode => {
return filterNode.getChildren().length > 0 || filterNode.getFilter().getFilterKey();
});
return filterNodes.length > 0
? this._transformFilterNodes(filterNodes, FilterCombinators.AND)
? this._transformFilterNodes(filterNodes, FilterCombinator.AND)
: null;
}

Expand All @@ -97,11 +97,11 @@ export default class FilterRegistry {

/**
* Transforms a list of filter nodes {@link CombinedFilterNode} or {@link SimpleFilterNode} to
* answers-core's {@link Filter} or {@link CombinedFilter}
* search-core's {@link Filter} or {@link CombinedFilter}
*
* @param {Array<CombinedFilterNode|SimpleFilterNode>} filterNodes
* @param {FilterCombinator} combinator from answers-core
* @returns {CombinedFilter|Filter} from answers-core
* @param {FilterCombinator} combinator from search-core
* @returns {import('@yext/search-core').StaticFilter} from search-core
*/
_transformFilterNodes (filterNodes, combinator) {
const filters = filterNodes.flatMap(filterNode => {
Expand All @@ -115,18 +115,18 @@ export default class FilterRegistry {
return filters.length === 1
? filters[0]
: {
kind: combinator === FilterCombinator.OR ? 'disjunction' : 'conjunction',
filters: filters,
combinator: combinator
};
}

/**
* Transforms a {@link SimpleFilterNode} to answers-core's {@link Filter} or {@link CombinedFilter}
* Transforms a {@link SimpleFilterNode} to search-core's {@link Filter} or {@link CombinedFilter}
* if there are multiple matchers.
* TODO(SLAP-1183): remove the parsing for multiple matchers.
*
* @param {SimpleFilterNode} filterNode
* @returns {Filter}
* @returns {import('@yext/search-core').StaticFilter}
*/
_transformSimpleFilterNode (filterNode) {
const fieldId = Object.keys(filterNode.filter)[0];
Expand All @@ -135,29 +135,35 @@ export default class FilterRegistry {
if (matchers.length === 1) {
const matcher = matchers[0];
const value = filterComparison[matcher];
/** @type {import('@yext/search-core').FieldValueStaticFilter} */
return {
kind: 'fieldValue',
fieldId: fieldId,
matcher: matcher,
value: value
};
} else if (matchers.length > 1) {
/** @type {import('@yext/search-core').FieldValueStaticFilter[]} */
const childFilters = matchers.map(matcher => ({
kind: 'fieldValue',
fieldId: fieldId,
matcher: matcher,
value: filterComparison[matcher]
}));
/** @type {import('@yext/search-core').ConjunctionStaticFilter} */
return {
combinator: FilterCombinators.AND,
combinator: FilterCombinator.AND,
kind: 'conjunction',
filters: childFilters
};
}
}

/**
* Transforms a {@link Filter} into answers-core's {@link FacetOption}
* Transforms a {@link Filter} into search-core's {@link FacetOption}
*
* @param {Filter} filter
* @returns {FacetOption} from answers-core
* @returns {FacetOption} from search-core
*/
_transformSimpleFilterNodeIntoFacetOption (filter) {
const fieldId = Object.keys(filter)[0];
Expand Down Expand Up @@ -196,9 +202,9 @@ export default class FilterRegistry {
}

/**
* Gets the facet filters as an array of Filters to send to the answers-core.
* Gets the facet filters as an array of Filters to send to the search-core.
*
* @returns {Facet[]} from answers-core
* @returns {Facet[]} from search-core
*/
getFacetsPayload () {
const facets = this.getFacets();
Expand Down
Loading

0 comments on commit b4a6d5e

Please sign in to comment.