Find filters in map visualizations#5
Conversation
Look for filters also in mapStateJSON objects, where maps store their filters.
|
|
||
| for _, path := range paths { | ||
| if m.Get(path).IsStr() { | ||
| if m.Get(path).IsStr() && m.Get(path).Str() != "" { |
There was a problem hiding this comment.
Without this change this seems to return the first path it founds, even if it is empty. There are cases where the first path is empty, but there are others with values.
| if v.SavedObjectType != "visualization" { | ||
| return "" | ||
| } | ||
|
|
There was a problem hiding this comment.
Is there a reason to return a title only for visualizations?
| "embeddableConfig.attributes.kibanaSavedObjectMeta.searchSourceJSON", | ||
| "embeddableConfig.attributes.mapStateJSON", | ||
| "embeddableConfig.attributes.uiStateJSON", | ||
| "embeddableConfig.attributes.visState", |
There was a problem hiding this comment.
Adding the paths with the embeddableConfig prefix. Actually in all the test cases these paths are prefixed with embeddableConfig, so not sure if we need the others 🤔
| "attributes.layerListJSON", | ||
| "embeddableConfig.attributes.layerListJSON", |
There was a problem hiding this comment.
layerListJSON is an slice, and fails to be decoded with FromJSON, we need to use FromJSONSlice for them.
| "panelIndex": "d9771ad7-cec0-4e4b-a51e-bbc880a8af0d", | ||
| "title": "Unique IPs map encoded", | ||
| "type": "map", | ||
| "version": "8.10.2" |
There was a problem hiding this comment.
This one is a real example from the Apache package. I had to add a validation exception because we could not find a filter, but the filter is actually there.
The previous example is the same, but decoded. We don't support decoding maps yet in elastic-package, adding support in elastic/elastic-package#1825
|
Can you add some more background information in the description? What problem is this trying to solve? Where/how can we view the existing problem? How can we test the PR? Thanks |
Added more info to the description. For testing I have added test cases to the unit test directly taken from real world examples. Let me know if I should prepare a build of Thanks! |
| queryPaths := []string{ | ||
| "attributes.kibanaSavedObjectMeta.searchSourceJSON.query.query", | ||
| "attributes.state.query.query", | ||
| "embeddableConfig.attributes.mapStateJSON.query.query", |
There was a problem hiding this comment.
Should you also add the path embeddableConfig.attributes.mapStateJSON.filters?
Maps uses Kibana's unified search, which applies filtering from 2 locations. query captures the contents search bar while filters captures the contents of the filter bar. Both should be checked to know if a map panel applies a panel level filtering.
There was a problem hiding this comment.
The structure for queries and filters are different, so there are two different checks, each one with its own list of paths.
nreese
left a comment
There was a problem hiding this comment.
kibana-presentation changes LGTM
code review only
What
Support detection of filters in map visualizations. This detection is used by package-spec and elastic-package to check that dashboards in packages include filters.
How
Maps visualizations keep most of their definitions in the
mapStateJSONobject, including filters. This change adds the path to this object to the list of paths considered when looking for filters inHasFilter().Fix also the paths used to decode embedded JSON, so the fix mentioned also works for map panels whose content is encoded.
How to test
Export a dashboard containing a maps visualization stored by value, that includes a filter.
HasFilters()for this visualization should return true.Related issues