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

Revert "chore[#50212]: Combine StorageButtonComponent with options"

Kabiru Mwenja0a84380a5f20
diff --git a/modules/storages/app/components/storages/admin/storage_button_component.html.erb b/modules/storages/app/components/storages/admin/delete_storage_button_component.html.erb
similarity index 62%
rename from modules/storages/app/components/storages/admin/storage_button_component.html.erb
rename to modules/storages/app/components/storages/admin/delete_storage_button_component.html.erb
index dfea66c001e..d0d61eaf5fc 100644
--- a/modules/storages/app/components/storages/admin/storage_button_component.html.erb
+++ b/modules/storages/app/components/storages/admin/delete_storage_button_component.html.erb
@@ -1,6 +1,6 @@
<%=
render(Primer::Beta::Button.new(**button_options)) do |button|
- button.with_leading_visual_icon(icon: icon_name)
+ button.with_leading_visual_icon(icon: :trash)
label
end
%>
diff --git a/modules/storages/app/components/storages/admin/storage_button_component.rb b/modules/storages/app/components/storages/admin/delete_storage_button_component.rb
similarity index 61%
rename from modules/storages/app/components/storages/admin/storage_button_component.rb
rename to modules/storages/app/components/storages/admin/delete_storage_button_component.rb
index b1af473b536..a7d900c5a40 100644
--- a/modules/storages/app/components/storages/admin/storage_button_component.rb
+++ b/modules/storages/app/components/storages/admin/delete_storage_button_component.rb
@@ -29,42 +29,28 @@
#++
#
module Storages::Admin
- class StorageButtonComponent < ApplicationComponent
- options action: :new,
+ class DeleteStorageButtonComponent < ApplicationComponent
+ options scheme: :danger,
size: :medium,
tag: :a
alias_method :storage, :model
- def button_options
- { size:,
- tag:,
- role: :button }.merge(button_options_from_action)
- end
-
private
- def button_options_from_action
- case action
- when :new
- { scheme: :primary, href: Rails.application.routes.url_helpers.new_admin_settings_storage_path,
- aria: { label: I18n.t("storages.label_add_new_storage") } }
- when :delete
- { scheme: :danger, href: Rails.application.routes.url_helpers.admin_settings_storage_path(storage),
- aria: { label: I18n.t("storages.label_delete_storage") },
- data: { confirm: I18n.t('storages.delete_warning.storage') },
- method: :delete }
- end
+ def button_options
+ { scheme:,
+ size:,
+ tag:,
+ role: :button,
+ href: admin_settings_storage_path(storage),
+ aria: { label: I18n.t("storages.label_delete_storage") },
+ data: { confirm: I18n.t('storages.delete_warning.storage') },
+ method: :delete }
end
def label
- { new: I18n.t("storages.label_storage"),
- delete: I18n.t('button_delete') }[action]
- end
-
- def icon_name
- { new: 'plus',
- delete: 'trash' }[action]
+ I18n.t('button_delete')
end
end
end
diff --git a/modules/storages/app/components/storages/admin/new_storage_button_component.rb b/modules/storages/app/components/storages/admin/new_storage_button_component.rb
new file mode 100644
index 00000000000..5de250128fc
--- /dev/null
+++ b/modules/storages/app/components/storages/admin/new_storage_button_component.rb
@@ -0,0 +1,50 @@
+# 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 NewStorageButtonComponent < ApplicationComponent
+ options scheme: :primary,
+ size: :medium,
+ tag: :a
+
+ def button_options
+ { scheme:,
+ size:,
+ tag:,
+ role: :button,
+ href: Rails.application.routes.url_helpers.new_admin_settings_storage_path,
+ aria: { label: I18n.t("storages.label_add_new_storage") } }
+ end
+
+ def label
+ I18n.t("storages.label_storage")
+ end
+ end
+end
diff --git a/modules/storages/app/components/storages/admin/storage_list_component.html.erb b/modules/storages/app/components/storages/admin/storage_list_component.html.erb
index 009b37b888e..4dd4f850b3c 100644
--- a/modules/storages/app/components/storages/admin/storage_list_component.html.erb
+++ b/modules/storages/app/components/storages/admin/storage_list_component.html.erb
@@ -57,7 +57,7 @@
component.with_heading(tag: :h2).with_content(I18n.t('storages.storage_list_blank_slate.heading'))
component.with_description { I18n.t('storages.storage_list_blank_slate.description') }
- component.with_primary_action(**Storages::Admin::StorageButtonComponent.new(action: :new).button_options) do |button|
+ component.with_primary_action(**Storages::Admin::NewStorageButtonComponent.new.button_options) do |button|
button.with_leading_visual_icon(icon: :plus)
I18n.t("storages.label_storage")
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 8aa3eaff7d7..3a7ebb62351 100644
--- a/modules/storages/app/views/storages/admin/storages/edit.html.erb
+++ b/modules/storages/app/views/storages/admin/storages/edit.html.erb
@@ -36,7 +36,7 @@ See COPYRIGHT and LICENSE files for more details.
<% end %>
<% header.with_actions do %>
- <%= render(Storages::Admin::StorageButtonComponent.new(@storage, action: :delete)) %>
+ <%= render(Storages::Admin::DeleteStorageButtonComponent.new(@storage)) %>
<% end %>
<% end %>
diff --git a/modules/storages/app/views/storages/admin/storages/index.html.erb b/modules/storages/app/views/storages/admin/storages/index.html.erb
index cdf2756c3f3..eb97aad3343 100644
--- a/modules/storages/app/views/storages/admin/storages/index.html.erb
+++ b/modules/storages/app/views/storages/admin/storages/index.html.erb
@@ -12,7 +12,7 @@
<% end %>
<% header.with_actions do %>
- <%= render(Storages::Admin::StorageButtonComponent.new(action: :new)) %>
+ <%= render(Storages::Admin::NewStorageButtonComponent.new) %>
<% end %>
<% end %>