Skip to content

Commit

Permalink
Don't refetch when disabled filters change
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasolson committed Jul 29, 2019
1 parent 11480fb commit a618a3e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,14 @@ function VisEditor(
// update the searchSource when filters update
const filterUpdateSubscription = subscribeWithScope($scope, queryFilter.getUpdates$(), {
next: () => {
$scope.filters = queryFilter.getFilters();
const filters = queryFilter.getFilters();
const isFetchRequired = !_.isEqual(
(filters || []).filter(filter => !filter.meta.disabled),
($scope.filters || []).filter(filter => !filter.meta.disabled),
);
$scope.filters = filters;
$scope.globalFilters = queryFilter.getGlobalFilters();
if (isFetchRequired) $scope.fetch();
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { debounce } from 'lodash';
import { debounce, isEqual } from 'lodash';
import { uiModules } from 'ui/modules';
import 'angular-sanitize';
import { VisEditorTypesRegistryProvider } from 'ui/registry/vis_editor_types';
Expand Down Expand Up @@ -59,9 +59,16 @@ uiModules
editor.destroy();
});

$scope.$watchGroup(['timeRange', 'filters'], debounce(() => {
$scope.renderFunction();
}, 100));
const debouncedRender = debounce($scope.renderFunction, 100);
$scope.$watch('timeRange', debouncedRender);
$scope.$watch('filters', filters => {
if (!isEqual(
(filters || []).filter(filter => !filter.meta.disabled),
($scope.filters || []).filter(filter => !filter.meta.disabled),
)) {
debouncedRender();
}
});
}
};
});

0 comments on commit a618a3e

Please sign in to comment.