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

[ML] Maps integration: adds influencers to tooltip in anomalies layer #126007

Merged
merged 4 commits into from
Mar 1, 2022

Conversation

alvarezmelissa87
Copy link
Contributor

@alvarezmelissa87 alvarezmelissa87 commented Feb 17, 2022

Summary

Related meta issue: #123492

Adds influencers to the tooltip for each point on the map - if influencers are present.
Limits to 3 influencers and 3 influencer values to prevent tooltip from becoming too big.

image

Checklist

Delete any items that are not applicable to this PR.

@alvarezmelissa87 alvarezmelissa87 added [Deprecated-Use Team:Presentation]Team:Geo Former Team Label for Geo Team. Now use Team:Presentation :ml release_note:skip Skip the PR/issue when compiling release notes v8.2.0 labels Feb 17, 2022
@alvarezmelissa87 alvarezmelissa87 self-assigned this Feb 17, 2022
@alvarezmelissa87 alvarezmelissa87 requested a review from a team as a code owner February 17, 2022 23:30
@elasticmachine
Copy link
Contributor

Pinging @elastic/ml-ui (:ml)

@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-gis (Team:Geo)

@alvarezmelissa87 alvarezmelissa87 changed the title [ML] Maps integration: adds influencers to tooltip in anomalies layer WIP [ML] Maps integration: adds influencers to tooltip in anomalies layer Feb 17, 2022
@alvarezmelissa87 alvarezmelissa87 changed the title WIP [ML] Maps integration: adds influencers to tooltip in anomalies layer [ML] Maps integration: adds influencers to tooltip in anomalies layer Feb 23, 2022
const INFLUENCER_LIMIT = 3;
const INFLUENCER_MAX_VALUES = 3;

function getInfluencersHtmlString(
Copy link
Member

Choose a reason for hiding this comment

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

nit: Would be good to add some unit tests for this utility 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.

Added in 1dd5976

}
}

return htmlString;
Copy link
Member

Choose a reason for hiding this comment

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

If influencers.length == 0, would this htmlString be '<ul>' which is invalid html 🤔 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call - checked for influencer length before entering the function and also moved closing tag out of the loop in 1dd5976

@qn895
Copy link
Member

qn895 commented Feb 28, 2022

Pretty sure it's not related to this PR but I wasn't sure if the tooltip popups being persisted is intentional here

Screen.Recording.2022-02-28.at.12.19.59.mov


htmlString += `<li>${influencer_field_name}: ${fieldValuesString}</li>`;

// Only show top two influencers
Copy link
Member

Choose a reason for hiding this comment

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

super duper nit: since INFLUENCER_LIMIT is a constant and can potentially be changed in the future, I think this comment should not mention "two" specifically.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point - removed in 1dd5976

@nreese
Copy link
Contributor

nreese commented Feb 28, 2022

Pretty sure it's not related to this PR but I wasn't sure if the tooltip popups being persisted is intentional here

This is expected behavior. Tooltips stay opened when clicked. Tooltips auto-hide with mouse over. https://www.elastic.co/guide/en/kibana/current/vector-tooltip.html#maps-vector-tooltip-locking

@qn895
Copy link
Member

qn895 commented Feb 28, 2022

Latest changes LGTM 🎉

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
ml 3.5MB 3.5MB +521.0B
Unknown metric groups

ESLint disabled line counts

id before after diff
ml 98 99 +1

Total ESLint disabled count

id before after diff
ml 100 101 +1

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @alvarezmelissa87

Copy link
Contributor

@walterra walterra left a comment

Choose a reason for hiding this comment

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

Overall code LGTM. Just a general question because I don't know the consuming code: Can you explain why we need to create a raw HTML string instead of passing on React/TSX?

@alvarezmelissa87 alvarezmelissa87 merged commit 058ad18 into elastic:main Mar 1, 2022
@alvarezmelissa87 alvarezmelissa87 deleted the ml-maps-tooltip branch March 1, 2022 17:29
@alvarezmelissa87 alvarezmelissa87 added the backport:skip This commit does not require backporting label Mar 1, 2022
@thomasneirynck
Copy link
Contributor

thomasneirynck commented Mar 1, 2022

hi @walterra

wrt #126007 (review)

Can you explain why we need to create a raw HTML string instead of passing on React/TSX?

It is the Maps-plugin API that requires the tooltip-value to be a html-string. The reason for that is that Kibana-field-formatted values (as defined in the Data View in Stack Management), return actual HTML-strings that need to be displayed as is. This restriction bled through to the interfaces Maps exposes and that AnomalySourceTooltipProperty needs to implement.

See where this is being called and more details:

<td
className="eui-textOverflowWrap"
/*
* Justification for dangerouslySetInnerHTML:
* Property value contains value generated by Field formatter
* Since these formatters produce raw HTML, this component needs to be able to render them as-is, relying
* on the field formatter to only produce safe HTML.
*/
dangerouslySetInnerHTML={{ __html: tooltipProperty.getHtmlDisplayValue() }} // eslint-disable-line react/no-danger
/>

imho, this is an issue mainly on the MapsPlugin API-side, and needs to be resolved there first. I'd agree that the clean solution would be that external-implementers would be able to return React-dom.

I'll create a follow-up ticket for Maps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting [Deprecated-Use Team:Presentation]Team:Geo Former Team Label for Geo Team. Now use Team:Presentation :ml release_note:skip Skip the PR/issue when compiling release notes v8.2.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants