From 8e25bba2dfa3452e1f9097c3d9b0b295f7962f11 Mon Sep 17 00:00:00 2001
From: Sean Arnold <sarnold@gitlab.com>
Date: Tue, 30 Jun 2020 17:44:24 +1200
Subject: [PATCH] Add AlertManagement Alert state pill

- Update helper, css
- Add alias method
---
 app/assets/stylesheets/framework/issue_box.scss |  1 +
 app/helpers/todos_helper.rb                     | 11 ++++++++++-
 app/models/alert_management/alert.rb            |  2 ++
 3 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/app/assets/stylesheets/framework/issue_box.scss b/app/assets/stylesheets/framework/issue_box.scss
index 385b29f8bbe..4d5032ac674 100644
--- a/app/assets/stylesheets/framework/issue_box.scss
+++ b/app/assets/stylesheets/framework/issue_box.scss
@@ -30,6 +30,7 @@
   }
 
   &.status-box-issue-closed,
+  &.status-box-alert-resolved,
   &.status-box-mr-merged {
     background-color: $blue-500;
   }
diff --git a/app/helpers/todos_helper.rb b/app/helpers/todos_helper.rb
index 2b4f2f11d1e..cf7e2444157 100644
--- a/app/helpers/todos_helper.rb
+++ b/app/helpers/todos_helper.rb
@@ -97,6 +97,8 @@ module TodosHelper
         'mr'
       when Issue
         'issue'
+      when AlertManagement::Alert
+        'alert'
       end
 
     content_tag(:span, nil, class: 'target-status') do
@@ -214,7 +216,14 @@ module TodosHelper
   end
 
   def show_todo_state?(todo)
-    (todo.target.is_a?(MergeRequest) || todo.target.is_a?(Issue)) && %w(closed merged).include?(todo.target.state)
+    case todo.target
+    when MergeRequest, Issue
+      %w(closed merged).include?(todo.target.state)
+    when AlertManagement::Alert
+      %w(resolved).include?(todo.target.state)
+    else
+      false
+    end
   end
 
   def todo_group_options
diff --git a/app/models/alert_management/alert.rb b/app/models/alert_management/alert.rb
index c897a777d2a..75ed0690dd1 100644
--- a/app/models/alert_management/alert.rb
+++ b/app/models/alert_management/alert.rb
@@ -127,6 +127,8 @@ module AlertManagement
     scope :counts_by_status, -> { group(:status).count }
     scope :counts_by_project_id, -> { group(:project_id).count }
 
+    alias_method :state, :human_status_name
+
     def self.sort_by_attribute(method)
       case method.to_s
       when 'started_at_asc'     then order_start_time(:asc)
-- 
2.30.9