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(native-filters): Set default scope by filters' and charts' datasets #15302

Merged
merged 11 commits into from
Jun 24, 2021

Conversation

kgabryje
Copy link
Member

SUMMARY

When new native filter was created, "Apply to all panels" scope was always selected by default. In the case of dashboards that have charts built on multiple datasets (e.g. Slack Dashboard from test data), filter that uses given dataset usually is incompatible and does not have any effect on charts that use a different dataset. This PR implements "smarter" selection of default scope - when user created a new filter, charts that use different dataset than the filter will be unselected. Changing dataset updates the default scoping tree, but only if the user didn't make any changes there - if the user changes selection in the scoping tree and then changes dataset, we don't update the tree automatically.
The feature takes effect only on new filters. Once a filter is saved, we don't apply default selection to the scopong tree upon editing the filter and its dataset.
Next to "incompatible" charts I added an icon with a tooltip that explains why those charts were not selected by default. I used Info icon for that purpose. Other icons that I considered were Alert and Warning , but since potentially a lot of those icons can appear next to each other, I didn't want to use something too "aggressive". I'd greatly appreciate design input/approval! CC @mihir174.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Screen.Recording.2021-06-22.at.19.34.14.mov

TESTING INSTRUCTIONS

  1. Enable DASHBOARD_NATIVE_FILTERS feature flag
  2. Create a dashboard with charts that use the same dataset.
  3. Create a native filter and verify that "Apply to all panels" scope is selected by default
  4. Create a dashboard with charts that use multiple datasets
  5. Create a native filter, choose a dataset and verify that only the charts that use that dataset are in scope by default.
  6. Change dataset, verify that scope tree got updated so that charts that use the new dataset are now in scope.
  7. Modify the scope, change dataset and verify that the scope didn't change.
  8. Save the filter, edit it, change its dataset, verify that the scoe didn't change.

ADDITIONAL INFORMATION

CC: @villebro @michael-s-molina @rusackas

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.

LGTM - a few minor readability improvement ideas. Also, should we reword this, especially if it will end up applying to charts referencing a different dataset, in which case the info icon could be helpful (maybe even stating how many charts are refefrencing a different dataset)?

image

Comment on lines 60 to 67
const initialScope = scope || getDefaultScopeValue(chartId);
const initialScoping = isScopingAll(initialScope, chartId)
? Scoping.all
: Scoping.specific;
const [initialScope] = useState(
scope || getDefaultScopeValue(chartId, initiallyExcludedCharts),
);
const [initialScoping] = useState(
isScopingAll(initialScope, chartId) ? Scoping.all : Scoping.specific,
);
Copy link
Member

Choose a reason for hiding this comment

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

This isn't directly related to this PR, but it confused me while reading this code: having two props called initialScope and initialScoping right next to each other feels very ambiguous. If changing this to something slightly more specific doesn't lead down a huge rabbit hole, I'd opt for renaming Scoping to ScopingType and consequently initialScoping to initialScopingType, perhaps even initialScope to initialChartScope.

Copy link
Member Author

Choose a reason for hiding this comment

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

Totally agree, I feel like I spend more time trying to wrap my head around difference between those 2 than actual developing. I'll change that in this PR

@@ -580,6 +592,28 @@ const FiltersConfigForm = (
setActiveFilterPanelKey(activeFilterPanelKey);
}, [hasCheckedAdvancedControl]);

const initiallyExcluded = useMemo(() => {
Copy link
Member

Choose a reason for hiding this comment

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

nit: initiallyExcludedCharts

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.

Very nice! Extra points for the useComponentDidUpdate hook :D

@kgabryje
Copy link
Member Author

@graceguo-supercat Would you like to verify that this PR works properly on Airbnb environments before it's merged?

@codecov
Copy link

codecov bot commented Jun 23, 2021

Codecov Report

Merging #15302 (cd6232a) into master (cef3dc0) will decrease coverage by 0.01%.
The diff coverage is 87.17%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #15302      +/-   ##
==========================================
- Coverage   77.23%   77.22%   -0.02%     
==========================================
  Files         973      975       +2     
  Lines       50438    50525      +87     
  Branches     6175     6201      +26     
==========================================
+ Hits        38957    39017      +60     
- Misses      11276    11301      +25     
- Partials      205      207       +2     
Flag Coverage Δ
javascript 71.79% <87.17%> (-0.02%) ⬇️

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

Impacted Files Coverage Δ
...nd/src/common/hooks/useComponentDidUpdate/index.ts 0.00% <0.00%> (ø)
...ilterScopingModal/CrossFilterScopingForm/index.tsx 84.61% <ø> (ø)
...ConfigModal/FiltersConfigForm/FilterScope/state.ts 95.65% <66.66%> (-4.35%) ⬇️
...odal/FiltersConfigForm/FilterScope/ScopingTree.tsx 90.62% <80.00%> (-5.03%) ⬇️
...ConfigModal/FiltersConfigForm/FilterScope/utils.ts 95.89% <81.81%> (-2.62%) ⬇️
...onfigModal/FiltersConfigForm/FiltersConfigForm.tsx 69.97% <90.00%> (-0.03%) ⬇️
...odal/FiltersConfigForm/FilterScope/FilterScope.tsx 88.88% <92.00%> (+2.68%) ⬆️
...oks/useComponentDidUpdate/useComponentDidUpdate.ts 100.00% <100.00%> (ø)
...ConfigModal/FiltersConfigForm/FilterScope/types.ts 100.00% <100.00%> (ø)
...veFilters/FilterBar/FilterControls/FilterValue.tsx 66.99% <0.00%> (-4.15%) ⬇️
... and 11 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 cef3dc0...cd6232a. Read the comment docs.

@@ -115,6 +115,7 @@ describe('FilterScope', () => {
fireEvent.click(screen.getByText('Scoping'));
fireEvent.click(screen.getByLabelText('Apply to specific panels'));

screen.debug(undefined, 30000);
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
screen.debug(undefined, 30000);

Copy link
Member Author

Choose a reason for hiding this comment

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

👍

}
}, [effect]);

useEffect(() => {
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point, thanks!

@kgabryje kgabryje merged commit f0b6419 into apache:master Jun 24, 2021
@junlincc junlincc added dashboard:native-filters Related to the native filters of the Dashboard need:qa-review Requires QA review labels Jul 13, 2021
@junlincc junlincc added this to In progress in Native dashboard filters via automation Jul 13, 2021
@junlincc junlincc moved this from In progress to Done in Native dashboard filters Jul 13, 2021
cccs-RyanS pushed a commit to CybercentreCanada/superset that referenced this pull request Dec 17, 2021
…ets (apache#15302)

* feat(native-filters): Set default scope by filter's and charts datasets

* Fix undefined error

* Use JSON.stringify in dependency array

* Fix lint issue

* Lock scope after switching radio buttons

* Fix weird eslint issue

* Change prop names

* Implement useComponentDidUpdate

* Fix lint

* Refactor useComponentDidUpdate

* Remove screen.debug()
QAlexBall pushed a commit to QAlexBall/superset that referenced this pull request Dec 29, 2021
…ets (apache#15302)

* feat(native-filters): Set default scope by filter's and charts datasets

* Fix undefined error

* Use JSON.stringify in dependency array

* Fix lint issue

* Lock scope after switching radio buttons

* Fix weird eslint issue

* Change prop names

* Implement useComponentDidUpdate

* Fix lint

* Refactor useComponentDidUpdate

* Remove screen.debug()
cccs-rc pushed a commit to CybercentreCanada/superset that referenced this pull request Mar 6, 2024
…ets (apache#15302)

* feat(native-filters): Set default scope by filter's and charts datasets

* Fix undefined error

* Use JSON.stringify in dependency array

* Fix lint issue

* Lock scope after switching radio buttons

* Fix weird eslint issue

* Change prop names

* Implement useComponentDidUpdate

* Fix lint

* Refactor useComponentDidUpdate

* Remove screen.debug()
@mistercrunch mistercrunch added the 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels label 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 need:qa-review Requires QA review size/L 🚢 1.3.0
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

[native-filters]upscope chart if the filter uses a different dataset?
5 participants