Skip to content

Commit

Permalink
Merge pull request #17010 from opf/fix/storages-capitalization-again
Browse files Browse the repository at this point in the history
Fix capitalization on storage errors status
  • Loading branch information
mereghost authored Oct 22, 2024
2 parents f4eaa80 + de39d25 commit 6afa6b9
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ See COPYRIGHT and LICENSE files for more details.

health_status_container.with_row(mt: 2) do
primer_form_with(
model: @storage,
url: validate_connection_admin_settings_storage_connection_validation_path(@storage),
model:,
url: validate_connection_admin_settings_storage_connection_validation_path(model),
method: :post,
data: { turbo: true }
) do
Expand All @@ -56,22 +56,22 @@ See COPYRIGHT and LICENSE files for more details.
end
end

if @storage.automatic_management_enabled?
if model.automatic_management_enabled?
health_status_container.with_row(mt: 2) do
render(Primer::Beta::Text.new(font_weight: :bold)) { I18n.t("storages.health.project_folders.subtitle") }
end

health_status_container.with_row(mt: 2) do
concat(render(Primer::Beta::Text.new(pr: 2, test_selector: "storage-health-checked-at")) do
I18n.t('storages.health.checked', datetime: helpers.format_time(@storage.health_checked_at))
I18n.t('storages.health.checked', datetime: helpers.format_time(model.health_checked_at))
end)

concat(render(Primer::Beta::Label.new(scheme: health_status_indicator[:scheme], test_selector: "storage-health-status")) do
health_status_indicator[:label]
end)
end

if @storage.health_unhealthy?
if model.health_unhealthy?
health_status_container.with_row(mt: 2) do
render(Primer::Beta::Text.new(color: :muted, test_selector: "storage-health-error")) do
formatted_health_reason
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,15 @@
module Storages
module Admin
module SidePanel
class HealthStatusComponent < ApplicationComponent # rubocop:disable OpenProject/AddPreviewForViewComponent
class HealthStatusComponent < ApplicationComponent
include ApplicationHelper
include OpTurbo::Streamable
include OpPrimer::ComponentHelpers

def initialize(storage:)
super(storage)
@storage = storage
end

private

def health_status_indicator
case @storage.health_status
case model.health_status
when "healthy"
{ scheme: :success, label: I18n.t("storages.health.label_healthy") }
when "unhealthy"
Expand All @@ -57,8 +52,15 @@ def health_status_indicator
# 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"
def formatted_health_reason
"#{@storage.health_reason_identifier.tr('_', ' ').strip.capitalize}: #{@storage.health_reason_description} " +
I18n.t("storages.health.since", datetime: helpers.format_time(@storage.health_changed_at))
identifier = model.health_reason_identifier.tr("_", " ").strip
description = model.health_reason_description

if description.present?
identifier.capitalize!
identifier << ": #{description}"
end

"#{identifier} #{I18n.t('storages.health.since', datetime: helpers.format_time(model.health_changed_at))}"
end

def validation_result_placeholder
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<%=
component_wrapper do
render(Primer::OpenProject::SidePanel.new) do |panel|
panel.with_section(Storages::Admin::SidePanel::HealthStatusComponent.new(storage: @storage))
panel.with_section(Storages::Admin::SidePanel::HealthStatusComponent.new(@storage))

if @storage.automatic_management_enabled?
panel.with_section(Storages::Admin::SidePanel::HealthNotificationsComponent.new(storage: @storage))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@
RSpec.describe Storages::Admin::SidePanel::HealthStatusComponent, type: :component do
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)
end

context "with healthy storage" do
shared_let(:storage) do
let(:storage) do
travel_to(frozen_date_time) do
create(:nextcloud_storage_with_complete_configuration, :as_healthy)
end
Expand All @@ -52,7 +52,7 @@
end

context "with storage health pending" do
shared_let(:storage) do
let(:storage) do
travel_to(frozen_date_time) do
create(:nextcloud_storage_with_complete_configuration)
end
Expand All @@ -64,7 +64,7 @@
end

context "with unhealthy storage" do
shared_let(:storage) do
let(:storage) do
travel_to(frozen_date_time) do
create(:nextcloud_storage_with_complete_configuration, :as_unhealthy)
end
Expand All @@ -76,8 +76,22 @@
end
end

context "with an unhealthy storage with a localized error message" do
let(:error_text) { I18n.t("services.errors.models.nextcloud_sync_service.unauthorized") }
let(:storage) do
travel_to(frozen_date_time) do
create(:nextcloud_storage_with_complete_configuration, :as_unhealthy, health_reason: error_text)
end
end

it "shows a correctly formatted error message" do
expect(page).to have_test_selector("storage-health-status", text: "Error")
expect(page).to have_test_selector("storage-health-error", text: "#{error_text} since 11/28/2023 01:02 AM")
end
end

context "with unhealthy storage, long reason" do
shared_let(:storage) do
let(:storage) do
travel_to(frozen_date_time) do
create(:nextcloud_storage_with_complete_configuration, :as_unhealthy_long_reason)
end
Expand Down

0 comments on commit 6afa6b9

Please sign in to comment.