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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Allow turbo_stream with scrolling
Oliver Günther5136cc4a3b7e
diff --git a/app/components/op_turbo/stream_component.html.erb b/app/components/op_turbo/stream_component.html.erbindex bac890e181e..8a0a9e20775 100644--- a/app/components/op_turbo/stream_component.html.erb+++ b/app/components/op_turbo/stream_component.html.erb@@ -26,11 +26,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.See COPYRIGHT and LICENSE files for more details.++#%>-<turbo-stream action="<%=@action%>" target="<%=@target%>">+<%= content_tag("turbo-stream", action: @action, target: @target, **@turbo_stream_args) do %><% if @template %><template><%= @template %></template><% end %>-</turbo-stream>-+<% end %>diff --git a/app/components/op_turbo/stream_component.rb b/app/components/op_turbo/stream_component.rbindex 2fb2ecef982..43fa04eaab7 100644--- a/app/components/op_turbo/stream_component.rb+++ b/app/components/op_turbo/stream_component.rb@@ -28,9 +28,10 @@module OpTurboclass StreamComponent < ApplicationComponent- def initialize(template:, action:, target:)+ def initialize(action:, target:, template: nil, **turbo_stream_args)super()+ @turbo_stream_args = turbo_stream_args@template = template@action = action@target = targetdiff --git a/app/controllers/concerns/op_turbo/component_stream.rb b/app/controllers/concerns/op_turbo/component_stream.rbindex 125a26975e8..6d3b3fa2716 100644--- a/app/controllers/concerns/op_turbo/component_stream.rb+++ b/app/controllers/concerns/op_turbo/component_stream.rb@@ -39,6 +39,7 @@ module OpTurboyield(format) if format_blockendend+alias_method :respond_with_turbo_streams, :respond_to_with_turbo_streamsdef update_via_turbo_stream(component:, status: :ok)@@ -82,6 +83,12 @@ module OpTurboturbo_streams << instance.render_as_turbo_stream(view_context:, action: :flash)end+ def scroll_into_view_via_turbo_stream(target, behavior: :auto, block: :start)+ turbo_streams << OpTurbo::StreamComponent+ .new(action: :scroll_into_view, target:, behavior:, block:)+ .render_in(view_context)+ end+def turbo_streams@turbo_streams ||= []enddiff --git a/modules/auth_saml/app/components/saml/providers/sections/form_component.html.erb b/modules/auth_saml/app/components/saml/providers/sections/form_component.html.erbindex 5a7c0dce3f0..64490434c0f 100644--- a/modules/auth_saml/app/components/saml/providers/sections/form_component.html.erb+++ b/modules/auth_saml/app/components/saml/providers/sections/form_component.html.erb@@ -1,5 +1,6 @@<%=primer_form_with(+ id: "saml-providers-edit-form",model: provider,url:,method: form_method,diff --git a/modules/auth_saml/app/components/saml/providers/sections/metadata_form_component.html.erb b/modules/auth_saml/app/components/saml/providers/sections/metadata_form_component.html.erbindex 86a2ed28470..26ee6189d80 100644--- a/modules/auth_saml/app/components/saml/providers/sections/metadata_form_component.html.erb+++ b/modules/auth_saml/app/components/saml/providers/sections/metadata_form_component.html.erb@@ -1,6 +1,7 @@<%=primer_form_with(model: provider,+ id: "saml-providers-edit-form",url: import_metadata_saml_provider_path(provider),data: {controller: "show-when-value-selected"diff --git a/modules/auth_saml/app/components/saml/providers/sections/show_component.html.erb b/modules/auth_saml/app/components/saml/providers/sections/show_component.html.erbindex e3d6adb05cc..0b381375eb9 100644--- a/modules/auth_saml/app/components/saml/providers/sections/show_component.html.erb+++ b/modules/auth_saml/app/components/saml/providers/sections/show_component.html.erb@@ -23,6 +23,7 @@tag: :a,scheme: :invisible,href: edit_saml_provider_path(provider, edit_state: @target_state),+ data: { turbo: true, turbo_stream: true },aria: { label: I18n.t(:label_edit) }))diff --git a/modules/auth_saml/app/components/saml/providers/view_component.html.erb b/modules/auth_saml/app/components/saml/providers/view_component.html.erbindex 0c2ac92d501..7a5f055091b 100644--- a/modules/auth_saml/app/components/saml/providers/view_component.html.erb+++ b/modules/auth_saml/app/components/saml/providers/view_component.html.erb@@ -1,140 +1,141 @@-<% if provider.seeded_from_env? %>- <%=- render(Primer::Alpha::Banner.new(mb: 2, scheme: :default, icon: :bell, spacious: true)) do- I18n.t("saml.providers.seeded_from_env")- end- %>-<% end %>+<%= component_wrapper do %>+ <% if provider.seeded_from_env? %>+ <%=+ render(Primer::Alpha::Banner.new(mb: 2, scheme: :default, icon: :bell, spacious: true)) do+ I18n.t("saml.providers.seeded_from_env")+ end+ %>+ <% end %>-<%=- render(border_box_container) do |component|- component.with_header(color: :muted) do- render(Primer::Beta::Text.new(font_weight: :semibold)) { I18n.t("activemodel.attributes.saml/provider.display_name") }- end+<%= render(border_box_container) do |component|+ component.with_header(color: :muted) do+ render(Primer::Beta::Text.new(font_weight: :semibold)) { I18n.t("activemodel.attributes.saml/provider.display_name") }+ end- component.with_row(scheme: :default) do- if edit_state == :name- render(Saml::Providers::Sections::FormComponent.new(- provider,- form_class: Saml::Providers::NameInputForm,- edit_state:,- heading: nil- ))- else- render(Saml::Providers::Sections::ShowComponent.new(- provider,- view_mode:,- target_state: :name,- heading: t("saml.providers.singular"),- description: t("saml.providers.section_texts.display_name")- ))- end+ component.with_row(scheme: :default) do+ if edit_state == :name+ render(Saml::Providers::Sections::FormComponent.new(+ provider,+ form_class: Saml::Providers::NameInputForm,+ edit_state:,+ heading: nil+ ))+ else+ render(Saml::Providers::Sections::ShowComponent.new(+ provider,+ view_mode:,+ target_state: :name,+ heading: t("saml.providers.singular"),+ description: t("saml.providers.section_texts.display_name")+ ))end+ end- component.with_row(scheme: :neutral, color: :muted) do- render(Primer::Beta::Text.new(font_weight: :semibold)) { I18n.t('saml.providers.label_automatic_configuration') }- end+ component.with_row(scheme: :neutral, color: :muted) do+ render(Primer::Beta::Text.new(font_weight: :semibold)) { I18n.t('saml.providers.label_automatic_configuration') }+ end- component.with_row(scheme: :default) do- if edit_state == :metadata- render(Saml::Providers::Sections::MetadataFormComponent.new(provider))- else- render(Saml::Providers::Sections::ShowComponent.new(- provider,- target_state: :metadata,- view_mode:,- heading: t("saml.providers.label_metadata"),- description: t("saml.providers.section_texts.metadata"),- label: provider.has_metadata? ? t(:label_completed) : t(:label_not_configured),- label_scheme: provider.has_metadata? ? :success : :secondary- ))- end+ component.with_row(scheme: :default) do+ if edit_state == :metadata+ render(Saml::Providers::Sections::MetadataFormComponent.new(provider))+ else+ render(Saml::Providers::Sections::ShowComponent.new(+ provider,+ target_state: :metadata,+ view_mode:,+ heading: t("saml.providers.label_metadata"),+ description: t("saml.providers.section_texts.metadata"),+ label: provider.has_metadata? ? t(:label_completed) : t(:label_not_configured),+ label_scheme: provider.has_metadata? ? :success : :secondary+ ))end+ end- component.with_row(scheme: :neutral, color: :muted) do- render(Primer::Beta::Text.new(font_weight: :semibold)) { I18n.t('saml.providers.section_headers.configuration') }- end+ component.with_row(scheme: :neutral, color: :muted) do+ render(Primer::Beta::Text.new(font_weight: :semibold)) { I18n.t('saml.providers.section_headers.configuration') }+ end- component.with_row(scheme: :default) do- if edit_state == :configuration- render(Saml::Providers::Sections::FormComponent.new(- provider,- form_class: Saml::Providers::ConfigurationForm,- edit_state:,- heading: t("saml.providers.section_texts.configuration_form")- ))- else- render(Saml::Providers::Sections::ShowComponent.new(- provider,- target_state: :configuration,- view_mode:,- heading: t("saml.providers.label_configuration_details"),- description: t("saml.providers.section_texts.configuration"),- label: (provider.persisted? && !provider.configured?) ? t(:label_incomplete) : nil,- ))- end+ component.with_row(scheme: :default) do+ if edit_state == :configuration+ render(Saml::Providers::Sections::FormComponent.new(+ provider,+ form_class: Saml::Providers::ConfigurationForm,+ edit_state:,+ heading: t("saml.providers.section_texts.configuration_form")+ ))+ else+ render(Saml::Providers::Sections::ShowComponent.new(+ provider,+ target_state: :configuration,+ view_mode:,+ heading: t("saml.providers.label_configuration_details"),+ description: t("saml.providers.section_texts.configuration"),+ label: (provider.persisted? && !provider.configured?) ? t(:label_incomplete) : nil,+ ))end+ end- component.with_row(scheme: :default) do- if edit_state == :encryption- render(Saml::Providers::Sections::FormComponent.new(- provider,- form_class: Saml::Providers::EncryptionForm,- edit_state:,- heading: t("saml.providers.section_texts.encryption_form")- ))- else- render(Saml::Providers::Sections::ShowComponent.new(- provider,- target_state: :encryption,- view_mode:,- heading: t("saml.providers.label_configuration_encryption"),- description: t("saml.providers.section_texts.encryption")- ))- end+ component.with_row(scheme: :default) do+ if edit_state == :encryption+ render(Saml::Providers::Sections::FormComponent.new(+ provider,+ form_class: Saml::Providers::EncryptionForm,+ edit_state:,+ heading: t("saml.providers.section_texts.encryption_form")+ ))+ else+ render(Saml::Providers::Sections::ShowComponent.new(+ provider,+ target_state: :encryption,+ view_mode:,+ heading: t("saml.providers.label_configuration_encryption"),+ description: t("saml.providers.section_texts.encryption")+ ))end+ end- component.with_row(scheme: :neutral, color: :muted) do- render(Primer::Beta::Text.new(font_weight: :semibold)) { I18n.t('saml.providers.section_headers.attributes') }- end+ component.with_row(scheme: :neutral, color: :muted) do+ render(Primer::Beta::Text.new(font_weight: :semibold)) { I18n.t('saml.providers.section_headers.attributes') }+ end- component.with_row(scheme: :default) do- if edit_state == :mapping- render(Saml::Providers::Sections::FormComponent.new(- provider,- form_class: Saml::Providers::MappingForm,- edit_state:,- heading: t("saml.instructions.mapping")- ))- else- render(Saml::Providers::Sections::ShowComponent.new(- provider,- target_state: :mapping,- view_mode:,- heading: t("saml.providers.label_mapping"),- description: t("saml.providers.section_texts.mapping"),- label: provider.mapping_configured? ? t(:label_completed) : t(:label_incomplete),- label_scheme: provider.mapping_configured? ? :success : :attention- ))- end+ component.with_row(scheme: :default) do+ if edit_state == :mapping+ render(Saml::Providers::Sections::FormComponent.new(+ provider,+ form_class: Saml::Providers::MappingForm,+ edit_state:,+ heading: t("saml.instructions.mapping")+ ))+ else+ render(Saml::Providers::Sections::ShowComponent.new(+ provider,+ target_state: :mapping,+ view_mode:,+ heading: t("saml.providers.label_mapping"),+ description: t("saml.providers.section_texts.mapping"),+ label: provider.mapping_configured? ? t(:label_completed) : t(:label_incomplete),+ label_scheme: provider.mapping_configured? ? :success : :attention+ ))end- component.with_row(scheme: :default) do- if edit_state == :requested_attributes- render(Saml::Providers::Sections::FormComponent.new(- provider,- form_class: Saml::Providers::RequestAttributesForm,- edit_state:,- heading: t("saml.instructions.requested_attributes")- ))- else- render(Saml::Providers::Sections::ShowComponent.new(- provider,- target_state: :requested_attributes,- view_mode:,- heading: t("saml.providers.requested_attributes"),- description: t("saml.providers.section_texts.requested_attributes")- ))- end+ end+ component.with_row(scheme: :default) do+ if edit_state == :requested_attributes+ render(Saml::Providers::Sections::FormComponent.new(+ provider,+ form_class: Saml::Providers::RequestAttributesForm,+ edit_state:,+ heading: t("saml.instructions.requested_attributes")+ ))+ else+ render(Saml::Providers::Sections::ShowComponent.new(+ provider,+ target_state: :requested_attributes,+ view_mode:,+ heading: t("saml.providers.requested_attributes"),+ description: t("saml.providers.section_texts.requested_attributes")+ ))endend+end%>+<% end %>diff --git a/modules/auth_saml/app/components/saml/providers/view_component.rb b/modules/auth_saml/app/components/saml/providers/view_component.rbindex 75ddf562dfd..75cc6121ee8 100644--- a/modules/auth_saml/app/components/saml/providers/view_component.rb+++ b/modules/auth_saml/app/components/saml/providers/view_component.rb@@ -30,6 +30,7 @@#module Saml::Providersclass ViewComponent < ApplicationComponent+ include OpTurbo::Streamableinclude OpPrimer::ComponentHelpersoptions :view_mode, :edit_statediff --git a/modules/auth_saml/app/controllers/saml/providers_controller.rb b/modules/auth_saml/app/controllers/saml/providers_controller.rbindex c3c9f6d87a4..ecb05e69c1c 100644--- a/modules/auth_saml/app/controllers/saml/providers_controller.rb+++ b/modules/auth_saml/app/controllers/saml/providers_controller.rb@@ -1,5 +1,7 @@module Samlclass ProvidersController < ::ApplicationController+ include OpTurbo::ComponentStream+layout "admin"menu_item :plugin_saml@@ -14,6 +16,18 @@ module Samldef edit@edit_state = params[:edit_state].to_sym if params.key?(:edit_state)++ respond_to do |format|+ format.turbo_stream do+ component = Saml::Providers::ViewComponent.new(@provider,+ view_mode: :edit,+ edit_state: @edit_state)+ update_via_turbo_stream(component:)+ scroll_into_view_via_turbo_stream("saml-providers-edit-form", behavior: :instant)+ render turbo_stream: turbo_streams, status:+ end+ format.html+ endenddef show; end