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#50737]: Let SaveOrCancel component extend sys args directly

Kabiru Mwenja1022308f9a67
diff --git a/modules/storages/app/components/storages/admin/forms/automatically_managed_project_folders_form_component.html.erb b/modules/storages/app/components/storages/admin/forms/automatically_managed_project_folders_form_component.html.erb
index f6a74c65eff..b92da09d10a 100644
--- a/modules/storages/app/components/storages/admin/forms/automatically_managed_project_folders_form_component.html.erb
+++ b/modules/storages/app/components/storages/admin/forms/automatically_managed_project_folders_form_component.html.erb
@@ -32,8 +32,12 @@
Storages::Admin::SaveOrCancelForm.new(
form,
storage:,
- submit_label: I18n.t("storages.buttons.done_complete_setup"),
- cancel_button_path: edit_admin_settings_storage_path(storage)
+ submit_button_options: {
+ label: I18n.t("storages.buttons.done_complete_setup")
+ },
+ cancel_button_options: {
+ href: edit_admin_settings_storage_path(storage)
+ }
)
)
end
diff --git a/modules/storages/app/components/storages/admin/forms/general_info_form_component.html.erb b/modules/storages/app/components/storages/admin/forms/general_info_form_component.html.erb
index 360cb8dff9a..03fdf8fd656 100644
--- a/modules/storages/app/components/storages/admin/forms/general_info_form_component.html.erb
+++ b/modules/storages/app/components/storages/admin/forms/general_info_form_component.html.erb
@@ -25,8 +25,13 @@
Storages::Admin::SaveOrCancelForm.new(
form,
storage:,
- cancel_button_path:,
- cancel_button_should_break_from_frame:
+ submit_button_options: {
+ disabled: submit_button_disabled?,
+ },
+ cancel_button_options: {
+ href: cancel_button_path,
+ target: '_top'
+ }
)
)
end
diff --git a/modules/storages/app/components/storages/admin/forms/general_info_form_component.rb b/modules/storages/app/components/storages/admin/forms/general_info_form_component.rb
index 9031a49a714..1b29c699a81 100644
--- a/modules/storages/app/components/storages/admin/forms/general_info_form_component.rb
+++ b/modules/storages/app/components/storages/admin/forms/general_info_form_component.rb
@@ -35,10 +35,12 @@ module Storages::Admin::Forms
options form_method: :post,
render_host: true,
+ submit_button_disabled: false,
cancel_button_should_break_from_frame: false,
cancel_button_path: Rails.application.routes.url_helpers.admin_settings_storages_path
alias_method :render_host?, :render_host
+ alias_method :submit_button_disabled?, :submit_button_disabled
def form_url
options[:form_url] || default_form_url
diff --git a/modules/storages/app/components/storages/admin/forms/oauth_client_form_component.html.erb b/modules/storages/app/components/storages/admin/forms/oauth_client_form_component.html.erb
index 190820e5413..3a8054699ff 100644
--- a/modules/storages/app/components/storages/admin/forms/oauth_client_form_component.html.erb
+++ b/modules/storages/app/components/storages/admin/forms/oauth_client_form_component.html.erb
@@ -18,7 +18,15 @@
end
oauth_client_row.with_row do
- render(Storages::Admin::SaveOrCancelForm.new(form, storage:))
+ render(
+ Storages::Admin::SaveOrCancelForm.new(
+ form,
+ storage:,
+ cancel_button_options: {
+ href: edit_admin_settings_storage_path(storage)
+ }
+ )
+ )
end
end
end
diff --git a/modules/storages/app/forms/storages/admin/save_or_cancel_form.rb b/modules/storages/app/forms/storages/admin/save_or_cancel_form.rb
index 242db77fc64..2b4f52d412f 100644
--- a/modules/storages/app/forms/storages/admin/save_or_cancel_form.rb
+++ b/modules/storages/app/forms/storages/admin/save_or_cancel_form.rb
@@ -30,29 +30,37 @@ module Storages::Admin
class SaveOrCancelForm < ApplicationForm
form do |buttons|
buttons.group(layout: :horizontal) do |button_group|
- button_group.submit(name: :submit,
- scheme: :primary,
- label: @submit_label)
- button_group.button(name: :cancel,
- scheme: :default,
- tag: :a,
- href: @cancel_button_path,
- label: I18n.t('button_cancel'),
- target: @cancel_button_target)
+ button_group.submit(**@submit_button_options)
+ button_group.button(**@cancel_button_options)
end
end
- def initialize(
- storage:,
- cancel_button_path: nil,
- cancel_button_should_break_from_frame: false,
- submit_label: I18n.t('storages.buttons.save_and_continue')
- )
+ def initialize(storage:, submit_button_options: {}, cancel_button_options: {})
super()
@storage = storage
- @submit_label = submit_label
- @cancel_button_path = cancel_button_path || Rails.application.routes.url_helpers.edit_admin_settings_storage_path(storage)
- @cancel_button_target = '_top' if cancel_button_should_break_from_frame
+ @submit_button_options = default_submit_button_options.merge(submit_button_options)
+ @cancel_button_options = default_cancel_button_options.merge(cancel_button_options)
+ end
+
+ private
+
+ def default_submit_button_options
+ {
+ name: :submit,
+ scheme: :primary,
+ label: I18n.t('storages.buttons.save_and_continue'),
+ disabled: false
+ }
+ end
+
+ def default_cancel_button_options
+ {
+ name: :cancel,
+ scheme: :default,
+ tag: :a,
+ href: Rails.application.routes.url_helpers.admin_settings_storages_path,
+ label: I18n.t('button_cancel')
+ }
end
end
end