Skip to content

Commit

Permalink
chore[Op#51022]: update edit page with provider type
Browse files Browse the repository at this point in the history
  • Loading branch information
akabiru committed Nov 28, 2023
1 parent 42138fb commit e384eb9
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
flex_layout do |general_info_row|
general_info_row.with_row(mb: 3) do
concat(render(Primer::Beta::Text.new(font_weight: :bold)) { I18n.t("storages.label_file_storage") })
concat(render(Storages::Admin::ProviderTypeHiddenInputForm.new(form, storage:)))
concat(render(Storages::Admin::ProviderTypeHiddenInputForm.new(form, storage:))) if storage.new_record?
end

general_info_row.with_row(mb: 3) do
Expand Down
43 changes: 25 additions & 18 deletions modules/storages/app/views/storages/admin/storages/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,20 @@ See COPYRIGHT and LICENSE files for more details.
++#%>

<%
label_storage_provider_part = render(Primer::Beta::Text.new(tag: :span, font_weight: :light, color: :muted)) do
"(#{I18n.t("storages.provider_types.#{@storage.short_provider_type}.name")})"
end
label_storage_name_with_provider_label = "#{@storage.name} #{label_storage_provider_part}".html_safe
%>

<% html_title t(:label_administration), t("project_module_storages"), t('label_edit_x', x: @storage.name) %>
<% local_assigns[:additional_breadcrumb] = @storage.name %>

<%= render(Primer::OpenProject::PageHeader.new) do |header| %>
<% header.with_title(test_selector: 'storage-new-page-header--title') do %>
<%= render OpTurbo::FrameComponent.new(@storage, context: :edit_storage_header) do %>
<%= @storage.name %>
<%= label_storage_name_with_provider_label %>
<% end %>
<% end %>

Expand All @@ -45,24 +52,24 @@ See COPYRIGHT and LICENSE files for more details.

<% header.with_actions do %>
<%=
primer_form_with(
model: @storage,
url: confirm_destroy_admin_settings_storage_path(@storage),
method: :get
) do |_form|
render(
Primer::Beta::Button.new(
scheme: :danger,
size: :medium,
type: :submit,
aria: { label: I18n.t("storages.label_delete_storage") },
test_selector: 'storage-delete-button'
)
) do |button|
button.with_leading_visual_icon(icon: :trash)
I18n.t('button_delete')
primer_form_with(
model: @storage,
url: confirm_destroy_admin_settings_storage_path(@storage),
method: :get
) do |_form|
render(
Primer::Beta::Button.new(
scheme: :danger,
size: :medium,
type: :submit,
aria: { label: I18n.t("storages.label_delete_storage") },
test_selector: 'storage-delete-button'
)
) do |button|
button.with_leading_visual_icon(icon: :trash)
I18n.t('button_delete')
end
end
end
%>
<% end %>
<% end %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
) { t("storages.instructions.file_storage_docs_link", provider_name: I18n.t("storages.provider_types.#{@storage.short_provider_type}.name")) }

Check notice

Code scanning / Brakeman

Unescaped parameter value. Note

Unescaped parameter value.
).html_safe
%>
<% end %>
<% end %>

<%= render(Storages::Admin::StorageViewComponent.new(@storage)) %>
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
<%
label_storage_provider_part = render(Primer::Beta::Text.new(tag: :span, font_weight: :light, color: :muted)) do
"(#{I18n.t("storages.provider_types.#{@storage.short_provider_type}.name")})"
end
label_storage_name_with_provider_label = "#{@storage.name} #{label_storage_provider_part}".html_safe
%>

<%= turbo_stream.update dom_id(@storage, :edit_storage_header) do %>
<%= @storage.name %>
<%= label_storage_name_with_provider_label %>
<% end %>

<%= turbo_stream.update :full_breadcrumbs do %>
<%
breadcrumb_paths(
Expand Down
16 changes: 6 additions & 10 deletions modules/storages/spec/features/admin_storages_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@
end
end

describe 'File storage edit view' do
describe 'Edit file storage' do
it 'renders a danger zone for deletion' do
storage = create(:nextcloud_storage, name: "Foo Nextcloud")
visit edit_admin_settings_storage_path(storage)
Expand All @@ -327,7 +327,7 @@
end

context 'with Nextcloud Storage' do
let(:storage) { create(:nextcloud_storage, :as_automatically_managed) }
let(:storage) { create(:nextcloud_storage, :as_automatically_managed, name: 'Cloud Storage') }
let(:oauth_application) { create(:oauth_application, integration: storage) }
let(:oauth_client) { create(:oauth_client, integration: storage) }
let(:secret) { 'awesome_secret' }
Expand All @@ -341,7 +341,7 @@
it 'renders an edit view', :webmock do
visit edit_admin_settings_storage_path(storage)

expect(page).to have_test_selector('storage-new-page-header--title', text: storage.name.capitalize)
expect(page).to have_test_selector('storage-new-page-header--title', text: "Cloud Storage (Nextcloud)")

aggregate_failures 'Storage edit view' do
# General information
Expand Down Expand Up @@ -374,13 +374,11 @@
# Update a storage - happy path
find_test_selector('storage-edit-host-button').click
within_test_selector('storage-general-info-form') do
expect(page).to have_css('#storages_nextcloud_storage_provider_type[disabled]')

fill_in 'storages_nextcloud_storage_name', with: 'My Nextcloud'
click_button 'Save and continue'
end

expect(page).to have_test_selector('storage-new-page-header--title', text: 'My Nextcloud')
expect(page).to have_test_selector('storage-new-page-header--title', text: 'My Nextcloud (Nextcloud)')
expect(page).to have_test_selector('storage-description', text: "Nextcloud - My Nextcloud - #{storage.host}")

# Update a storage - unhappy path
Expand Down Expand Up @@ -489,7 +487,7 @@
it 'renders an edit view', :webmock do
visit edit_admin_settings_storage_path(storage)

expect(page).to have_test_selector('storage-new-page-header--title', text: 'Test Drive')
expect(page).to have_test_selector('storage-new-page-header--title', text: 'Test Drive (OneDrive/SharePoint)')

aggregate_failures 'Storage edit view' do
# General information
Expand All @@ -509,13 +507,11 @@
# Update a storage - happy path
find_test_selector('storage-edit-host-button').click
within_test_selector('storage-general-info-form') do
expect(page).to have_css('#storages_one_drive_storage_provider_type[disabled]')

fill_in 'storages_one_drive_storage_name', with: 'My OneDrive'
click_button 'Save and continue'
end

expect(page).to have_test_selector('storage-new-page-header--title', text: 'My OneDrive')
expect(page).to have_test_selector('storage-new-page-header--title', text: 'My OneDrive (OneDrive/SharePoint)')
expect(page).to have_test_selector('storage-description', text: 'OneDrive/SharePoint - My OneDrive')

# Update a storage - unhappy path
Expand Down

0 comments on commit e384eb9

Please sign in to comment.