-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add distance to card data #1550
Conversation
- modify result data in card component by adding localized distance string with km or mi as unit of length based on locale, if distance is given from liveAPI data. - functions to get distance from locale is mainly extracted from Theme with minor changes J=1573 TEST=manual - test with standard card component on index.html with universal search, after modifying the template to display distance, and see that distance is porperly formatted on each result.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to check with Rose about the scope of this item. I'm assuming she wants distance
as an attribute that's available when specifying a dataMapping
for a card. Does she want the raw data or the formatted data? Or does she want the raw data, but a method available in the SDK to format it if the user so chooses?
Confirmed with her this item should provide raw data for dataMapping and then a method for formatting |
@@ -111,6 +111,10 @@ export default class CardComponent extends Component { | |||
|
|||
// Use the cardType as component name if it is not a built-in type | |||
const cardComponentName = cardTypes[cardType] || cardType; | |||
|
|||
// additional field(s) for dataMappings config option | |||
this.result._raw.distance = this.result.distance; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would it make sense to add this to answers-core's ResultFactory.ts? Instead of having the base card component mutate the raw data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems more of a SDK specific implementation for user customization purposes using dataMappings, so I think it might not be necessary to modify answers-core's result format
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok! should we do this in the constructor instead then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh yeah, make sense. Updated!
@@ -64,6 +64,9 @@ export default class CardComponent extends Component { | |||
* @type {string} | |||
*/ | |||
this.verticalKey = data.verticalKey; | |||
|
|||
// additional field(s) for dataMappings config option | |||
this.result._raw.distance = this.result.distance; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this will error out if data.result is undefined, since in that case this.result will be set to {}
(also can we move this to right below this.result is first set)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah yup, you are right. Updated!
## Version 1.12.0 ### Features - Allow search rate tracking (#1558) - Add support for setting and changing the visitor and passing it to answers-core (#1564) - Add support for the auth token that is passed in from the config (#1566) - Add an `environment` field to support consumer auth in Sandbox (#1597) - Allow components to override the beforeMount function (#1547) - Add distance to the card data and a function to format it (#1550) - WCAG updates (allow pagination with Enter (#1575), identify current page in navigation tab (#1576), update autocomplete screen reader support (#1578, #1579)) ### Changes - Update directAnswers component data to include the searcher (#1596) - Use custom alerts instead of window.alert (#1549) - Update Mapbox version to match the Theme (#1551) - Internal repo changes (#1562, #1577) ### Bugfixes - Fix console error which would appear on google maps (#1548) - Fix FAQ expansion when default is expanded (#1553) - Fix error for searches on page load with no businessId (#1561)
J=1573
TEST=manual