-
Notifications
You must be signed in to change notification settings - Fork 14k
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: Implement drag and drop columns for filters #13340
Conversation
Can we create a feature branch? Not sure if this goes against the Apache way, but maybe you can also create a PR to @zhaoyongjie 's fork/branch and tag us for review over there. |
dc34ade
to
c215550
Compare
Creating a PR to an original branch sounds good, I'll do that next time. This branch is already rebased on master as Yongjie's PR was merged, so it's ready for review. |
I personally suggest not to make generic components now. The main reason is that these components are completely inconsistent in function, and we should not do such maintenance that increases complexity. For dimension(group by) selector
For filter selector, Superset is now just a simple dimension filter
For metric selector
suggestions are welcome |
There're definitely certain things you can abstract away for all these. The basic interactions are the same, it's just what happens after you drop is different. It should be possible to let each different drop item and target extend from the same base class or React hook. At the very least, DnD item types should be managed in a global registry (eg. as an Enum). |
c215550
to
ad66337
Compare
import { DatasourcePanelDndItem } from '../../DatasourcePanel/types'; | ||
|
||
export const GroupByItemType = 'groupByItem'; | ||
export const FilterItemType = 'filterItemType'; |
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.
https://github.com/apache/superset/pull/13210/files#r583265905
I'd imagine you will be adding more types in the future, so it could make sense to make this an enum.
@@ -19,26 +19,26 @@ | |||
import { ColumnMeta } from '@superset-ui/chart-controls'; | |||
|
|||
export class OptionSelector { |
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.
https://github.com/apache/superset/pull/13210/files#r583272323
Here's one way to make this generic so that adhoc columns/metrics can also be selected. But of course you can also make sure each adhoc item have a unique id/label and use is as the option key.
ad66337
to
2df1f79
Compare
Update: |
9da4682
to
0bd133e
Compare
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.
A few non-blocking comments. Tested all different scenarios I could think of (dragging column, saved metric, calculated column and adhoc metric into the filter control), and all worked beautifully. Code looks super solid but due to the size of the PR something might have gone unnoticed. However, since this is behind a FF and I wasn't able to notice any problems with the FF turned off, I think this is good to go.
export enum DndItemType { | ||
// an existing column in table | ||
column = 'column', | ||
// a selected column option in ColumnSelectControl | ||
columnOption = 'columnOption', | ||
// an adhoc column option in ColumnSelectControl | ||
adhocColumnOption = 'adhocColumn', | ||
|
||
// a saved metric | ||
metric = 'metric', | ||
// a selected saved metric in MetricsControl | ||
metricOption = 'metricOption', | ||
// an adhoc metric option in MetricsControl | ||
adhocMetricOption = 'adhocMetric', | ||
|
||
// an adhoc filter option | ||
filterOption = 'filterOption', | ||
} |
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.
nit: I believe the common convention is to use PascalCase for enum names:
https://www.typescriptlang.org/docs/handbook/enums.html
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.
👍
import { DndItemType } from '../../DndItemType'; | ||
|
||
const isDictionaryForAdhocFilter = (value: FilterOptionValueType) => | ||
value && !(value instanceof AdhocFilter) && value.expressionType; |
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 assume checking for value here isn't necessary as value
is always an object (=always truthy)?
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 removed value
and used value?.expressionType
instead, just in case it was null or undefined
Merging this to unblock other PRs requiring new features from |
* Implement DnD feature for filters * minor refactor * Fix types * Fix undefined error * Refactor * Fix ts errors * Fix conflicting dnd types * Bump superset-ui packages * Change DndItemType case to PascalCase * Remove redundant null check * Fix * Fix csrf mock api call
SUMMARY
The goal was to implement creating adhoc filters by dragging columns from datasource panel to filters control. Also, I attempted to make Yongjie's (#13210) implementation more generic, so that we can reuse components with filters and, in the future, with metrics controls.
CC: @villebro @zhaoyongjie @ktmud @junlincc
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Screen.Recording.2021-02-25.at.16.46.43.mov
TEST PLAN
Pull apache-superset/superset-ui#988, link chart-controls to Superset, set
ENABLE_EXPLORE_DRAG_AND_DROP
feature flag.ADDITIONAL INFORMATION