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

feat(explore): new datasets have autocomplete filters enabled if UX_BETA is set #15864

Merged
merged 5 commits into from Jul 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -17,12 +17,19 @@
* under the License.
*/
import React, { useEffect, useMemo, useState } from 'react';
import { logging, SupersetClient, t, Metric } from '@superset-ui/core';
import {
FeatureFlag,
isFeatureEnabled,
logging,
Metric,
SupersetClient,
t,
} from '@superset-ui/core';
import { ColumnMeta } from '@superset-ui/chart-controls';
import { Tooltip } from 'src/components/Tooltip';
import {
Operators,
OPERATOR_ENUM_TO_OPERATOR_TYPE,
Operators,
} from 'src/explore/constants';
import { OptionSortType } from 'src/explore/types';
import {
Expand Down Expand Up @@ -304,9 +311,14 @@ export const DndFilterSelect = (props: DndFilterSelectProps) => {
sqlExpression: (droppedItem as AdhocMetric)?.translateToSql(),
});
}
return new AdhocFilter({
const config: Partial<AdhocFilter> = {
subject: (droppedItem as ColumnMeta)?.column_name,
});
};
if (isFeatureEnabled(FeatureFlag.UX_BETA)) {
config.operator = OPERATOR_ENUM_TO_OPERATOR_TYPE[Operators.IN].operation;
config.operatorId = Operators.IN;
}
Comment on lines +317 to +320
Copy link
Member

Choose a reason for hiding this comment

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

When we drop a non-string column, the UX feels slightly unintuitive (here I dropped the num column):

image

Since we have the full set of columns along with their type_generic, maybe we could consider having different behavior for numeric and temporal column types while we're at it?

Copy link
Member

Choose a reason for hiding this comment

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

good idea! it would be great to have the numeric slider in adhoc filter eventually when we redesign the entire component.
For temporal columns, i doubt users would use adhoc filter for it.
For numeric, we can use "=" or "<"? either way, the preselection is not gonna trigger any query, or adding additional clicks to selection, so the change is harmless. it really depends on what our best guess is without further data.

return new AdhocFilter(config);
}, [droppedItem]);

return (
Expand Down
Expand Up @@ -427,7 +427,7 @@ const AdhocFilterEditPopoverSimpleTabContent: React.FC<Props> = props => {
>
{suggestions.map((suggestion: string) => (
<Select.Option value={suggestion} key={suggestion}>
{suggestion}
{String(suggestion)}
</Select.Option>
))}

Expand Down
4 changes: 2 additions & 2 deletions superset/connectors/base/models.py
Expand Up @@ -24,7 +24,7 @@
from sqlalchemy.ext.declarative import declared_attr
from sqlalchemy.orm import foreign, Query, relationship, RelationshipProperty, Session

from superset import security_manager
from superset import is_feature_enabled, security_manager
from superset.constants import NULL_STRING
from superset.models.helpers import AuditMixinNullable, ImportExportMixin, QueryResult
from superset.models.slice import Slice
Expand Down Expand Up @@ -103,7 +103,7 @@ def name(self) -> str:
description = Column(Text)
default_endpoint = Column(Text)
is_featured = Column(Boolean, default=False) # TODO deprecating
filter_select_enabled = Column(Boolean, default=False)
filter_select_enabled = Column(Boolean, default=is_feature_enabled("UX_BETA"))
offset = Column(Integer, default=0)
cache_timeout = Column(Integer)
params = Column(String(1000))
Expand Down
1 change: 1 addition & 0 deletions superset/examples/bart_lines.py
Expand Up @@ -59,6 +59,7 @@ def load_bart_lines(only_metadata: bool = False, force: bool = False) -> None:
tbl = table(table_name=tbl_name)
tbl.description = "BART lines"
tbl.database = database
tbl.filter_select_enabled = True
db.session.merge(tbl)
db.session.commit()
tbl.fetch_metadata()
Expand Up @@ -24,7 +24,7 @@ schema: null
sql: ''
params: null
template_params: null
filter_select_enabled: false
filter_select_enabled: true
fetch_values_predicate: null
extra: null
uuid: d95a2865-53ce-1f82-a53d-8e3c89331469
Expand Down
Expand Up @@ -24,7 +24,7 @@ schema: null
sql: null
params: null
template_params: null
filter_select_enabled: false
filter_select_enabled: true
fetch_values_predicate: null
extra: null
uuid: 3e8130eb-0831-d568-b531-c3ce6d68d3d8
Expand Down
2 changes: 1 addition & 1 deletion superset/examples/configs/datasets/examples/channels.yaml
Expand Up @@ -24,7 +24,7 @@ schema: null
sql: null
params: null
template_params: null
filter_select_enabled: false
filter_select_enabled: true
fetch_values_predicate: null
extra: null
uuid: f7db6d45-7056-f395-d24a-6c805fb4c97d
Expand Down
Expand Up @@ -24,7 +24,7 @@ schema: null
sql: null
params: null
template_params: null
filter_select_enabled: false
filter_select_enabled: true
fetch_values_predicate: null
extra: null
uuid: e8623bb9-5e00-f531-506a-19607f5f8005
Expand Down
Expand Up @@ -24,7 +24,7 @@ schema: null
sql: ''
params: null
template_params: null
filter_select_enabled: false
filter_select_enabled: true
fetch_values_predicate: null
extra: null
uuid: 974b7a1c-22ea-49cb-9214-97b7dbd511e0
Expand Down
Expand Up @@ -24,7 +24,7 @@ schema: null
sql: ''
params: null
template_params: null
filter_select_enabled: false
filter_select_enabled: true
fetch_values_predicate: null
extra: null
uuid: 0bd5d01c-b7d8-471b-b3a5-366ce6c920d4
Expand Down
Expand Up @@ -25,7 +25,7 @@ sql: SELECT c.name AS channel_name, u.name AS member_name FROM channel_members c
JOIN channels c ON cm.channel_id = c.id JOIN users u ON cm.user_id = u.id
params: null
template_params: null
filter_select_enabled: false
filter_select_enabled: true
fetch_values_predicate: null
extra: null
uuid: 3d9c0054-b31b-4102-92de-b1ef9f9e5e77
Expand Down
2 changes: 1 addition & 1 deletion superset/examples/configs/datasets/examples/messages.yaml
Expand Up @@ -24,7 +24,7 @@ schema: null
sql: null
params: null
template_params: null
filter_select_enabled: false
filter_select_enabled: true
fetch_values_predicate: null
extra: null
uuid: e032c69e-716e-d700-eff7-07800d0f9989
Expand Down
Expand Up @@ -25,7 +25,7 @@ sql: SELECT m.ts, c.name, m.text FROM messages m JOIN channels c ON m.channel_id
c.id
params: null
template_params: null
filter_select_enabled: false
filter_select_enabled: true
fetch_values_predicate: null
extra: null
uuid: 6e533506-fce6-4f6a-b116-d139df6dbdea
Expand Down
Expand Up @@ -25,7 +25,7 @@ sql: SELECT date, total_membership - lag(total_membership) OVER (ORDER BY date)
new_members FROM exported_stats
params: null
template_params: null
filter_select_enabled: false
filter_select_enabled: true
fetch_values_predicate: null
extra: null
uuid: 9dd99cda-ff6b-4575-9a74-684d06e871ab
Expand Down
2 changes: 1 addition & 1 deletion superset/examples/configs/datasets/examples/threads.yaml
Expand Up @@ -24,7 +24,7 @@ schema: null
sql: null
params: null
template_params: null
filter_select_enabled: false
filter_select_enabled: true
fetch_values_predicate: null
extra: null
uuid: d7438be6-6078-17dd-cf9a-56f0ef546c80
Expand Down
Expand Up @@ -24,7 +24,7 @@ schema: null
sql: null
params: null
template_params: null
filter_select_enabled: false
filter_select_enabled: true
fetch_values_predicate: null
extra: null
uuid: a6771c73-96fc-44c6-8b6e-9d303955ea48
Expand Down
2 changes: 1 addition & 1 deletion superset/examples/configs/datasets/examples/users.yaml
Expand Up @@ -24,7 +24,7 @@ schema: null
sql: null
params: null
template_params: null
filter_select_enabled: false
filter_select_enabled: true
fetch_values_predicate: null
extra: null
uuid: 7195db6b-2d17-7619-b7c7-26b15378df8c
Expand Down
Expand Up @@ -28,7 +28,7 @@ sql: 'SELECT uc1.name as channel_1, uc2.name as channel_2, count(*) AS cnt
HAVING uc1.name <> uc2.name'
params: null
template_params: null
filter_select_enabled: false
filter_select_enabled: true
fetch_values_predicate: null
extra: null
uuid: 473d6113-b44a-48d8-a6ae-e0ef7e2aebb0
Expand Down
Expand Up @@ -24,7 +24,7 @@ schema: null
sql: null
params: null
template_params: null
filter_select_enabled: false
filter_select_enabled: true
fetch_values_predicate: null
extra: null
uuid: 29b18573-c9d6-40bc-b8cb-f70c9a1b6244
Expand Down
Expand Up @@ -27,7 +27,7 @@ params:
database_name: examples
import_time: 1606677834
template_params: null
filter_select_enabled: false
filter_select_enabled: true
fetch_values_predicate: null
extra: null
uuid: 53d47c0c-c03d-47f0-b9ac-81225f808283
Expand Down
1 change: 1 addition & 0 deletions superset/examples/country_map.py
Expand Up @@ -79,6 +79,7 @@ def load_country_map_data(only_metadata: bool = False, force: bool = False) -> N
obj = table(table_name=tbl_name)
obj.main_dttm_col = "dttm"
obj.database = database
obj.filter_select_enabled = True
if not any(col.metric_name == "avg__2004" for col in obj.metrics):
col = str(column("2004").compile(db.engine))
obj.metrics.append(SqlMetric(metric_name="avg__2004", expression=f"AVG({col})"))
Expand Down
1 change: 1 addition & 0 deletions superset/examples/energy.py
Expand Up @@ -63,6 +63,7 @@ def load_energy(
tbl = table(table_name=tbl_name)
tbl.description = "Energy consumption"
tbl.database = database
tbl.filter_select_enabled = True

if not any(col.metric_name == "sum__value" for col in tbl.metrics):
col = str(column("value").compile(db.engine))
Expand Down
1 change: 1 addition & 0 deletions superset/examples/flights.py
Expand Up @@ -63,6 +63,7 @@ def load_flights(only_metadata: bool = False, force: bool = False) -> None:
tbl = table(table_name=tbl_name)
tbl.description = "Random set of flights in the US"
tbl.database = database
tbl.filter_select_enabled = True
db.session.merge(tbl)
db.session.commit()
tbl.fetch_metadata()
Expand Down
1 change: 1 addition & 0 deletions superset/examples/long_lat.py
Expand Up @@ -88,6 +88,7 @@ def load_long_lat_data(only_metadata: bool = False, force: bool = False) -> None
obj = table(table_name=tbl_name)
obj.main_dttm_col = "datetime"
obj.database = database
obj.filter_select_enabled = True
db.session.merge(obj)
db.session.commit()
obj.fetch_metadata()
Expand Down
1 change: 1 addition & 0 deletions superset/examples/multiformat_time_series.py
Expand Up @@ -80,6 +80,7 @@ def load_multiformat_time_series(
obj = table(table_name=tbl_name)
obj.main_dttm_col = "ds"
obj.database = database
obj.filter_select_enabled = True
dttm_and_expr_dict: Dict[str, Tuple[Optional[str], None]] = {
"ds": (None, None),
"ds2": (None, None),
Expand Down
1 change: 1 addition & 0 deletions superset/examples/paris.py
Expand Up @@ -56,6 +56,7 @@ def load_paris_iris_geojson(only_metadata: bool = False, force: bool = False) ->
tbl = table(table_name=tbl_name)
tbl.description = "Map of Paris"
tbl.database = database
tbl.filter_select_enabled = True
db.session.merge(tbl)
db.session.commit()
tbl.fetch_metadata()
1 change: 1 addition & 0 deletions superset/examples/random_time_series.py
Expand Up @@ -65,6 +65,7 @@ def load_random_time_series_data(
obj = table(table_name=tbl_name)
obj.main_dttm_col = "ds"
obj.database = database
obj.filter_select_enabled = True
db.session.merge(obj)
db.session.commit()
obj.fetch_metadata()
Expand Down
1 change: 1 addition & 0 deletions superset/examples/sf_population_polygons.py
Expand Up @@ -58,6 +58,7 @@ def load_sf_population_polygons(
tbl = table(table_name=tbl_name)
tbl.description = "Population density of San Francisco"
tbl.database = database
tbl.filter_select_enabled = True
db.session.merge(tbl)
db.session.commit()
tbl.fetch_metadata()