update default filters
Summary: Searchbar didn't update the filters when new default filters were added. This adds the new filters when they are added to the searchbar. Existing filters are not touched. Reviewed By: passy Differential Revision: D12999885 fbshipit-source-id: 51d9a1579724be2098b54161b39a0769180fb343
This commit is contained in:
committed by
Facebook Github Bot
parent
bf7c35387c
commit
274d71cb2f
@@ -107,7 +107,7 @@ const Searchable = (
|
||||
placeholder: 'Search...',
|
||||
};
|
||||
|
||||
state = {
|
||||
state: State = {
|
||||
filters: this.props.defaultFilters || [],
|
||||
focusedToken: -1,
|
||||
searchTerm: '',
|
||||
@@ -176,6 +176,21 @@ const Searchable = (
|
||||
if (this.props.onFilterChange != null) {
|
||||
this.props.onFilterChange(this.state.filters);
|
||||
}
|
||||
} else if (prevProps.defaultFilters !== this.props.defaultFilters) {
|
||||
const mergedFilters = [...this.state.filters];
|
||||
this.props.defaultFilters.forEach((defaultFilter: Filter) => {
|
||||
const filterIndex = mergedFilters.findIndex(
|
||||
(f: Filter) => f.key === defaultFilter.key,
|
||||
);
|
||||
if (filterIndex > -1) {
|
||||
mergedFilters[filterIndex] = defaultFilter;
|
||||
} else {
|
||||
mergedFilters.push(defaultFilter);
|
||||
}
|
||||
});
|
||||
this.setState({
|
||||
filters: mergedFilters,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user