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

[Maps] Enable ability to provide custom renderer for tooltip #46150

Merged
merged 10 commits into from
Sep 27, 2019

Conversation

nreese
Copy link
Contributor

@nreese nreese commented Sep 19, 2019

Fixes #43641

This PR enhances factory.createFromState method with a renderTooltipContent parameter. When set, renderTooltipContent is used to render the tooltip content.

/**
 * Render custom tooltip content
 *
 * @param {function} addFilters
 * @param {function} closeTooltip
 * @param {Array} features - Vector features at tooltip location.
 * @param {boolean} isLocked
 * @param {function} loadFeatureProperties - Loads feature properties. Call with { layerId, featureId }. Returns Promise.
 *
 * @return {Component} A React Component.
 */
const renderTooltipContent = ({ addFilters, closeTooltip, features, isLocked, loadFeatureProperties}) => {
  return <div>Custom tooltip content</div>;
}

const mapEmbeddable = await factory.createFromState(state, input, parent, renderTooltipContent);

PR also adds unit tests for TooltipControl component

cc @spong

@nreese nreese added WIP Work in progress [Deprecated-Use Team:Presentation]Team:Geo Former Team Label for Geo Team. Now use Team:Presentation v8.0.0 release_note:skip Skip the PR/issue when compiling release notes v7.5.0 labels Sep 19, 2019
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-gis

@spong
Copy link
Member

spong commented Sep 19, 2019

This may've been leftover from the previous implementation, but looks like the margins/centering of the loading spinner are a little off.

Hover / Click

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@spong
Copy link
Member

spong commented Sep 23, 2019

Would it be possible to get access to findLayerById as well? Without this, to display all available layers we would have to call loadFeatureProperties() for each unique layerId to get _indexPattern.title off of the feature props.

@nreese
Copy link
Contributor Author

nreese commented Sep 23, 2019

Would it be possible to get access to findLayerById as well? Without this, to display all available layers we would have to call loadFeatureProperties() for each unique layerId to get _indexPattern.title off of the feature props.

Would you just want a method to get layer name? Not sure we want to expose the entire layer API outside of maps application?

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@nreese nreese requested a review from kindsun September 24, 2019 20:06
@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@nreese nreese removed the WIP Work in progress label Sep 26, 2019
getLayerName: this._getLayerName,
};

if (this.props.renderTooltipContent) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Small thing, but I wonder if we should consider setting default props to false on renderTooltipContent

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I do not understand what you mean. Could you elaborate?

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually null would be more appropriate here. I think it just feels strange to rely on a prop that's undefined embedded several components down without having a default value. My first thought was, "we're relying on this value, what's the default if not overridden?" But yeah, undefined evaluates to false so it doesn't really make a difference.

Copy link
Contributor

@kindsun kindsun left a comment

Choose a reason for hiding this comment

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

lgtm. pulled down the code and mostly just reviewed programatically since it's designed to be leveraged by other apps. It'd be nice to see some functional tests but I think that onus falls on the leveraging apps (like SIEM) if they think it'd be beneficial.

  • code review

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@nreese nreese merged commit c3f4f5d into elastic:master Sep 27, 2019
nreese added a commit to nreese/kibana that referenced this pull request Sep 27, 2019
…#46150)

* [Maps] Enable ability to provide custom renderer for tooltip

* add unit test for on click handler

* unit tests for mouseout behavior

* add unit tests for on map move

* clean up test

* pass getLayerName to custom tooltip renderer

* fix jest test
nreese added a commit that referenced this pull request Sep 27, 2019
…#46843)

* [Maps] Enable ability to provide custom renderer for tooltip

* add unit test for on click handler

* unit tests for mouseout behavior

* add unit tests for on map move

* clean up test

* pass getLayerName to custom tooltip renderer

* fix jest test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Deprecated-Use Team:Presentation]Team:Geo Former Team Label for Geo Team. Now use Team:Presentation release_note:skip Skip the PR/issue when compiling release notes v7.5.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Maps] [Embeddables] Enable ability to provide custom renderer for tooltip
4 participants