Skip to content

Commit

Permalink
@Dosant code review
Browse files Browse the repository at this point in the history
  • Loading branch information
Liza K committed Feb 3, 2020
1 parent 73bb9fa commit 8a58878
Showing 1 changed file with 10 additions and 17 deletions.
27 changes: 10 additions & 17 deletions src/plugins/data/public/ui/search_bar/create_search_bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,10 @@ export function createSearchBar({ core, storage, data }: StatefulSearchBarDeps)
const fetchSavedQuery = async () => {
if (props.savedQueryId) {
const newSavedQuery = await savedQueries.getSavedQuery(props.savedQueryId);
if (newSavedQuery) setSavedQuery(newSavedQuery);
// Make sure we set the saved query to the most recent one
if (newSavedQuery && newSavedQuery.id === props.savedQueryId) {
setSavedQuery(newSavedQuery);
}
}
};
fetchSavedQuery();
Expand All @@ -199,56 +202,46 @@ export function createSearchBar({ core, storage, data }: StatefulSearchBarDeps)
// timerange
const [timeRange, setTimerange] = useState(timefilter.timefilter.getTime());
useEffect(() => {
let isSubscribed = true;
const subscriptions = new Subscription();

subscriptions.add(
timefilter.timefilter.getRefreshIntervalUpdate$().subscribe({
next: () => {
if (isSubscribed) {
const newRefreshInterval = timefilter.timefilter.getRefreshInterval();
setRefreshInterval(newRefreshInterval.value);
setRefreshPaused(newRefreshInterval.pause);
}
const newRefreshInterval = timefilter.timefilter.getRefreshInterval();
setRefreshInterval(newRefreshInterval.value);
setRefreshPaused(newRefreshInterval.pause);
},
})
);

subscriptions.add(
timefilter.timefilter.getTimeUpdate$().subscribe({
next: () => {
if (isSubscribed) {
setTimerange(timefilter.timefilter.getTime());
}
setTimerange(timefilter.timefilter.getTime());
},
})
);

return () => {
isSubscribed = false;
subscriptions.unsubscribe();
};
}, [timefilter.timefilter]);

// filters
const [filters, setFilters] = useState(filterManager.getFilters());
useEffect(() => {
let isSubscribed = true;
const subscriptions = new Subscription();

subscriptions.add(
filterManager.getUpdates$().subscribe({
next: () => {
if (isSubscribed) {
const newFilters = filterManager.getFilters();
setFilters(newFilters);
}
const newFilters = filterManager.getFilters();
setFilters(newFilters);
},
})
);

return () => {
isSubscribed = false;
subscriptions.unsubscribe();
};
}, [filterManager]);
Expand Down

0 comments on commit 8a58878

Please sign in to comment.