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: Implement drag and drop columns for filters #13340

Merged
merged 12 commits into from
Mar 7, 2021

Conversation

kgabryje
Copy link
Member

@kgabryje kgabryje commented Feb 25, 2021

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

  • Has associated issue:
  • Changes UI
  • Requires DB Migration.
  • Confirm DB Migration upgrade and downgrade tested.
  • Introduces new feature or API
  • Removes existing feature or API

@villebro villebro self-requested a review February 25, 2021 16:53
@junlincc junlincc added the explore:control Related to the controls panel of Explore label Feb 25, 2021
@ktmud
Copy link
Member

ktmud commented Feb 25, 2021

In current state it's difficult to review, so I suggest delaying reviews until the original PR is merged.

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.

@junlincc junlincc added explore:drag&drop Related to drag&drop in Explore and removed explore:control Related to the controls panel of Explore labels Feb 25, 2021
@kgabryje
Copy link
Member Author

you can also create a PR to @zhaoyongjie 's fork/branch and tag us for review over there.

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.

@zhaoyongjie
Copy link
Member

zhaoyongjie commented Feb 26, 2021

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

  1. columns (can shift between)
  2. Level columns(AKA hierarchy) (there may be folding between levels, can not shift between)
  3. columns set(such as generate case...when... clause)

For filter selector, Superset is now just a simple dimension filter

  1. If we want to drag saved_metric to generate a having clause, we need to enable metic drop to filter
  2. columns, or top level of hierarchy
  3. Drag into different types of columns should have different filter

For metric selector

  1. columns ( generate ad-hoc metric)
  2. saved_metric

suggestions are welcome

@ktmud
Copy link
Member

ktmud commented Feb 26, 2021

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).

import { DatasourcePanelDndItem } from '../../DatasourcePanel/types';

export const GroupByItemType = 'groupByItem';
export const FilterItemType = 'filterItemType';
Copy link
Member

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

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.

@kgabryje
Copy link
Member Author

kgabryje commented Mar 3, 2021

Update:
New feature - drag and drop saved metrics from Datasource Panel and adhoc metrics to filters box to quickly create a filter based on a metric.
Fix typescript errors.
@ktmud thank you for your suggestions - I applied your solution to use enum for dnd types; making OptionSelector more generic is in progress
To test the new changes, please pull and link apache-superset/superset-ui#988
CC @villebro @zhaoyongjie

Copy link
Member

@villebro villebro left a 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.

Comment on lines 23 to 40
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',
}
Copy link
Member

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

Copy link
Member Author

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;
Copy link
Member

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)?

Copy link
Member Author

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

@villebro
Copy link
Member

villebro commented Mar 7, 2021

Merging this to unblock other PRs requiring new features from superset-ui (let's address any potential review comments in a follow-up PR)

@villebro villebro merged commit 7b370e6 into apache:master Mar 7, 2021
allanco91 pushed a commit to allanco91/superset that referenced this pull request May 21, 2021
* 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
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 1.2.0 labels Mar 12, 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 explore:drag&drop Related to drag&drop in Explore size/XL 🚢 1.2.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants