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

chore: Preserve native filters selection after refresh #15583

Merged

Conversation

michael-s-molina
Copy link
Member

SUMMARY

Preserve native filters selection after refresh.

@jinghua-qa @junlincc @rosemarie-chiu @rusackas

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

screen-recording-2021-07-08-at-74912-am_jwOvpeQb.mp4

TESTING INSTRUCTIONS

  • Add some native filters with different types and default values
  • Change the filter values in the filter bar
  • Refresh
  • The user selection should be preserved

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
  • Introduces new feature or API
  • Removes existing feature or API

@codecov
Copy link

codecov bot commented Jul 8, 2021

Codecov Report

Merging #15583 (b0da1cc) into master (f0c0d74) will increase coverage by 0.02%.
The diff coverage is 80.85%.

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

@@            Coverage Diff             @@
##           master   #15583      +/-   ##
==========================================
+ Coverage   76.99%   77.02%   +0.02%     
==========================================
  Files         978      979       +1     
  Lines       51493    51506      +13     
  Branches     6951     6946       -5     
==========================================
+ Hits        39649    39671      +22     
+ Misses      11620    11611       -9     
  Partials      224      224              
Flag Coverage Δ
javascript 71.57% <80.85%> (+0.05%) ⬆️

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

Impacted Files Coverage Δ
...s/components/TimeColumn/TimeColumnFilterPlugin.tsx 0.00% <0.00%> (ø)
...ers/components/TimeGrain/TimeGrainFilterPlugin.tsx 0.00% <0.00%> (ø)
...board/components/nativeFilters/FilterBar/index.tsx 86.32% <81.48%> (+3.14%) ⬆️
...omponents/nativeFilters/FilterBar/Header/index.tsx 100.00% <100.00%> (+10.25%) ⬆️
...set-frontend/src/dashboard/util/getDashboardUrl.ts 100.00% <100.00%> (ø)
...ntend/src/dashboard/util/replaceUndefinedByNull.ts 100.00% <100.00%> (ø)
superset-frontend/src/dataMask/reducer.ts 67.30% <100.00%> (+2.00%) ⬆️
...et-frontend/src/filters/components/Select/index.ts 90.00% <0.00%> (-10.00%) ⬇️
... and 1 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 f0c0d74...b654aee. Read the comment docs.

@michael-s-molina michael-s-molina marked this pull request as draft July 8, 2021 18:57
@michael-s-molina michael-s-molina marked this pull request as ready for review July 9, 2021 15:02
@junlincc junlincc added the dashboard:native-filters Related to the native filters of the Dashboard label Jul 9, 2021
@kgabryje
Copy link
Member

/testenv up FEATURE_DASHBOARD_NATIVE_FILTERS=true

@github-actions
Copy link
Contributor

@kgabryje Ephemeral environment spinning up at http://52.27.157.190:8080. Credentials are admin/admin. Please allow several minutes for bootstrapping and startup.

*/
import { cloneDeep } from 'lodash';

export default function replaceUndefinedByNull(object: Object) {
Copy link
Member

Choose a reason for hiding this comment

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

We run cloneDeep on every level of recursion - I think doing it once, in the first level of recursion, would be enough. However, I'd like to propose a different solution:

const replacer = (key, val) => {
  if (val === undefined) return null;
  return val;
}

const replaceUndefinedByNull = (object) => JSON.parse(JSON.stringify(object, replacer));

I'm not sure if it would be faster than your solution (we could time it to verify), but I think it's easier to understand. WDYT?

Copy link
Member Author

@michael-s-molina michael-s-molina Jul 12, 2021

Choose a reason for hiding this comment

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

I totally agree with the unnecessary cloneDeep. Will fix that.

About the JSON serialization/deserialization I prefer the cloneDeep because it's faster. We already have benchmarks on this topic:
https://stackoverflow.com/questions/122102/what-is-the-most-efficient-way-to-deep-clone-an-object-in-javascript
https://jsben.ch/bWfk9

@@ -128,6 +131,7 @@ const dataMaskReducer = produce(
[],
cleanState,
draft,
undefined,
Copy link
Member

@kgabryje kgabryje Jul 12, 2021

Choose a reason for hiding this comment

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

Why do we need pass undefined here explicitely?

Copy link
Member Author

Choose a reason for hiding this comment

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

This was a result of a previous refactor where I had an additional parameter but ended up reverting. Will remove it. Nice catch!

@kgabryje
Copy link
Member

2 issues that I noticed:

  1. When we open a dashboard with native filter preselected in the URL, the chart requests are done twice - first time without the native filter and 2nd time with the native filter.
  2. When we open a dashboard with native filter preselected in the URL, any change to the native filter is applied instantly instead of waiting until user clicks apply
Screen.Recording.2021-07-12.at.12.21.20.mov

@michael-s-molina michael-s-molina added this to In progress in Native dashboard filters via automation Jul 12, 2021
@michael-s-molina
Copy link
Member Author

@kgabryje Fixed the issues.

@michael-s-molina
Copy link
Member Author

/testenv up FEATURE_DASHBOARD_NATIVE_FILTERS=true

@github-actions
Copy link
Contributor

@michael-s-molina Ephemeral environment spinning up at http://34.215.175.94:8080. Credentials are admin/admin. Please allow several minutes for bootstrapping and startup.

@michael-s-molina
Copy link
Member Author

/testenv up FEATURE_DASHBOARD_NATIVE_FILTERS=true

@github-actions
Copy link
Contributor

@michael-s-molina Ephemeral environment spinning up at http://34.214.105.118:8080. Credentials are admin/admin. Please allow several minutes for bootstrapping and startup.

@rusackas rusackas requested a review from suddjian July 13, 2021 17:26
Copy link
Member

@suddjian suddjian left a comment

Choose a reason for hiding this comment

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

Approved with non-blocking test request, thanks!

return result;
}

export default function replaceUndefinedByNull(object: Object) {
Copy link
Member

@suddjian suddjian Jul 13, 2021

Choose a reason for hiding this comment

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

Tests for this would be nice

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes! Will do it in a follow-up PR. Thanks for the review!

@michael-s-molina michael-s-molina merged commit e6bbca3 into apache:master Jul 13, 2021
Native dashboard filters automation moved this from In progress to Done Jul 13, 2021
@github-actions
Copy link
Contributor

Ephemeral environment shutdown and build artifacts deleted.

cccs-RyanS pushed a commit to CybercentreCanada/superset that referenced this pull request Dec 17, 2021
QAlexBall pushed a commit to QAlexBall/superset that referenced this pull request Dec 29, 2021
cccs-rc pushed a commit to CybercentreCanada/superset that referenced this pull request Mar 6, 2024
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 1.3.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 size/L v1.3 🚢 1.3.0
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

[native-filters]filter scoping select don't stick after refresh
6 participants