-
Notifications
You must be signed in to change notification settings - Fork 14.4k
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
Enable freeform-select with fetched column values for filter values #1697
Conversation
@@ -871,6 +872,7 @@ class SqlaTable(Model, Queryable, AuditMixinNullable, ImportMixin): | |||
default_endpoint = Column(Text) | |||
database_id = Column(Integer, ForeignKey('dbs.id'), nullable=False) | |||
is_featured = Column(Boolean, default=False) | |||
filter_select_enabled = Column(Boolean, default=False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there any reason not to enable filter select all of the time? it seems like a better user experience to have the values available for filtering in a select rather than a text input.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the original incentive was that filter method only retrieves samples of the values, not all of them, for some columns there could be way too many values to be displayed, and user prefer to directly add values in input, separated by comma, instead of wrapping each value in single quotes and add it as an option. (The reason for wrapping values in quote is to accomodate values with comma in them)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok thx for the explanation 👍
""" | ||
Returns the URL to retrieve column values used in the filter dropdown | ||
""" | ||
d = self.orig_form_data.copy() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we use a more descriptive variable name here and on line 160? i'm assuming they stand for data
and ordered_data
? nice to be more specific.
datasource_class).filter_by(id=datasource_id).first() | ||
|
||
if not datasource: | ||
flash(__("The datasource seems to have been deleted"), "alert") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we have a constant, DATASOURCE_MISSING_ERR
, for this error message here:
https://github.com/airbnb/superset/blob/master/superset/views.py#L81
datasource_access = self.can_access( | ||
'datasource_access', datasource.perm) | ||
if not (all_datasource_access or datasource_access): | ||
flash(__("You don't seem to have access to this datasource"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could use ALL_DATASOURCE_ACCESS_ERR
here. https://github.com/airbnb/superset/blob/master/superset/views.py#L79
'all_datasource_access', 'all_datasource_access') | ||
datasource_access = self.can_access( | ||
'datasource_access', datasource.perm) | ||
if not (all_datasource_access or datasource_access): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like we have datasource access methods on the base view we could use here: https://github.com/airbnb/superset/blob/master/superset/views.py#L54
if not (self.all_datasource_access() or self.datasource_access(datasource))
@@ -65,13 +84,23 @@ export default class Filter extends React.Component { | |||
onChange={this.changeOp.bind(this, this.props.filter)} | |||
/> | |||
<div className="col-lg-6"> | |||
<input | |||
{this.props.filter_select ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this might be easier to read if we pull it out into it's own method, like renderFilterInput
/> | ||
{selectWrap} | ||
<div> | ||
{selectWrap} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 space indent needed
this is looking good. i'm curious to hear other thoughts on this: should we just enable filter selects by default, and not have an option to enable/disable? seems to me that the select with column values is a much better ux and we should be choosing smart defaults over too much configuration. @mistercrunch @bkyryliuk thoughts? |
a0e32c7
to
25c620d
Compare
@@ -65,13 +84,23 @@ export default class Filter extends React.Component { | |||
onChange={this.changeOp.bind(this, this.props.filter)} | |||
/> | |||
<div className="col-lg-6"> | |||
<input | |||
{this.props.renderFilterSelect ? | |||
(<SelectField |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like this should be indented 2 spaces. might be cleaner to pull this out to another method and call that here {this.renderFilterFormField()}
@@ -42,8 +42,18 @@ export default class SelectField extends React.Component { | |||
if (this.props.freeForm) { | |||
// For FreeFormSelect, insert value into options if not exist | |||
const values = this.props.choices.map((c) => c[0]); | |||
if (values.indexOf(this.props.value) === -1) { | |||
options.push({ value: this.props.value, label: this.props.value }); | |||
if (this.props.value) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might be cleaner to pull this out into another method and add a comment about how this is for supporting the free form select field options.
this generally LGTM. there are a lot of code changes here, would probably be beneficial to write some tests as well, but could come in another PR if you want to get this out asap. |
25c620d
to
7ab2756
Compare
- db migration to add filter_select_enabled - add freeform-multi option for Selectfield - modify formatFilter() function on query to accomodate filter-select
2192819
to
0aae4b6
Compare
Credits to: @the-dcruz https://github.com/airbnb/superset/pull/1061
Done:
To enable:
![screen shot 2016-11-28 at 10 23 37 am](https://cloud.githubusercontent.com/assets/20978302/20680678/e1864c0e-b554-11e6-984b-3ba64f1fbf52.png)
in edit table mode:
Select for filter-value:
![screen shot 2016-11-28 at 10 18 40 am](https://cloud.githubusercontent.com/assets/20978302/20680613/a4ed5a58-b554-11e6-9429-4f28258eec39.png)
needs-review @mistercrunch @ascott @bkyryliuk