Skip to content

Commit

Permalink
Add cleanup in FilterItem component
Browse files Browse the repository at this point in the history
  • Loading branch information
Maja Grubic committed Dec 21, 2020
1 parent e08a704 commit f68292d
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/plugins/data/public/ui/filter_bar/filter_item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,27 @@ export function FilterItem(props: Props) {

useEffect(() => {
const index = props.filter.meta.index;
let isSubscribed = true;
if (index) {
getIndexPatterns()
.get(index)
.then((indexPattern) => {
setIndexPatternExists(!!indexPattern);
if (isSubscribed) {
setIndexPatternExists(!!indexPattern);
}
})
.catch(() => {
setIndexPatternExists(false);
if (isSubscribed) {
setIndexPatternExists(false);
}
});
} else {
} else if (isSubscribed) {
// Allow filters without an index pattern and don't validate them.
setIndexPatternExists(true);
}
return () => {
isSubscribed = false;
};
}, [props.filter.meta.index]);

function handleBadgeClick(e: MouseEvent<HTMLInputElement>) {
Expand Down

0 comments on commit f68292d

Please sign in to comment.