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

feat(headless): expose logRecommendationOpen action #902

Merged
merged 11 commits into from
Jun 17, 2021
Merged

Conversation

samisayegh
Copy link
Contributor

@github-actions
Copy link

github-actions bot commented Jun 16, 2021

Pull Request Report

PR Title

✅ Title follows the conventional commit spec.

Bundle Size

File Compression Old (kb) New (kb) Change (%)
dist/browser/headless.js bundled 529 529.9 0.2
minified 217.9 218.2 0.2
gzipped 62.3 62.4 0.1
dist/browser/headless.esm.js bundled 512.4 513.2 0.2
minified 279.6 280.1 0.2
gzipped 68.2 68.3 0.1
dist/browser/case-assist/headless.js bundled 0.5 0.5 0
minified 0.3 0.3 0
gzipped 0.2 0.2 0
dist/browser/case-assist/headless.esm.js bundled 0.1 0.1 0
minified 0 0 0
gzipped 0.1 0.1 0
dist/browser/recommendation/headless.js bundled 345.5 348.6 0.9
minified 153.6 154.9 0.8
gzipped 44.6 45 0.9
dist/browser/recommendation/headless.esm.js bundled 336.6 339.6 0.9
minified 189.3 191.2 1
gzipped 48.6 49.1 1
dist/browser/product-recommendation/headless.js bundled 343.9 343.9 0
minified 152.7 152.7 0
gzipped 44.4 44.4 0
dist/browser/product-recommendation/headless.esm.js bundled 334.9 334.9 0
minified 189.2 189.2 0
gzipped 48.6 48.6 0

@@ -35,7 +35,7 @@
"@reduxjs/toolkit": "^1.5.0",
Copy link
Contributor Author

@samisayegh samisayegh Jun 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what happened to the package-lock. If you try installing the latest analytics package, is the diff large?
I am using node 16.2.0, npm 7.13.0

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's definitely something wonky with the package locks, I think they need to be updated more often

const resultIndex =
state.recommendation?.recommendations.findIndex(
({uniqueId}) => result.uniqueId === uniqueId
) || 0;
Copy link
Contributor Author

@samisayegh samisayegh Jun 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question on this ternary, similar to the one on line 120:

  • If the recommendation state property does not exist, the index is 0, and the document position is 1 (line 149).
  • If the recommendation state exists, but the result is not found in the array, the index is -1 and document position is 0.

I feel it's weird to send two different values for the same condition of "result not found".
However, I'm not sure on what the correct value for documentPosition should be, 0 or 1?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Those documents not being found * should * not happen, since it's not really logical to be able to click on a document that does not exist. But.. 🤷

  • It's there as a fallback/artefact of the type system being unable to assure us that a given value will really be in the array, (which is normal, I guess 🤔 ) Another approach would be to just throw an error and not log anything. Which should happen upstream anyway, not in this function, which is pretty deep in the codebase.

  • For now I would suggest that index should be 0, and documentPosition -1 when it's not found. Which most likely means it's going to be rejected by UA (I would assume...).

In any case, I guess just keep in mind that no matter what, if we are unable to find the given result unique ID in the list of results, there's not much we can do to make the UA payload "correct", it's most likely going to fail in one manner or the other. And it being 0, or -1, is a small detail versus the fact that there's some code upstream that is completely wrong when calling this function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, I don't feel this is important enough to solve right now. It's definitely niche, but I still think it would be good to addressed, whether through a value, or some kind of feedback to the devs. I've created a jira to revisit.

{recommendation.title}
</ResultLink>
</a>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These samples will eventually leverage a buildInteractiveRecommendation controller.

@samisayegh samisayegh changed the title feat(headless): expose logRecommendationOpen event feat(headless): expose logRecommendationOpen action Jun 16, 2021
const resultIndex =
state.recommendation?.recommendations.findIndex(
({uniqueId}) => result.uniqueId === uniqueId
) || 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Those documents not being found * should * not happen, since it's not really logical to be able to click on a document that does not exist. But.. 🤷

  • It's there as a fallback/artefact of the type system being unable to assure us that a given value will really be in the array, (which is normal, I guess 🤔 ) Another approach would be to just throw an error and not log anything. Which should happen upstream anyway, not in this function, which is pretty deep in the codebase.

  • For now I would suggest that index should be 0, and documentPosition -1 when it's not found. Which most likely means it's going to be rejected by UA (I would assume...).

In any case, I guess just keep in mind that no matter what, if we are unable to find the given result unique ID in the list of results, there's not much we can do to make the UA payload "correct", it's most likely going to fail in one manner or the other. And it being 0, or -1, is a small detail versus the fact that there's some code upstream that is completely wrong when calling this function.

export function filterProtocol(uri: string) {
// Filters out dangerous URIs that can create XSS attacks such as `javascript:`.
const isAbsolute = /^(https?|ftp|file|mailto|tel):/i.test(uri);
const isRelative = /^\//.test(uri);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want to cover ./ ../

@samisayegh samisayegh merged commit 68fca5b into master Jun 17, 2021
@samisayegh samisayegh deleted the KIT-757 branch June 17, 2021 19:53
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