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

fix(FilterBar): after opening the filters-dialog, enable manual control of filters again #683

Merged
merged 2 commits into from
Sep 21, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion packages/main/src/components/FilterBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ const FilterBar: FC<FilterBarPropTypes> = forwardRef((props: FilterBarPropTypes,
return Children.toArray(children) as unknown[];
}, [toggledFilters, children]);

const prevChildren = useRef({});

const renderChildren = useCallback(() => {
const childProps = { considerGroupName, inFB: true } as any;
return safeChildren()
Expand All @@ -252,10 +254,28 @@ const FilterBar: FC<FilterBarPropTypes> = forwardRef((props: FilterBarPropTypes,
filterItemProps = filterValue(dialogItemRef, child);
}
}
if (!child.props.children)
if (!child.props.children) {
return cloneElement(child as ReactElement<any>, {
...childProps
});
}
if (
prevChildren.current?.[child.key] &&
//Input
(child.props.children?.props?.value !== prevChildren.current?.[child.key]?.value ||
//Combobox
child.props.children?.props?.filterValue !== prevChildren.current?.[child.key]?.filterValue ||
//Checkbox
child.props.children?.props?.checked !== prevChildren.current?.[child.key]?.checked ||
//Selectable
child.props.children?.props?.children?.map((item) => item.props.selected).join(',') !==
prevChildren?.current?.[child.key]?.children?.map((item) => item.props.selected).join(','))
) {
const { [child.key]: omit, ...rest } = dialogRefs;
setDialogRefs(rest);
}
prevChildren.current[child.key] = child.props.children.props;

return cloneElement(child as ReactElement<any>, {
...childProps,
children: {
Expand Down