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

Factored out StorageGeneralInfoComponent

Andreas Pfohl3c851768179b
diff --git a/modules/storages/app/components/storages/admin/storage_general_info_component.html.erb b/modules/storages/app/components/storages/admin/storage_general_info_component.html.erb
new file mode 100644
index 00000000000..fed831a65d9
--- /dev/null
+++ b/modules/storages/app/components/storages/admin/storage_general_info_component.html.erb
@@ -0,0 +1,29 @@
+<%=
+ grid_layout('op-storage-view--row', tag: :div, align_items: :center) do |grid|
+ grid.with_area(:item, tag: :div, mr: 3) do
+ concat(render(Primer::Beta::Text.new(font_weight: :semibold, mr: 1, test_selector: 'storage-provider-label')) { I18n.t('storages.file_storage_view.storage_provider') })
+ concat(configuration_check_label_for(:host_name_configured))
+ end
+
+ grid.with_area(:description, tag: :div, color: :subtle, test_selector: 'storage-description') do
+ render(Primer::Beta::Truncate.new(font_weight: :light)) { storage_description }
+ end
+
+ grid.with_area(:"icon-button", tag: :div, color: :subtle) do
+ flex_layout(justify_content: :flex_end) do |icons_container|
+ icons_container.with_column do
+ render(
+ Primer::Beta::IconButton.new(
+ icon: :pencil,
+ tag: :a,
+ scheme: :invisible,
+ href: edit_host_admin_settings_storage_path(storage),
+ aria: { label: I18n.t('storages.label_edit_storage_host') } ,
+ test_selector: 'storage-edit-host-button'
+ )
+ )
+ end
+ end
+ end
+ end
+%>
diff --git a/modules/storages/app/components/storages/admin/storage_general_info_component.rb b/modules/storages/app/components/storages/admin/storage_general_info_component.rb
new file mode 100644
index 00000000000..f7f45b866a0
--- /dev/null
+++ b/modules/storages/app/components/storages/admin/storage_general_info_component.rb
@@ -0,0 +1,37 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2023 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::Admin
+ class StorageGeneralInfoComponent < ApplicationComponent
+ include OpPrimer::ComponentHelpers
+ alias_method :storage, :model
+ include StorageViewInformation
+ end
+end
diff --git a/modules/storages/app/components/storages/admin/storage_view_component.html.erb b/modules/storages/app/components/storages/admin/storage_view_component.html.erb
index e27e28710e7..5e633236fc0 100644
--- a/modules/storages/app/components/storages/admin/storage_view_component.html.erb
+++ b/modules/storages/app/components/storages/admin/storage_view_component.html.erb
@@ -6,33 +6,7 @@
component.with_row(scheme: :default) do
render(OpTurbo::FrameComponent.new(storage, context: :storage_view_general_info)) do
- grid_layout('op-storage-view--row', tag: :div, align_items: :center) do |grid|
- grid.with_area(:item, tag: :div, mr: 3) do
- concat(render(Primer::Beta::Text.new(font_weight: :semibold, mr: 1, test_selector: 'storage-provider-label')) { I18n.t('storages.file_storage_view.storage_provider') })
- concat(configuration_check_label_for(:host_name_configured))
- end
-
- grid.with_area(:description, tag: :div, color: :subtle, test_selector: 'storage-description') do
- render(Primer::Beta::Truncate.new(font_weight: :light)) { storage_description }
- end
-
- grid.with_area(:"icon-button", tag: :div, color: :subtle) do
- flex_layout(justify_content: :flex_end) do |icons_container|
- icons_container.with_column do
- render(
- Primer::Beta::IconButton.new(
- icon: :pencil,
- tag: :a,
- scheme: :invisible,
- href: edit_host_admin_settings_storage_path(storage),
- aria: { label: I18n.t('storages.label_edit_storage_host') } ,
- test_selector: 'storage-edit-host-button'
- )
- )
- end
- end
- end
- end
+ render(Storages::Admin::StorageGeneralInfoComponent.new(storage))
end
end
diff --git a/modules/storages/app/components/storages/admin/storage_view_component.rb b/modules/storages/app/components/storages/admin/storage_view_component.rb
index 03ede2530f0..af50ab1c83e 100644
--- a/modules/storages/app/components/storages/admin/storage_view_component.rb
+++ b/modules/storages/app/components/storages/admin/storage_view_component.rb
@@ -32,51 +32,6 @@ module Storages::Admin
class StorageViewComponent < ApplicationComponent
include OpPrimer::ComponentHelpers
alias_method :storage, :model
-
- private
-
- def storage_description
- [storage.short_provider_type.capitalize,
- storage.name,
- storage.host].compact.join(' - ')
- end
-
- def configuration_check_label_for(config)
- if storage.configuration_checks[config.to_sym]
- status_label(I18n.t('storages.label_connected'), scheme: :success, test_selector: "label-#{config}-status")
- else
- status_label(I18n.t('storages.label_incomplete'), scheme: :attention, test_selector: "label-#{config}-status")
- end
- end
-
- def automatically_managed_project_folders_status_label
- test_selector = 'label-managed-project-folders-status'
-
- if storage.automatically_managed?
- status_label(I18n.t('storages.label_active'), scheme: :success, test_selector:)
- elsif storage.automatic_management_unspecified?
- status_label(I18n.t('storages.label_incomplete'), scheme: :attention, test_selector:)
- else
- status_label(I18n.t('storages.label_inactive'), scheme: :secondary, test_selector:)
- end
- end
-
- def openproject_oauth_client_description
- return unless storage.oauth_application
-
- "#{I18n.t('storages.label_oauth_client_id')}: #{storage.oauth_application.uid}"
- end
-
- def provider_oauth_client_description
- if storage.oauth_client
- "#{I18n.t('storages.label_oauth_client_id')}: #{storage.oauth_client.client_id}"
- else
- I18n.t('storages.configuration_checks.oauth_client_incomplete', provider: storage.short_provider_type.capitalize)
- end
- end
-
- def status_label(label, scheme:, test_selector:)
- render(Primer::Beta::Label.new(scheme:, test_selector:)) { label }
- end
+ include StorageViewInformation
end
end
diff --git a/modules/storages/app/components/storages/admin/storage_view_information.rb b/modules/storages/app/components/storages/admin/storage_view_information.rb
new file mode 100644
index 00000000000..4fd088acdb6
--- /dev/null
+++ b/modules/storages/app/components/storages/admin/storage_view_information.rb
@@ -0,0 +1,51 @@
+# frozen_string_literal: true
+
+module Storages::Admin
+ module StorageViewInformation
+ private
+
+ def storage_description
+ [storage.short_provider_type.capitalize,
+ storage.name,
+ storage.host].compact.join(' - ')
+ end
+
+ def configuration_check_label_for(config)
+ if storage.configuration_checks[config.to_sym]
+ status_label(I18n.t('storages.label_connected'), scheme: :success, test_selector: "label-#{config}-status")
+ else
+ status_label(I18n.t('storages.label_incomplete'), scheme: :attention, test_selector: "label-#{config}-status")
+ end
+ end
+
+ def status_label(label, scheme:, test_selector:)
+ render(Primer::Beta::Label.new(scheme:, test_selector:)) { label }
+ end
+
+ def automatically_managed_project_folders_status_label
+ test_selector = 'label-managed-project-folders-status'
+
+ if storage.automatically_managed?
+ status_label(I18n.t('storages.label_active'), scheme: :success, test_selector:)
+ elsif storage.automatic_management_unspecified?
+ status_label(I18n.t('storages.label_incomplete'), scheme: :attention, test_selector:)
+ else
+ status_label(I18n.t('storages.label_inactive'), scheme: :secondary, test_selector:)
+ end
+ end
+
+ def openproject_oauth_client_description
+ return unless storage.oauth_application
+
+ "#{I18n.t('storages.label_oauth_client_id')}: #{storage.oauth_application.uid}"
+ end
+
+ def provider_oauth_client_description
+ if storage.oauth_client
+ "#{I18n.t('storages.label_oauth_client_id')}: #{storage.oauth_client.client_id}"
+ else
+ I18n.t('storages.configuration_checks.oauth_client_incomplete', provider: storage.short_provider_type.capitalize)
+ end
+ end
+ end
+end
diff --git a/modules/storages/app/views/storages/admin/storages/update.turbo_stream.erb b/modules/storages/app/views/storages/admin/storages/update.turbo_stream.erb
index 07479268488..6da3cda7393 100644
--- a/modules/storages/app/views/storages/admin/storages/update.turbo_stream.erb
+++ b/modules/storages/app/views/storages/admin/storages/update.turbo_stream.erb
@@ -1,6 +1,6 @@
-<%= turbo_stream.update ActionView::RecordIdentifier.dom_id(@storage, :storage_view_general_info) do %>
- <%= render(::Storages::Admin::StorageViewComponent.new(@storage)) %>
+<%= turbo_stream.update dom_id(@storage, :storage_view_general_info) do %>
+ <%= render(::Storages::Admin::StorageGeneralInfoComponent.new(@storage)) %>
<% end %>
-<%= turbo_stream.update ActionView::RecordIdentifier.dom_id(@storage, :edit_storage_header) do %>
+<%= turbo_stream.update dom_id(@storage, :edit_storage_header) do %>
<%= @storage.name %>
<% end %>
diff --git a/modules/storages/spec/features/admin_storages_spec.rb b/modules/storages/spec/features/admin_storages_spec.rb
index 958f1774fd6..88950db5165 100644
--- a/modules/storages/spec/features/admin_storages_spec.rb
+++ b/modules/storages/spec/features/admin_storages_spec.rb
@@ -116,6 +116,7 @@ RSpec.describe 'Admin storages',
click_button 'Save and continue'
end
+ expect(page).to have_test_selector('storage-name-title', text: 'My Nextcloud')
expect(page).to have_test_selector('storage-description', text: [storage.short_provider_type.capitalize,
'My Nextcloud',
storage.host].join(' - '))