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] Add back removed logic copying feature properties for injected data #49400

Merged
merged 5 commits into from
Oct 30, 2019

Conversation

kindsun
Copy link
Contributor

@kindsun kindsun commented Oct 25, 2019

Fixes a regression introduced by #47158. Logic specific to the Maps app leaks into the parsed GeoJSON object prior to indexing, causing it to be unnecessarily indexed:

Screenshot from 2019-10-25 14-02-01

This PR adds back the removed logic but in a different location to work with the new InjectedData workflow. The field no longer appears in the indexed data:

Screenshot from 2019-10-25 14-11-17

@kindsun kindsun added [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 v7.6.0 labels Oct 25, 2019
@elasticmachine
Copy link
Contributor

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

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@kindsun kindsun requested a review from nreese October 25, 2019 22:01
Copy link
Contributor

@nreese nreese left a comment

Choose a reason for hiding this comment

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

getInjectedData gets called any time syncLayerWithMB is called and syncLayerWithMB gets called any time layer state changes so putting the new properties in getInjectedData will cause a lot of new objects to get created often. cc @thomasneirynck

How about moving the fix further upstream and copy the properties prior creating the layer, or clean the properties prior to indexing?

Copy link
Contributor

@thomasneirynck thomasneirynck left a comment

Choose a reason for hiding this comment

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

This isn't the right fix imo, for the reasons @nreese mentions.

  • Syncing style should not require rewriting data.
  • The concept for InjectedData seems to be in the wrong place altogether: InjectedData does not belong on AbstractLayer if only VectorLayer is using it.
  • This PR is a spot-fix that provides an exceptional code-path for setting the visibility of a feature. Why would this knowledge have to bleed down?

imo, GeoJsonFileSource should correctly implement the same contract that all vector sources implement.

Specifically, GeoJsonFileSource should implement getGeoJsonWithMeta. In this method, it can then return a copy of the original source data, similar to how ES-source is dealing with the exact same issue and duplicating the properties. The concept of __injectedData could move down there as well (if we need it at all).

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@kindsun
Copy link
Contributor Author

kindsun commented Oct 29, 2019

After following up with an offline conversation, I've made a few changes that should address the feedback on this issue. I've backed out the introduction of the InjectedData class. To prevent any issues with copying featureCollection objects now stored again on the descriptor, I've renamed it __featureCollection allowing us to safely avoid the copy step. Setting a breakpoint right after a call to copyPersistentState I confirmed the sourceDescriptor doesn't contain __featureCollection as expected:

image

While backing out InjectedData, I also reintroduced getGeoJsonWithMeta which includes the original logic used to prevent polluting data-to-be-indexed with kibana-specific props:

image

I believe this should address the above concerns but feel free to let me know if you see anything else!

Copy link
Contributor

@nreese nreese left a comment

Choose a reason for hiding this comment

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

Thanks for backing out the __injectedData changes.

LGTM
code review, tested in chrome

Copy link
Contributor

@thomasneirynck thomasneirynck left a comment

Choose a reason for hiding this comment

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

Thanks, I think this addresses both issues more succinctly. 💯

@@ -125,6 +127,22 @@ export class GeojsonFileSource extends AbstractVectorSource {
);
}

async getGeoJsonWithMeta() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd add a safety check here to check on the existence of __featureCollection. This source could be created by a client who's passing in a descriptor without the __featureCollection property, especially now we have embeddables (e.g. consider an embeddable-client just injecting data with a GeoJsonSource and misconfigurin the descriptor). We don't want this call to throw.

You could also enforce that there's always an empty featureCollection for the __featureCollection property in the GeoJsonFileSource#constructor .

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You could also enforce that there's always an empty featureCollection for the __featureCollection property in the GeoJsonFileSource#constructor .

I like that. Done!

…imally to a geojson object with an empty features array
static createDescriptor(geoJson, name) {
// Wrap feature as feature collection if needed
let featureCollection;
if (geoJson.type === 'FeatureCollection') {
Copy link
Contributor

@nreese nreese Oct 29, 2019

Choose a reason for hiding this comment

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

Need to check that geoJson is not null here and else if statement

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@kindsun kindsun merged commit e02b092 into elastic:master Oct 30, 2019
kindsun pushed a commit to kindsun/kibana that referenced this pull request Oct 30, 2019
… data (elastic#49400)

* Add back removed logic copying feature properties for injected data prior to modification

* Back out injected data and assign featureCollection to sourceDescriptor with __ prefix

* Review feedback. Ensure __featureCollection is always initialized minimally to a geojson object with an empty features array

* Check for null/undefined
kindsun pushed a commit to kindsun/kibana that referenced this pull request Oct 30, 2019
… data (elastic#49400)

* Add back removed logic copying feature properties for injected data prior to modification

* Back out injected data and assign featureCollection to sourceDescriptor with __ prefix

* Review feedback. Ensure __featureCollection is always initialized minimally to a geojson object with an empty features array

* Check for null/undefined
kindsun pushed a commit that referenced this pull request Oct 30, 2019
… data (#49400) (#49699)

* Add back removed logic copying feature properties for injected data prior to modification

* Back out injected data and assign featureCollection to sourceDescriptor with __ prefix

* Review feedback. Ensure __featureCollection is always initialized minimally to a geojson object with an empty features array

* Check for null/undefined
kindsun pushed a commit that referenced this pull request Oct 30, 2019
… data (#49400) (#49698)

* Add back removed logic copying feature properties for injected data prior to modification

* Back out injected data and assign featureCollection to sourceDescriptor with __ prefix

* Review feedback. Ensure __featureCollection is always initialized minimally to a geojson object with an empty features array

* Check for null/undefined
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 v7.6.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants