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

Conditionally show Visualize button based on aggregatable status #8694

Merged
merged 3 commits into from
Oct 17, 2016

Conversation

Bargs
Copy link
Contributor

@Bargs Bargs commented Oct 14, 2016

Now that we know which fields are aggregatable, we should only show the Visualize button in the Discover sidebar when a field is in fact aggregatable.

Fixes #5873

screen shot 2016-10-14 at 6 27 24 pm

@cjcenizal
Copy link
Contributor

cjcenizal commented Oct 15, 2016

Two points of note...

  1. Kibana 5.0 seems to show a different error than what's show in the linked issue:

image

I don't really know what this error means. How does it relate to the idea of a field being aggregatable?

  1. This tooltip would previously be visible on buttons like this:

image

How does this warning relate to the idea of a field being aggregatable, if at all?

@@ -44,6 +44,7 @@ <h5 ng-show="!field.details.error">Quick Count <kbn-info info="Top 5 values base

<a
ng-href="{{vizLocation(field)}}"
ng-if="field.aggregatable"
Copy link
Contributor

@cjcenizal cjcenizal Oct 15, 2016

Choose a reason for hiding this comment

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

I think this would be more ergonomic if it called a method, like this:

ng-if="isFieldVisualizable(field)"

which then called a service:

import isFieldVisualizable from 'ui/visualize/is_field_visualizable'; // location tbd
scope.isFieldVisualizable = isFieldVisualizable;

which codified this rule (and future related rules):

// is_field_visualizable.js
export default isFieldVisualizable(field) {
  // Some explanation here about why non-aggregatable fields can't be visualized.
  if (!field.aggregatable) {
    return false;
  }

  return true;
}

It seems like a lot of code for such a small feature, but I think it's important we codify our business logic this way. Otherwise the "what" of the code isn't justified by a "why". Other benefits include increased readability, testability (we can test the service), and scalability (we can add additional rules to the service).

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 would agree if there were multiple factors that went into deciding if a field was "visualizable", but as things stand today I think that's a premature abstraction. Non-aggregatable fields can't be visualized because Kibana visualizes aggregations. I could add an inline comment which I think would be less confusing than creating a new service.

Copy link
Contributor

Choose a reason for hiding this comment

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

That makes sense. How about a compromise? Can you just put the isFieldVisualizable method on the scope instead of in a separate service? At least this way the code becomes self-documenting.

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 added an additional flag to the field object itself, I think it's a more appropriate place to put that kind of logic. Let me know how that looks to you.

@cjcenizal
Copy link
Contributor

The code works great! I just had a couple questions for my own enlightenment, and a couple small suggestions.

@tbragin
Copy link
Contributor

tbragin commented Oct 16, 2016

I checked out the PR and I see the following behavior - when you repeatedly open and close a field where the visualize button is shown, it remains visible when you close the field, and thus when you open it again, now you see multiple buttons. Anyone else sees that behavior?

screen shot 2016-10-16 at 6 27 09 am

@Bargs
Copy link
Contributor Author

Bargs commented Oct 17, 2016

I don't really know what this error means. How does it relate to the idea of a field being aggregatable?

Analyzed fields can only be aggregated if they have fielddata enabled. Pre-5.0 it was enabled by default, now it's disabled by default so that these errors are much more common.

How does this warning relate to the idea of a field being aggregatable, if at all?

If a user manually enables fielddata on an analyzed field they can still create visualizations with it, but it'll probably suck up a lot of memory and give unexpected results because you're visualizing the analyzed data, not the data as it originally existed in _source. So this warning is still relevant in those cases.

@Bargs
Copy link
Contributor Author

Bargs commented Oct 17, 2016

@tbragin yup I see that too, and confirmed it only happens in this PR. Great catch

@Bargs Bargs force-pushed the filterVisualizeButton branch from 0254818 to 75a2f23 Compare October 17, 2016 17:39
@Bargs
Copy link
Contributor Author

Bargs commented Oct 17, 2016

@tbragin fixed the whack-a-button problem. Ready for another look.

@cjcenizal
Copy link
Contributor

LGTM

@jbudz jbudz self-assigned this Oct 17, 2016
@jbudz
Copy link
Member

jbudz commented Oct 17, 2016

discover-visualize mov

whoops, that's a small gif. I'm clicking on xss, which doesn't have visualize (expected), but clicking visualize on the field above tries to load xss still.

@Bargs
Copy link
Contributor Author

Bargs commented Oct 17, 2016

@jbudz weird. That appears to be an existing issue in master as well. I'll see if I can fix it though.

@jbudz
Copy link
Member

jbudz commented Oct 17, 2016

If you want a separate issue for it, this LGTM

@Bargs Bargs merged commit ff01707 into elastic:master Oct 17, 2016
elastic-jasper added a commit that referenced this pull request Oct 17, 2016
---------

**Commit 1:**
Conditionally show Visualize button based on aggregatable status

* Original sha: 76c2687
* Authored by Matthew Bargar <[email protected]> on 2016-10-14T22:23:37Z

**Commit 2:**
Switch to ng-show so controller can maintain reference to Visualize button and remove it upon toggle

* Original sha: 9da6ddf
* Authored by Matthew Bargar <[email protected]> on 2016-10-17T17:21:11Z

**Commit 3:**
Add visualizable flag to field object

* Original sha: 75a2f23
* Authored by Matthew Bargar <[email protected]> on 2016-10-17T17:39:13Z
elastic-jasper added a commit that referenced this pull request Oct 17, 2016
---------

**Commit 1:**
Conditionally show Visualize button based on aggregatable status

* Original sha: 76c2687
* Authored by Matthew Bargar <[email protected]> on 2016-10-14T22:23:37Z

**Commit 2:**
Switch to ng-show so controller can maintain reference to Visualize button and remove it upon toggle

* Original sha: 9da6ddf
* Authored by Matthew Bargar <[email protected]> on 2016-10-17T17:21:11Z

**Commit 3:**
Add visualizable flag to field object

* Original sha: 75a2f23
* Authored by Matthew Bargar <[email protected]> on 2016-10-17T17:39:13Z
This was referenced Oct 17, 2016
Bargs pushed a commit that referenced this pull request Oct 17, 2016
Bargs pushed a commit that referenced this pull request Oct 17, 2016
@epixa epixa added the v5.1.1 label Dec 8, 2016
@epixa epixa removed the v5.1.0 label Dec 8, 2016
airow pushed a commit to airow/kibana that referenced this pull request Feb 16, 2017
---------

**Commit 1:**
Conditionally show Visualize button based on aggregatable status

* Original sha: 77294135d9bc8c70f562a866ea1f52b83b56c1a2 [formerly 76c2687]
* Authored by Matthew Bargar <[email protected]> on 2016-10-14T22:23:37Z

**Commit 2:**
Switch to ng-show so controller can maintain reference to Visualize button and remove it upon toggle

* Original sha: 414865ec12af65652e9339329e6826270a3f4f0e [formerly 9da6ddf]
* Authored by Matthew Bargar <[email protected]> on 2016-10-17T17:21:11Z

**Commit 3:**
Add visualizable flag to field object

* Original sha: 8d830f2d92fbf099de573a60ce878a9a3ef3ccea [formerly 75a2f23]
* Authored by Matthew Bargar <[email protected]> on 2016-10-17T17:39:13Z


Former-commit-id: 6874f1b
airow pushed a commit to airow/kibana that referenced this pull request Feb 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants