Skip to content
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

Merged
merged 8 commits into from
Sep 22, 2021
Merged

Add distance to card data #1550

merged 8 commits into from
Sep 22, 2021

Conversation

yen-tt
Copy link
Contributor

@yen-tt yen-tt commented Sep 20, 2021

  • add distance to result data in card component for dataMapping
  • provide a function in ANSWERS that format + 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 some 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.
  • jest test

Yen Truong added 3 commits September 20, 2021 17:32
- 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.
@yen-tt yen-tt added the WIP Work in progress label Sep 21, 2021
@yen-tt yen-tt removed the WIP Work in progress label Sep 21, 2021
Copy link
Collaborator

@tmeyer2115 tmeyer2115 left a 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?

package.json Show resolved Hide resolved
src/core/utils/i18nutils.js Outdated Show resolved Hide resolved
@yen-tt
Copy link
Contributor Author

yen-tt commented Sep 21, 2021

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;
Copy link
Contributor

@oshi97 oshi97 Sep 21, 2021

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.

Copy link
Contributor Author

@yen-tt yen-tt Sep 22, 2021

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

Copy link
Contributor

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?

Copy link
Contributor Author

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!

@coveralls
Copy link

coveralls commented Sep 22, 2021

Coverage Status

Coverage increased (+0.07%) to 59.386% when pulling 2e6ec8e on dev/distance-to-card into 796a0b8 on develop.

@yen-tt yen-tt requested a review from oshi97 September 22, 2021 15:36
@@ -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;
Copy link
Contributor

@oshi97 oshi97 Sep 22, 2021

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)

Copy link
Contributor Author

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!

@yen-tt yen-tt merged commit 963eec0 into develop Sep 22, 2021
@yen-tt yen-tt deleted the dev/distance-to-card branch September 22, 2021 20:10
@nmanu1 nmanu1 mentioned this pull request Nov 16, 2021
nmanu1 added a commit that referenced this pull request Nov 16, 2021
## 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants