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

Enable freeform-select with fetched column values for filter values #1697

Merged
merged 7 commits into from
Dec 16, 2016

Conversation

vera-liu
Copy link
Contributor

Credits to: @the-dcruz https://github.com/airbnb/superset/pull/1061
Done:

  • db migration to add filter_select_enabled
  • add freeform-multi option for Selectfield
  • modify formatFilter() function on query to accomodate filter-select

To enable:
in edit table mode:
screen shot 2016-11-28 at 10 23 37 am

Select for filter-value:
screen shot 2016-11-28 at 10 18 40 am

screen shot 2016-11-28 at 10 18 40 am

needs-review @mistercrunch @ascott @bkyryliuk

@@ -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)
Copy link

@ascott ascott Nov 29, 2016

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.

Copy link
Contributor Author

@vera-liu vera-liu Nov 29, 2016

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)

Copy link

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()
Copy link

@ascott ascott Nov 29, 2016

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")
Copy link

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"),
Copy link

Choose a reason for hiding this comment

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

'all_datasource_access', 'all_datasource_access')
datasource_access = self.can_access(
'datasource_access', datasource.perm)
if not (all_datasource_access or datasource_access):
Copy link

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 ?
Copy link

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}
Copy link

Choose a reason for hiding this comment

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

2 space indent needed

@ascott
Copy link

ascott commented Nov 29, 2016

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?

@vera-liu vera-liu force-pushed the freeform_select_filter branch from a0e32c7 to 25c620d Compare December 2, 2016 20:24
@@ -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
Copy link

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) {
Copy link

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.

@ascott
Copy link

ascott commented Dec 14, 2016

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.

@vera-liu vera-liu force-pushed the freeform_select_filter branch from 25c620d to 7ab2756 Compare December 15, 2016 22:58
@vera-liu vera-liu force-pushed the freeform_select_filter branch from 2192819 to 0aae4b6 Compare December 16, 2016 22:05
@vera-liu vera-liu merged commit 6732f01 into apache:master Dec 16, 2016
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.15.1 labels Feb 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.15.1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants