Skip to content

Commit 5e5956a

Browse files
Utilize wizard in StorageViewComponent
The storage view component now has no own "opinion" on the display order and grouping of steps anymore, but will merely reflect the wizard configuration. Changes in the wizard are immediately reflected in the UI as well. Selection of the right components was also extracted into the storage registries. Renamings of existing translations were in most cases avoided, by renaming wizard steps according to existing translations. This made it necessary to unify the instantiation of all components rendered inside the storage view, which was relatively straight-forward for most of them. The OAuthClientFormComponent was challenging, as there was one use case where it needed to be initialized with a client that was not yet assigned to the storage.
1 parent e925349 commit 5e5956a

25 files changed

+156
-184
lines changed

modules/storages/app/common/storages/peripherals/nextcloud_registry.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,19 @@ module Peripherals
5858
end
5959

6060
namespace("components") do
61+
namespace("forms") do
62+
register(:automatically_managed_folders, ::Storages::Admin::Forms::AutomaticallyManagedProjectFoldersFormComponent)
63+
register(:general_information, ::Storages::Admin::Forms::GeneralInfoFormComponent)
64+
register(:oauth_application, ::Storages::Admin::OAuthApplicationInfoCopyComponent)
65+
register(:oauth_client, ::Storages::Admin::Forms::OAuthClientFormComponent)
66+
end
67+
6168
register(:setup_wizard, NextcloudStorageWizard)
69+
70+
register(:automatically_managed_folders, ::Storages::Admin::AutomaticallyManagedProjectFoldersInfoComponent)
71+
register(:general_information, ::Storages::Admin::GeneralInfoComponent)
72+
register(:oauth_application, ::Storages::Admin::OAuthApplicationInfoComponent)
73+
register(:oauth_client, ::Storages::Admin::OAuthClientInfoComponent)
6274
end
6375

6476
namespace("contracts") do

modules/storages/app/common/storages/peripherals/nextcloud_storage_wizard.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,19 @@
3131
module Storages
3232
module Peripherals
3333
class NextcloudStorageWizard < Wizard
34-
step :general_info, completed_if: ->(storage) { storage.host.present? && storage.name.present? }
34+
step :general_information, completed_if: ->(storage) { storage.host.present? && storage.name.present? }
3535

3636
step :oauth_application,
37+
section: :oauth_configuration,
3738
completed_if: ->(storage) { storage.oauth_application.present? },
3839
preparation: :prepare_oauth_application
3940

4041
step :oauth_client,
42+
section: :oauth_configuration,
4143
completed_if: ->(storage) { storage.oauth_client.present? },
4244
preparation: ->(storage) { storage.build_oauth_client }
4345

44-
step :automatically_managed_project_folders,
46+
step :automatically_managed_folders,
4547
completed_if: ->(storage) { !storage.automatic_management_unspecified? },
4648
preparation: :prepare_storage_for_automatic_management_form
4749

modules/storages/app/common/storages/peripherals/one_drive_registry.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,19 @@ module Peripherals
5252
end
5353

5454
namespace("components") do
55+
namespace("forms") do
56+
register(:access_management, ::Storages::Admin::Forms::AccessManagementFormComponent)
57+
register(:general_information, ::Storages::Admin::Forms::GeneralInfoFormComponent)
58+
register(:oauth_client, ::Storages::Admin::Forms::OAuthClientFormComponent)
59+
register(:redirect_uri, ::Storages::Admin::Forms::RedirectUriFormComponent)
60+
end
61+
5562
register(:setup_wizard, OneDriveStorageWizard)
63+
64+
register(:access_management, ::Storages::Admin::AccessManagementComponent)
65+
register(:general_information, ::Storages::Admin::GeneralInfoComponent)
66+
register(:oauth_client, ::Storages::Admin::OAuthClientInfoComponent)
67+
register(:redirect_uri, ::Storages::Admin::RedirectUriComponent)
5668
end
5769

5870
namespace("contracts") do

modules/storages/app/common/storages/peripherals/one_drive_storage_wizard.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,20 @@
3131
module Storages
3232
module Peripherals
3333
class OneDriveStorageWizard < Wizard
34-
step :general_info, completed_if: ->(storage) { storage.name.present? }
34+
step :general_information, completed_if: ->(storage) { storage.name.present? }
3535

3636
step :access_management,
37+
section: :access_management_section,
3738
completed_if: ->(storage) { !storage.automatic_management_unspecified? },
3839
preparation: :prepare_storage_for_access_management_form
3940

4041
step :oauth_client,
42+
section: :oauth_configuration,
4143
completed_if: ->(storage) { storage.oauth_client.present? },
4244
preparation: ->(storage) { storage.build_oauth_client }
4345

4446
step :redirect_uri,
47+
section: :oauth_configuration,
4548
completed_if: ->(storage) {
4649
storage.oauth_client&.created_at && storage.oauth_client.created_at < 3.seconds.ago # HACK HACK HACK
4750
}

modules/storages/app/components/storages/admin/forms/oauth_client_form_component.rb

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,12 @@ class OAuthClientFormComponent < ApplicationComponent
3333
include OpPrimer::ComponentHelpers
3434
include OpTurbo::Streamable
3535

36-
attr_reader :storage
37-
alias_method :oauth_client, :model
36+
alias_method :storage, :model
3837

3938
options in_wizard: false
4039

4140
def self.wrapper_key = :storage_oauth_client_section
4241

43-
def initialize(oauth_client:, storage:, **)
44-
super(oauth_client, **)
45-
@storage = storage
46-
end
47-
4842
def form_url
4943
query = { continue_wizard: storage.id } if in_wizard
5044
admin_settings_storage_oauth_client_path(storage, query)
@@ -65,6 +59,10 @@ def storage_provider_credentials_instructions
6559

6660
private
6761

62+
def oauth_client
63+
options[:oauth_client] || storage.oauth_client
64+
end
65+
6866
def one_drive_integration_link(target: "_blank")
6967
href = ::OpenProject::Static::Links[:storage_docs][:one_drive_oauth_application][:href]
7068
render(Primer::Beta::Link.new(href:, target:)) { I18n.t("storages.instructions.one_drive.application_link_text") }

modules/storages/app/components/storages/admin/forms/redirect_uri_form_component.rb

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,13 @@ class RedirectUriFormComponent < ApplicationComponent
3333
include OpPrimer::ComponentHelpers
3434
include OpTurbo::Streamable
3535

36-
attr_reader :storage
37-
alias_method :oauth_client, :model
36+
alias_method :storage, :model
37+
delegate :oauth_client, to: :storage
3838

3939
options in_wizard: false
4040

4141
def self.wrapper_key = :storage_redirect_uri_section
4242

43-
def initialize(oauth_client:, storage:, **)
44-
super(oauth_client, **)
45-
@storage = storage
46-
end
47-
4843
def form_url
4944
query = { continue_wizard: storage.id } if in_wizard
5045
finish_setup_admin_settings_storage_oauth_client_path(storage, query)

modules/storages/app/components/storages/admin/oauth_application_info_component.rb

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,8 @@ class OAuthApplicationInfoComponent < ApplicationComponent
3434
include OpTurbo::Streamable
3535
include StorageViewInformation
3636

37-
attr_reader :storage
38-
alias_method :oauth_application, :model
39-
40-
def initialize(oauth_application:, storage:, **)
41-
super(oauth_application, **)
42-
@storage = storage
43-
end
37+
alias_method :storage, :model
38+
delegate :oauth_application, to: :storage
4439

4540
def self.wrapper_key = :storage_openproject_oauth_section
4641
end

modules/storages/app/components/storages/admin/oauth_application_info_copy_component.rb

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,11 @@ class OAuthApplicationInfoCopyComponent < ApplicationComponent
3333
include OpTurbo::Streamable
3434
include OpPrimer::ComponentHelpers
3535

36-
attr_reader :storage
37-
alias_method :oauth_application, :model
36+
alias_method :storage, :model
37+
delegate :oauth_application, to: :storage
3838

3939
options in_wizard: false
4040

41-
def initialize(oauth_application:, storage:, **)
42-
super(oauth_application, **)
43-
@storage = storage
44-
end
45-
4641
def self.wrapper_key = :storage_openproject_oauth_section
4742

4843
def oauth_application_details_link

modules/storages/app/components/storages/admin/oauth_client_info_component.rb

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,8 @@ class OAuthClientInfoComponent < ApplicationComponent
3434
include OpTurbo::Streamable
3535
include StorageViewInformation
3636

37-
attr_reader :storage
38-
alias_method :oauth_client, :model
39-
40-
def initialize(oauth_client:, storage:, **)
41-
super(oauth_client, **)
42-
@storage = storage
43-
end
37+
alias_method :storage, :model
38+
delegate :oauth_client, to: :storage
4439

4540
def self.wrapper_key = :storage_oauth_client_section
4641

modules/storages/app/components/storages/admin/redirect_uri_component.rb

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,8 @@ class RedirectUriComponent < ApplicationComponent
3434
include OpTurbo::Streamable
3535
include StorageViewInformation
3636

37-
attr_reader :storage
38-
alias_method :oauth_client, :model
39-
40-
def initialize(oauth_client:, storage:, **)
41-
super(oauth_client, **)
42-
@storage = storage
43-
end
37+
alias_method :storage, :model
38+
delegate :oauth_client, to: :storage
4439

4540
def self.wrapper_key = :storage_redirect_uri_section
4641

0 commit comments

Comments
 (0)