From 526fffc4b581762399e908836f8dae579b673019 Mon Sep 17 00:00:00 2001
From: Leonardo Menezes <mail@lmenezes.com>
Date: Mon, 23 Oct 2017 21:35:54 +0200
Subject: [PATCH] ensure index health filter clears when no longer visible

closes #217
---
 public/js/app.js                          |  5 +++++
 src/app/components/overview/controller.js |  5 +++++
 tests/controllers/overview.tests.js       | 21 ++++++++++++++++++++-
 3 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/public/js/app.js b/public/js/app.js
index a7487c8..2519f44 100644
--- a/public/js/app.js
+++ b/public/js/app.js
@@ -866,6 +866,11 @@ angular.module('cerebro').controller('OverviewController', ['$scope', '$http',
           $scope.closed_indices = data.closed_indices;
           $scope.special_indices = data.special_indices;
           $scope.shardAllocation = data.shard_allocation;
+          if (!$scope.unassigned_shards &&
+            !$scope.relocating_shards &&
+            !$scope.initializing_shards) {
+            $scope.indices_filter.healthy = true;
+          }
         },
         function(error) {
           AlertService.error('Error while loading data', error);
diff --git a/src/app/components/overview/controller.js b/src/app/components/overview/controller.js
index 9868952..d8e9da0 100644
--- a/src/app/components/overview/controller.js
+++ b/src/app/components/overview/controller.js
@@ -59,6 +59,11 @@ angular.module('cerebro').controller('OverviewController', ['$scope', '$http',
           $scope.closed_indices = data.closed_indices;
           $scope.special_indices = data.special_indices;
           $scope.shardAllocation = data.shard_allocation;
+          if (!$scope.unassigned_shards &&
+            !$scope.relocating_shards &&
+            !$scope.initializing_shards) {
+            $scope.indices_filter.healthy = true;
+          }
         },
         function(error) {
           AlertService.error('Error while loading data', error);
diff --git a/tests/controllers/overview.tests.js b/tests/controllers/overview.tests.js
index e237c9f..53a4a55 100644
--- a/tests/controllers/overview.tests.js
+++ b/tests/controllers/overview.tests.js
@@ -76,7 +76,7 @@ describe('OverviewController', function() {
         };
         this.OverviewDataService.getOverview = function(success, error) {
           success(data);
-        }
+        };
         spyOn(this.OverviewDataService, 'getOverview').and.callThrough();
         spyOn(this.scope, 'setIndices').and.returnValue(true);
         spyOn(this.scope, 'setNodes').and.returnValue(true);
@@ -93,6 +93,25 @@ describe('OverviewController', function() {
         expect(this.scope.data).toEqual(data);
       }
     );
+
+    it('clears health filter if no unhealthy indices exist',
+      function() {
+        var data = {
+          indices: ['someIndex'],
+          nodes: ['someNode'],
+          unassigned_shards: 0,
+          relocating_shards: 0,
+          initializing_shards: 0
+        };
+        this.OverviewDataService.getOverview = function(success, error) {
+          success(data);
+        };
+        this.scope.indices_filter.healthy = false;
+        spyOn(this.OverviewDataService, 'getOverview').and.callThrough();
+        this.scope.refresh();
+        expect(this.scope.indices_filter.healthy).toEqual(true);
+      }
+    );
     
     it('cleans state and alerts users if refreshing data fails',
       function() {
-- 
GitLab