From 3ff61f3d6340dfb0f668a1689a572496d2700e14 Mon Sep 17 00:00:00 2001
From: Jozef Zigmund <jzigmund@redhat.com>
Date: Thu, 10 Nov 2016 17:32:50 +0100
Subject: [PATCH 1/4] Change class for instance_scan button

https://bugzilla.redhat.com/show_bug.cgi?id=1389055
---
 app/helpers/application_helper/toolbar/vm_clouds_center.rb | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/app/helpers/application_helper/toolbar/vm_clouds_center.rb b/app/helpers/application_helper/toolbar/vm_clouds_center.rb
index 47d169d0778..34846662893 100644
--- a/app/helpers/application_helper/toolbar/vm_clouds_center.rb
+++ b/app/helpers/application_helper/toolbar/vm_clouds_center.rb
@@ -25,8 +25,8 @@ class ApplicationHelper::Toolbar::VmCloudsCenter < ApplicationHelper::Toolbar::B
           :url_parms => "main_div",
           :confirm   => N_("Perform SmartState Analysis on the selected items?"),
           :enabled   => false,
-          :onwhen    => "1+",
-          :klass     => ApplicationHelper::Button::VmInstanceTemplateScan),
+          :klass     => ApplicationHelper::Button::BasicImage,
+          :onwhen    => "1+"),
         button(
           :instance_compare,
           'product product-compare fa-lg',

From ecf50dec967aa36461e37154cf8ba0320796cc9b Mon Sep 17 00:00:00 2001
From: Jozef Zigmund <jzigmund@redhat.com>
Date: Thu, 10 Nov 2016 17:33:35 +0100
Subject: [PATCH 2/4] Remove unnecessary condition

---
 .../application_helper/button/vm_instance_template_scan.rb      | 2 --
 1 file changed, 2 deletions(-)

diff --git a/app/helpers/application_helper/button/vm_instance_template_scan.rb b/app/helpers/application_helper/button/vm_instance_template_scan.rb
index e316270b500..6e4f2e989ce 100644
--- a/app/helpers/application_helper/button/vm_instance_template_scan.rb
+++ b/app/helpers/application_helper/button/vm_instance_template_scan.rb
@@ -13,12 +13,10 @@ def calculate_properties
   end
 
   def visible?
-    return true if @display == "instances"
     @record.supports_smartstate_analysis? && @record.has_proxy?
   end
 
   def disabled?
-    return false if @display == "instances"
     !(@record.supports_smartstate_analysis? && @record.has_active_proxy?)
   end
 end

From 9c5224dce61dd531fdff288f1538e96deb4d3716 Mon Sep 17 00:00:00 2001
From: Jozef Zigmund <jzigmund@redhat.com>
Date: Thu, 10 Nov 2016 17:35:41 +0100
Subject: [PATCH 3/4] Use x_node instead of inspecting sandbox

---
 app/helpers/application_helper/button/basic_image.rb | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/app/helpers/application_helper/button/basic_image.rb b/app/helpers/application_helper/button/basic_image.rb
index 1c4b8267ded..41e116c2b9f 100644
--- a/app/helpers/application_helper/button/basic_image.rb
+++ b/app/helpers/application_helper/button/basic_image.rb
@@ -1,7 +1,6 @@
 class ApplicationHelper::Button::BasicImage < ApplicationHelper::Button::Basic
   def visible?
-    @sb.fetch_path(:trees, :vandt_tree, :active_node).blank? ||
-      (@sb[:trees][:vandt_tree][:active_node] != "xx-arch" &&
-       @sb[:trees][:vandt_tree][:active_node] != "xx-orph")
+    active_node = @view_context.x_node
+    active_node.blank? || (active_node != "xx-arch" && active_node != "xx-orph")
   end
 end

From e63f2a0572ecc6e3ae8061dbb059be0dcb0705b1 Mon Sep 17 00:00:00 2001
From: Jozef Zigmund <jzigmund@redhat.com>
Date: Fri, 11 Nov 2016 16:17:51 +0100
Subject: [PATCH 4/4] Fix and refactor tests for ::Button::BasicImage

---
 .../buttons/basic_image_spec.rb               | 21 +++++++------------
 1 file changed, 7 insertions(+), 14 deletions(-)

diff --git a/spec/helpers/application_helper/buttons/basic_image_spec.rb b/spec/helpers/application_helper/buttons/basic_image_spec.rb
index 371298dd1fe..52f5e8d8d5d 100644
--- a/spec/helpers/application_helper/buttons/basic_image_spec.rb
+++ b/spec/helpers/application_helper/buttons/basic_image_spec.rb
@@ -1,27 +1,20 @@
 describe ApplicationHelper::Button::BasicImage do
   describe '#visible?' do
+    before do
+      @view_context = setup_view_context_with_sandbox({:trees => {:vandt_tree => {:active_node => "xx-arch"}},
+                                                       :active_tree => :vandt_tree})
+    end
     context "in list of archived VMs" do
-      before do
-        allow(ApplicationHelper).to receive(:get_record_cls).and_return(nil)
-        @sb = {:trees => {:vandt_tree => {:active_node => "xx-arch"}}}
-      end
-
       it "will be skipped" do
-        view_context = setup_view_context_with_sandbox({})
-        button = described_class.new(view_context, {}, {'sb' => @sb}, {})
+        button = described_class.new(@view_context, {}, {}, {})
         expect(button.visible?).to be_falsey
       end
     end
 
     context "in list of orphaned VMs" do
-      before do
-        allow(ApplicationHelper).to receive(:get_record_cls).and_return(nil)
-        @sb = {:trees => {:vandt_tree => {:active_node => "xx-arch"}}}
-      end
-
       it "will be skipped" do
-        view_context = setup_view_context_with_sandbox({})
-        button = described_class.new(view_context, {}, {'sb' => @sb}, {})
+        @view_context.x_node = "xx-orph"
+        button = described_class.new(@view_context, {}, {}, {})
         expect(button.visible?).to be_falsey
       end
     end