feat(Native Filters): Exclude Filter Values - #33054
Conversation
|
Based on your review schedule, I'll hold off on reviewing this PR until it's marked as ready for review. If you'd like me to take a look now, comment
|
937ef73 to
b6d9fa1
Compare
|
@geido Processing your ephemeral environment request here. Action: up. More information on how to use or configure ephemeral environments |
| useEffect(() => { | ||
| const container = current?.children.item(0); | ||
| if (!container) return; | ||
|
|
||
| const childrenArray = Array.from(container.children); | ||
|
|
||
| const resizeObserver = new ResizeObserver(() => { | ||
| recalculateItemWidths(); | ||
| }); | ||
|
|
||
| childrenArray.forEach(child => resizeObserver.observe(child)); | ||
|
|
||
| return () => { | ||
| childrenArray.forEach(child => resizeObserver.unobserve(child)); | ||
| resizeObserver.disconnect(); | ||
| }; | ||
| }, [current, items.length]); | ||
|
|
||
| // callback to update item widths so that the useLayoutEffect runs whenever | ||
| // width of any of the child changes | ||
| const recalculateItemWidths = () => { | ||
| const container = current?.children.item(0); | ||
| if (container) { | ||
| const { children } = container; | ||
| const childrenArray = Array.from(children); | ||
|
|
||
| const currentWidths = childrenArray.map(child => child.getBoundingClientRect().width); | ||
|
|
||
| // Update state with new widths | ||
| setItemsWidth(currentWidths); | ||
| } | ||
| }; | ||
|
|
There was a problem hiding this comment.
I am curious as of why all of this logic came into existence? What is this trying to solve?
There was a problem hiding this comment.
Earlier the native filter width was constant at gridUnit * 41 so we needed to calculate the overflowing elements only when a native filter was added or removed... And the UseLayoutEffect hook doesnt run whenever an existing Native filter adds in or loses the Exclude filter values checkbox and also the item widths arent updated whenever we add in or remove the dynamic exclude checkbox
What happens when we remove this code ?

I have added 6 filters which looks perfectly fine because the overflowing are being calculated properly but what happens if i add exclude filters checkbox on 2 of those without these resize observers

The item widths arent updated , the overflowing elements arent recalculated and the 4th one overflows even when it should have gone inside the dropdown
When i add the resize observers back , the calculations re run and the 4th one is pushed inside the dropdown , which is expected
| return { | ||
| FilterControlContainer: HorizontalFilterControlContainer, | ||
| FormItem: HorizontalFormItem, | ||
| FormItem: (props: any) => <HorizontalFormItem {...props} showExcludeSelection={showExcludeSelection} />, |
There was a problem hiding this comment.
Is there any reasons to pass showExcludeSelection explicitly? It seems this isn't necessary for all other settings, what makes this special?
There was a problem hiding this comment.
This particular setting is when the FormItem is part of horizontal list but not in overflowing dropdown and not in Vertical list
In this case the Width of this native filter is frozen to gridUnit * 41 px but we need space for the exclude filters checkbox as well so this prop is used as Styled Components props
| <span data-test="exclude-filter-label"> | ||
| {filterBarOrientation === FilterBarOrientation.Horizontal ? t('Exclude Values') : t('Exclude Filter Values')} | ||
| </span> | ||
| <Tooltip |
There was a problem hiding this comment.
I think the InfoTooltip could work here?
There was a problem hiding this comment.
|
@geido Processing your ephemeral environment request here. Action: up. More information on how to use or configure ephemeral environments |
|
@geido Ephemeral environment spinning up at http://34.212.99.121:8080. Credentials are 'admin'/'admin'. Please allow several minutes for bootstrapping and startup. |
|
@geido Processing your ephemeral environment request here. Action: up. More information on how to use or configure ephemeral environments |
|
@geido Ephemeral environment spinning up at http://44.245.202.222:8080. Credentials are 'admin'/'admin'. Please allow several minutes for bootstrapping and startup. |
|
I see this behavior where the item fits the horizontal bar. When I resize the window down it correctly goes inside "More filters" but when I expand it back again, it is not showing back in the bar outside of the "More filters" as it should. Is this happening on master too or was it introduced in this PR? Also, you have some Cypress failures that seem related. USA.Births.Names.1.mp4 |
@geido , I was able to fix the cypress test , it was due to including current in the dependancy array of useEffect which was causing a bit re renders and interrupting with cypress operations ... Removing that from the dependancy array fixed the cypress tests However , I was not able to reproduce the bug from video from the previous comment on the Ephemeral Environment , Can you please give info about the browser that you are using as seen in the video below And it shouldnt induce a bug like this as im only attatching resizeobservers on top of elements and updating item widths , However i will try testing on different browsers as well |
|
@geido Processing your ephemeral environment request here. Action: up. More information on how to use or configure ephemeral environments |
|
@geido Ephemeral environment spinning up at http://54.188.1.207:8080. Credentials are 'admin'/'admin'. Please allow several minutes for bootstrapping and startup. |
michael-s-molina
left a comment
There was a problem hiding this comment.
Removing the Request Changes status as I'll be out for the next days.
Thanks for the work @amaannawab923! @geido @kasiazjc I'll leave the final review and tests with you. Thanks for the discussions!
Co-authored-by: Amaan Nawab <nelsondrew07@gmail.com> (cherry picked from commit be1b8d6)
Co-authored-by: Amaan Nawab <nelsondrew07@gmail.com>


SUMMARY
This pr modifies the existing Inverse Selection feature , and makes it dynamic , Now if the Inverse Selection is enabled
it will show up a Select besides the filter which has 2 values , Is and Is not
where
IS: IN
IS NOT : NOT IN
and the user can switch between these .
It is backward compatible and will be true for Existing Native Filters with Inverse Selection
screen-capture.2.webm
It works in both Vertical and horizontal filter bar
Current Native Filter Control panel untouched with just inverse Selection Checkbox , which is being used to operate the is and is not Select for dynamic control

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
TESTING INSTRUCTIONS
To test this functionality:
Edit a dashboard and open the native filters panel.
Click Add/Edit Filters and choose the dataset and column you want to filter on.
Under Filter Settings, scroll down and enable the checkbox:
✅ Inverse Selection
Save the filter.
Now in the dashboard view, you will see a new select dropdown besides the native filter with 2 options
is and is not where
IS: IN
IS NOT : NOT IN
Select a few values and have not in selected
Click Apply and verify that the charts exclude the selected values using the NOT IN logic.
ADDITIONAL INFORMATION