Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

feat[Op#52449]: Upgrade the storage health status component to use sidebar component

Kabiru Mwenja7a27a7837311
diff --git a/modules/storages/app/components/storages/admin/health_status_component.html.erb b/modules/storages/app/components/storages/admin/health_status_component.html.erb
deleted file mode 100644
index 680eda58900..00000000000
--- a/modules/storages/app/components/storages/admin/health_status_component.html.erb
+++ /dev/null
@@ -1,29 +0,0 @@
-<%= render(Primer::Box.new) do %>
- <%= render(Primer::Beta::Heading.new(tag: :h4, mb: 2)) { I18n.t('storages.health.title') } %>
- <%= render(Primer::Beta::Text.new(tag: :div, mb: 2, font_weight: :bold)) { I18n.t('storages.health.subtitle') } %>
-
- <%= render(Primer::Box.new(py: 1)) do %>
- <%= render(Primer::Beta::Text.new(test_selector: "storage-health-checked-at")) {
- I18n.t('storages.health.checked', datetime: helpers.format_time(storage.health_checked_at))
- } %>
- <% if storage.health_healthy? %>
- <%= render(Primer::Beta::Label.new(scheme: :success, test_selector: "storage-health-label-healthy")) {
- I18n.t('storages.health.label_healthy')
- } %>
- <% elsif storage.health_unhealthy? %>
- <%= render(Primer::Beta::Label.new(scheme: :danger, test_selector: "storage-health-label-error")) {
- I18n.t('storages.health.label_error')
- } %>
- <% else %>
- <%= render(Primer::Beta::Label.new(scheme: :attention, test_selector: "storage-health-label-pending")) {
- I18n.t('storages.health.label_pending')
- } %>
- <% end %>
- <% end %>
-
- <% if storage.health_unhealthy? %>
- <%= render(Primer::Beta::Text.new(tag: :div, color: :muted, py: 1, test_selector: "storage-health-reason")) {
- formatted_health_reason
- } %>
- <% end %>
-<% end %>
diff --git a/modules/storages/app/components/storages/admin/sidebar/health_status_component.html.erb b/modules/storages/app/components/storages/admin/sidebar/health_status_component.html.erb
new file mode 100644
index 00000000000..6f51e23d39a
--- /dev/null
+++ b/modules/storages/app/components/storages/admin/sidebar/health_status_component.html.erb
@@ -0,0 +1,39 @@
+<%=
+ component_wrapper do
+ flex_layout do |health_status_container|
+ health_status_container.with_row do
+ flex_layout do |heading|
+ heading.with_row do
+ render(Primer::Beta::Heading.new(tag: :h4)) { "Health status" }
+ end
+
+ heading.with_row(mt: 2) do
+ render(Primer::Beta::Text.new(font_weight: :bold)) { "Automatically managed folder status" }
+ end
+ end
+ end
+
+ health_status_container.with_row(mt: 2) do
+ flex_layout do |health_status_label|
+ health_status_label.with_row do
+ concat(render(Primer::Beta::Text.new(pr: 2)) do
+ I18n.t('storages.health.checked', datetime: helpers.format_time(@storage.health_checked_at))
+ end)
+
+ concat(render(Primer::Beta::Label.new(scheme: health_status_indicator[:scheme])) do
+ health_status_indicator[:label]
+ end)
+ end
+
+ if @storage.health_unhealthy?
+ health_status_label.with_row(mt: 2) do
+ render(Primer::Beta::Text.new(color: :muted)) do
+ formatted_health_reason
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+%>
diff --git a/modules/storages/app/components/storages/admin/health_status_component.rb b/modules/storages/app/components/storages/admin/sidebar/health_status_component.rb
similarity index 71%
rename from modules/storages/app/components/storages/admin/health_status_component.rb
rename to modules/storages/app/components/storages/admin/sidebar/health_status_component.rb
index 0c2c31d041b..8aba2915861 100644
--- a/modules/storages/app/components/storages/admin/health_status_component.rb
+++ b/modules/storages/app/components/storages/admin/sidebar/health_status_component.rb
@@ -29,8 +29,30 @@
#++
#
module Storages::Admin
- class HealthStatusComponent < ApplicationComponent
- alias_method :storage, :model
+ class Sidebar::HealthStatusComponent < ApplicationComponent # rubocop:disable OpenProject/AddPreviewForViewComponent
+ include ApplicationHelper
+ include OpTurbo::Streamable
+ include OpPrimer::ComponentHelpers
+
+ attr_reader :storage
+
+ def initialize(storage:)
+ super(storage)
+ @storage = storage
+ end
+
+ private
+
+ def health_status_indicator
+ case storage.health_status
+ when "healthy"
+ { scheme: :success, label: I18n.t("storages.health.label_healthy") }
+ when "unhealthy"
+ { scheme: :danger, label: I18n.t("storages.health.label_error") }
+ else
+ { scheme: :attention, label: I18n.t("storages.health.label_pending") }
+ end
+ end
# This method returns the health identifier, description and the time since when the error occurs in a
# formatted manner. e.g. "Not found: Outbound request destination not found since 12/07/2023 03:45 PM"
diff --git a/modules/storages/app/components/storages/admin/sidebar_component.html.erb b/modules/storages/app/components/storages/admin/sidebar_component.html.erb
new file mode 100644
index 00000000000..8fe170b0d88
--- /dev/null
+++ b/modules/storages/app/components/storages/admin/sidebar_component.html.erb
@@ -0,0 +1,7 @@
+<%=
+ component_wrapper do
+ render(Primer::OpenProject::BorderGrid.new) do |border_grid|
+ border_grid.with_row { render(Storages::Admin::Sidebar::HealthStatusComponent.new(storage: @storage)) }
+ end
+ end
+%>
diff --git a/modules/storages/app/components/storages/admin/sidebar_component.rb b/modules/storages/app/components/storages/admin/sidebar_component.rb
new file mode 100644
index 00000000000..d9224ca87ce
--- /dev/null
+++ b/modules/storages/app/components/storages/admin/sidebar_component.rb
@@ -0,0 +1,43 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2024 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
+module Storages
+ module Admin
+ class SidebarComponent < ApplicationComponent # rubocop:disable OpenProject/AddPreviewForViewComponent
+ include ApplicationHelper
+ include OpTurbo::Streamable
+ include OpPrimer::ComponentHelpers
+
+ def initialize(storage:)
+ super
+
+ @storage = storage
+ end
+ end
+ end
+end
diff --git a/modules/storages/app/views/storages/admin/storages/edit.html.erb b/modules/storages/app/views/storages/admin/storages/edit.html.erb
index c0035698bf1..f4accb5e53e 100644
--- a/modules/storages/app/views/storages/admin/storages/edit.html.erb
+++ b/modules/storages/app/views/storages/admin/storages/edit.html.erb
@@ -82,7 +82,7 @@ See COPYRIGHT and LICENSE files for more details.
<% component.with_sidebar(col_placement: :end, row_placement: :end) do %>
<%= render(Primer::OpenProject::BorderGrid.new(spacious: true)) do |grid| %>
<% grid.with_row do %>
- <%= render(::Storages::Admin::HealthStatusComponent.new(@storage)) %>
+ <%= render(::Storages::Admin::SidebarComponent.new(storage: @storage)) %>
<% end %>
<% end %>
<% end %>
diff --git a/modules/storages/spec/components/storages/admin/health_status_component_spec.rb b/modules/storages/spec/components/storages/admin/sidebar/health_status_component_spec.rb
similarity index 97%
rename from modules/storages/spec/components/storages/admin/health_status_component_spec.rb
rename to modules/storages/spec/components/storages/admin/sidebar/health_status_component_spec.rb
index efc6df63df9..d91cf6cbad5 100644
--- a/modules/storages/spec/components/storages/admin/health_status_component_spec.rb
+++ b/modules/storages/spec/components/storages/admin/sidebar/health_status_component_spec.rb
@@ -29,11 +29,11 @@
require "spec_helper"
require_module_spec_helper
-RSpec.describe Storages::Admin::HealthStatusComponent, type: :component do
+RSpec.describe Storages::Admin::Sidebar::HealthStatusComponent, type: :component do
include ActiveSupport::Testing::TimeHelpers
frozen_date_time = Time.zone.local(2023, 11, 28, 1, 2, 3)
- subject(:health_status_component) { described_class.new(storage) }
+ subject(:health_status_component) { described_class.new(storage:) }
before do
render_inline(health_status_component)