-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Conversation
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.
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, | ||
); |
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.
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
.
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.
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(() => { |
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: initiallyExcludedCharts
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.
Very nice! Extra points for the useComponentDidUpdate
hook :D
@graceguo-supercat Would you like to verify that this PR works properly on Airbnb environments before it's merged? |
Codecov Report
@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
@@ -115,6 +115,7 @@ describe('FilterScope', () => { | |||
fireEvent.click(screen.getByText('Scoping')); | |||
fireEvent.click(screen.getByLabelText('Apply to specific panels')); | |||
|
|||
screen.debug(undefined, 30000); |
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.
screen.debug(undefined, 30000); |
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.
👍
} | ||
}, [effect]); | ||
|
||
useEffect(() => { |
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.
Do we need this second useEffect
? https://stackoverflow.com/questions/53179075/with-useeffect-how-can-i-skip-applying-an-effect-upon-the-initial-render
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.
Good point, thanks!
…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()
…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()
…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()
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 wereAlert
andWarning
, 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
DASHBOARD_NATIVE_FILTERS
feature flagADDITIONAL INFORMATION
CC: @villebro @michael-s-molina @rusackas