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

refactor(native-filters): update dataMask and ExtraFormData schema #13983

Merged
merged 24 commits into from
Apr 15, 2021

Conversation

simcha90
Copy link
Contributor

@simcha90 simcha90 commented Apr 7, 2021

SUMMARY

This PR implements native filter and cross filter API simplification efforts introduced in apache-superset/superset-ui#1040 and apache-superset/superset-ui#1053 . The following changes are done:

  1. setDataMask hook now has new structure:
{
   filterState: { value: any, ...otherProps: any }
   ownState: { ...otherProps: any }
   extraFormData: ExtraFormData
}
  1. Nested append_form_data and override_form_data fields in ExtraFormData type are moved up one level into the main filter object
  2. currentValue removed from formData now it passed in props.filterState.value
  3. In SuperChart injected ownState and filterState
  4. Fixed bug when remove cross filter from dashboard it's wasn't from dashboard metadata
  5. Fixed bug that filter_select was attached to filterBoxes
  6. Fixed bug that when user just added cross filter without setting, it's scoping filter not appeared in filter badge
  7. migrate old filter set metadata to new format
  8. upgrade Python code for legacy charts that depend on viz.py

Affected areas:

  1. Native filters
  2. Cross filters
  3. Own state of charts
  4. Filter sets

TEST PLAN

All frontend + backend unit tests have been updated, and a test for the migration has been added to ensure that both up and down migrations produce expected results.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided: only affects dashboards with filter sets. Will only affect environments running the DASHBOARD_NATIVE_FILTERS_SET feature flag
  • Introduces new feature or API
  • Removes existing feature or API

@amitmiran137
Copy link
Member

LGTM, Let's see what CI reveals

@amitmiran137 amitmiran137 requested a review from villebro April 7, 2021 06:22
@pull-request-size pull-request-size bot added size/XL and removed size/L labels Apr 8, 2021
@simcha90 simcha90 changed the title refactor(native-filters): Updates usage of ownFilters to ownState refactor(native-filters): Updates usage of dataMask structure Apr 8, 2021
simcha90 added 2 commits April 8, 2021 11:41
� Conflicts:
�	superset-frontend/src/explore/components/DataTablesPane/index.tsx
� Conflicts:
�	superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterSets/utils/index.ts
�	superset-frontend/src/filters/components/Select/SelectFilterPlugin.tsx
� Conflicts:
�	superset-frontend/src/filters/components/Select/SelectFilterPlugin.tsx
�	superset-frontend/src/filters/components/Select/transformProps.ts
�	superset-frontend/src/filters/components/Select/types.ts
@villebro villebro changed the title refactor(native-filters): Updates usage of dataMask structure [WIP] refactor(native-filters): Updates usage of dataMask structure Apr 12, 2021
@villebro
Copy link
Member

FYI: marking this as WIP until all superset-ui dependencies have been resolved

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 comments. During testing I also noticed that filter sets don't seem to work:
filter-set-refactor

superset-frontend/src/dashboard/actions/dashboardState.js Outdated Show resolved Hide resolved
superset-frontend/src/dataMask/types.ts Show resolved Hide resolved
@simcha90 simcha90 requested a review from a team as a code owner April 12, 2021 10:34
@codecov
Copy link

codecov bot commented Apr 12, 2021

Codecov Report

Merging #13983 (28aa87a) into master (68e11cd) will decrease coverage by 0.07%.
The diff coverage is 60.86%.

❗ Current head 28aa87a differs from pull request most recent head d493bb8. Consider uploading reports for the commit d493bb8 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master   #13983      +/-   ##
==========================================
- Coverage   79.93%   79.85%   -0.08%     
==========================================
  Files         943      943              
  Lines       47772    47745      -27     
  Branches     6019     6050      +31     
==========================================
- Hits        38185    38126      -59     
- Misses       9468     9497      +29     
- Partials      119      122       +3     
Flag Coverage Δ
cypress 56.29% <57.14%> (-0.14%) ⬇️
hive 80.48% <90.47%> (-0.01%) ⬇️
javascript 70.26% <41.42%> (+0.06%) ⬆️
mysql 80.75% <90.47%> (-0.01%) ⬇️
postgres 80.78% <90.47%> (-0.01%) ⬇️
presto ?
python 81.19% <90.47%> (-0.16%) ⬇️
sqlite 80.39% <90.47%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
superset-frontend/src/chart/Chart.jsx 64.81% <ø> (ø)
.../src/dashboard/components/gridComponents/Chart.jsx 86.59% <ø> (ø)
...ilters/FilterBar/FilterControls/FilterControls.tsx 94.73% <ø> (-0.27%) ⬇️
...nativeFilters/FilterBar/FilterSets/EditSection.tsx 80.00% <ø> (ø)
...perset-frontend/src/dashboard/containers/Chart.jsx 100.00% <ø> (ø)
superset-frontend/src/dashboard/reducers/types.ts 0.00% <ø> (ø)
superset-frontend/src/dataMask/types.ts 100.00% <ø> (ø)
...tend/src/explore/components/ExploreChartHeader.jsx 84.21% <ø> (ø)
...ntend/src/explore/components/ExploreChartPanel.jsx 82.60% <ø> (ø)
...src/explore/components/controls/VizTypeControl.jsx 92.06% <0.00%> (ø)
... and 56 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 68e11cd...d493bb8. Read the comment docs.

� Conflicts:
�	superset-frontend/spec/javascripts/dashboard/fixtures/mockNativeFilters.ts
�	superset-frontend/src/dashboard/actions/hydrate.js
�	superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterSets/FiltersHeader.tsx
�	superset-frontend/src/dashboard/components/nativeFilters/FilterBar/Header/index.tsx
�	superset-frontend/src/dashboard/util/activeAllDashboardFilters.ts
@github-actions
Copy link
Contributor

⚠️ @simcha90 Your base branch master has just also updated superset/migrations.

Please consider rebasing your branch to avoid db migration conflicts.

@villebro villebro changed the title [WIP] refactor(native-filters): Updates usage of dataMask structure refactor(native-filters): update dataMask and ExtraFormData schema Apr 15, 2021
Comment on lines -1075 to -1076
applied_time_extras = form_data.get("applied_time_extras", {})
form_data["applied_time_extras"] = applied_time_extras
Copy link
Member

@villebro villebro Apr 15, 2021

Choose a reason for hiding this comment

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

applied_time_extras are no longer needed for filter indicators

@villebro villebro added the risk:db-migration PRs that require a DB migration label Apr 15, 2021
Copy link
Member

@dpgaspar dpgaspar left a comment

Choose a reason for hiding this comment

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

Looks good, left a couple of comments

"time_range": "time_range",
}

EXTRA_FORM_DATA_OVERRIDE_EXTRA_KEYS = [
Copy link
Member

Choose a reason for hiding this comment

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

nit: we could use a set here



def upgrade():
bind = op.get_bind()
Copy link
Member

Choose a reason for hiding this comment

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

There's some complexity here, would be nice to place the entire logic here: https://github.com/apache/superset/tree/master/superset/migrations/shared
Then add some tests to assert that the migrations works has expected

#13351

@kgabryje
Copy link
Member

LGTM! It seems that there's still the old structure used in findExistingFilterSet.test.ts

Copy link
Member

@zhaoyongjie zhaoyongjie left a comment

Choose a reason for hiding this comment

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

LGTM! Added some suggestions.

Comment on lines +176 to +182
dashboards = (
session.query(Dashboard)
.filter(Dashboard.json_metadata.like('%"filter_sets_configuration"%'))
.all()
)
changed_filter_sets, changed_filters = 0, 0
for dashboard in dashboards:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
dashboards = (
session.query(Dashboard)
.filter(Dashboard.json_metadata.like('%"filter_sets_configuration"%'))
.all()
)
changed_filter_sets, changed_filters = 0, 0
for dashboard in dashboards:
dashboards = (
session.query(Dashboard)
.filter(Dashboard.json_metadata.like('%"filter_sets_configuration"%'))
)
changed_filter_sets, changed_filters = 0, 0
for dashboard in dashboards.yield_per(100):

Copy link
Member

Choose a reason for hiding this comment

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

Thanks - this is a great pattern! As this is behind a FF, I don't expect we'll have lots of these dashboards. Also in the interest of CI time and unblocking other PRs that are dependent on this I think I'll just merge now, but I can open up a follow up PR to implement this.

Comment on lines +212 to +218
dashboards = (
session.query(Dashboard)
.filter(Dashboard.json_metadata.like('%"filter_sets_configuration"%'))
.all()
)
changed_filter_sets, changed_filters = 0, 0
for dashboard in dashboards:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
dashboards = (
session.query(Dashboard)
.filter(Dashboard.json_metadata.like('%"filter_sets_configuration"%'))
.all()
)
changed_filter_sets, changed_filters = 0, 0
for dashboard in dashboards:
dashboards = (
session.query(Dashboard)
.filter(Dashboard.json_metadata.like('%"filter_sets_configuration"%'))
)
changed_filter_sets, changed_filters = 0, 0
for dashboard in dashboards.yield_per(100):

@villebro villebro merged commit 8ef572a into apache:master Apr 15, 2021
@junlincc junlincc added dashboard:native-filters Related to the native filters of the Dashboard risk:migration High risk PR, wait for(at least) a week to deploy after merging risk:refactor High risk as it involves large refactoring work and removed risk:migration High risk PR, wait for(at least) a week to deploy after merging labels Apr 15, 2021
QAlexBall pushed a commit to QAlexBall/superset that referenced this pull request Dec 29, 2021
…pache#13983)

* refactor: updates usage of `ownFilters` to `ownState`

* refactor: update dataMask (final)

* lint: fix lint

* refactor: revert feat

* fix: fix missed chart configuration

* add filter set migration

* apply new changes

* fix migration revision

* update migration

* fix jest mock

* js lint

* fix test types

* update tests and types

* remove append_form_data from tests

* fix findExistingFilterSet tests

* add migration test

Co-authored-by: Ville Brofeldt <ville.v.brofeldt@gmail.com>
@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 dashboard:native-filters Related to the native filters of the Dashboard risk:db-migration PRs that require a DB migration risk:refactor High risk as it involves large refactoring work size/XXL v1.2 🚢 1.2.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants