Skip to content

Commit

Permalink
fix: Reordering native filters ignored by filter bar (apache#22362)
Browse files Browse the repository at this point in the history
(cherry picked from commit da64fa2)
  • Loading branch information
kgabryje authored and jinghua-qa committed Dec 10, 2022
1 parent aab1d0e commit 57c7a44
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ const DropdownContainer = forwardRef(
visible={popoverVisible}
onVisibleChange={visible => setPopoverVisible(visible)}
placement="bottom"
destroyTooltipOnHide
>
<Button
buttonStyle="secondary"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,15 @@ const FilterControls: FC<FilterControlsProps> = ({
const showCollapsePanel = dashboardHasTabs && filtersWithValues.length > 0;

const renderer = useCallback(
({ id }: Filter | Divider) => {
const index = filtersWithValues.findIndex(f => f.id === id);
({ id }: Filter | Divider, index: number | undefined) => {
const filterIndex = filtersWithValues.findIndex(f => f.id === id);
const key = index ?? id;
return (
// Empty text node is to ensure there's always an element preceding
// the OutPortal, otherwise react-reverse-portal crashes
<React.Fragment key={id}>
<React.Fragment key={key}>
{'' /* eslint-disable-line react/jsx-curly-brace-presence */}
<OutPortal node={portalNodes[index]} inView />
<OutPortal node={portalNodes[filterIndex]} inView />
</React.Fragment>
);
},
Expand All @@ -127,7 +128,7 @@ const FilterControls: FC<FilterControlsProps> = ({

const items = useMemo(
() =>
filtersInScope.map(filter => ({
filtersInScope.map((filter, index) => ({
id: filter.id,
element: (
<div
Expand All @@ -136,7 +137,7 @@ const FilterControls: FC<FilterControlsProps> = ({
flex-shrink: 0;
`}
>
{renderer(filter)}
{renderer(filter, index)}
</div>
),
})),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { FiltersOutOfScopeCollapsible } from '../FiltersOutOfScopeCollapsible';
export interface FiltersDropdownContentProps {
filtersInScope: (Filter | Divider)[];
filtersOutOfScope: (Filter | Divider)[];
renderer: (filter: Filter | Divider) => ReactNode;
renderer: (filter: Filter | Divider, index: number) => ReactNode;
showCollapsePanel?: boolean;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { AntdCollapse } from 'src/components';

export interface FiltersOutOfScopeCollapsibleProps {
filtersOutOfScope: (Filter | Divider)[];
renderer: (filter: Filter | Divider) => ReactNode;
renderer: (filter: Filter | Divider, index: number) => ReactNode;
hasTopMargin?: boolean;
horizontalOverflow?: boolean;
}
Expand Down

0 comments on commit 57c7a44

Please sign in to comment.