Skip to content

Set uiState to Vis from visualization - #15549

Merged
timroes merged 1 commit into
elastic:masterfrom
timroes:uistate-refactor
Dec 14, 2017
Merged

timroes merged 1 commit into
elastic:masterfrom
timroes:uistate-refactor

Conversation

@timroes

@timroes timroes commented Dec 12, 2017

Copy link
Copy Markdown
Contributor

We previously passed the uiState down the whole chain from <visualize> to <visualization>, but still required the users of the topmost entry point he uses (most likely <visualize>) to call vis.setUiState(uiSTate) manually, besides passing it down.

This PR changes, that behavior, that <visualization> will now call vis.setUiState whenever it gets a new uiState. That way we make it easier to use visualizations, since you are not required to pass the uiState to different methods. There was also no use case earlier, in passing a different uiState to the <visualize> directive, than you set via vis.setUiState, it would just cause broken behavior.

Fixes #15255 since the visual loader didn't call that method, using it would exactly cause that weird behavior, where you pass a uiState to <visualize> but never set it via vis.setUiState, in which case you couldn't change any legend colors.

Also the visualize editor silently swallowed the uiState it got passed in, and the default editor instead would just read back the one already attached to the vis. This PR also properly passes down the uiState now also in editor mode.

@timroes timroes added Feature:Vis Loader Visualize loader APIs Feature:Visualizations Generic visualization features (in case no more specific feature label is available) chore v6.2.0 v7.0.0 labels Dec 12, 2017
@ppisljar

Copy link
Copy Markdown
Contributor

looks good, i will wait for the tests to pass and also give it some more testing before approving :)

@ppisljar ppisljar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@thomasneirynck thomasneirynck left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good. I tested this with a couple visualizations.

Could you also edit the corresponding docs?

https://www.elastic.co/guide/en/kibana/master/development-vis-editors.html#development-custom-editor

@timroes

timroes commented Dec 13, 2017 •

Copy link
Copy Markdown
Contributor Author

@thomasneirynck What would you like to fix there? That an editor might want to pass through the uiState to the $scope it generates? Since this documentation doesn't talk at all about how to actually render anything in this render method, and also doesn't tell anything about what to do with visData, searchSource, etc. or any other parameter that would be expected on the scope, I don't see the benefit of talking about uiState in that place.

If the custom editor doesn't by chance render the <visualization> element within its template it would anyway not be needed. And if it renders it, all the other things would also be needed, that we don't talk about there.

@thomasneirynck

thomasneirynck commented Dec 13, 2017 •

Copy link
Copy Markdown
Contributor

@timroes fair enough, we skipped over these properties for convenience as not to clutter the doc. So this is only tangentially related to this PR. The mismatching doc doesn't seem to right approach in hindsight. If we continue not to document them, this is a sign the Editor-API needs work. After all, when people write custom editors, they will see 3 (formerly 2) extra parameters passed in, that are very mysterious. And there is a possibly meaningful parameter in there (updateStatus), that goes unused in our internal code. Overloading signatures isn't a native feature of JS and imho there's no compelling reason to insist on having it here.

So if we're going to expand on the API-method, I'd use the opportunity to improve on getting the doc synced with the actual implementations. Couple of approaches to consider:

  • we document all arguments and briefly explain what they are, adding a DEPRECATED note on all but the visData. That we use them in the default-editor we can then chalk up to being legacy code. Other people should not.
  • the default editor gets a one-off .renderWithState(data, searchSource, uiState) method, and we check on its presence in the visualize_editor on which one to call. That gives us an internal special code-path, invisible and undocumented to other users.

The updateStatus flag actually I do think is meaningful, so we can consider keeping it (and documenting it). If so, I'd reorder updateStatus to be 2nd parameter for symmetry.

@timroes
timroes merged commit 51ec1a8 into elastic:master Dec 14, 2017
@timroes
timroes deleted the uistate-refactor branch December 14, 2017 09:40
timroes added a commit to timroes/kibana that referenced this pull request Dec 14, 2017
nyurik pushed a commit to nyurik/kibana that referenced this pull request Dec 15, 2017
patrykkopycinski pushed a commit to patrykkopycinski/kibana that referenced this pull request May 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore Feature:Vis Loader Visualize loader APIs Feature:Visualizations Generic visualization features (in case no more specific feature label is available) v6.2.0 v7.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants