From 0e10a1d4704035dfafcf26d16d9ba528e8aeac63 Mon Sep 17 00:00:00 2001 From: Kabiru Mwenja Date: Mon, 27 May 2024 16:30:51 +0300 Subject: [PATCH 1/4] [#55196] Wrong menu entry when deactivating a project attribute (not "Delete") https://community.openproject.org/work_packages/55196 --- app/components/projects/row_component.rb | 2 +- .../project_custom_field_mapping/row_component.rb | 6 +++--- config/locales/en.yml | 1 + 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/components/projects/row_component.rb b/app/components/projects/row_component.rb index 6dd80c99c2cd..695a210683c4 100644 --- a/app/components/projects/row_component.rb +++ b/app/components/projects/row_component.rb @@ -227,7 +227,7 @@ def action_menu label:, test_selector: "project-list-row--action-menu-item", content_arguments: button_options) do |item| - item.with_leading_visual_icon(icon:) + item.with_leading_visual_icon(icon:) if icon end end end diff --git a/app/components/settings/project_custom_fields/project_custom_field_mapping/row_component.rb b/app/components/settings/project_custom_fields/project_custom_field_mapping/row_component.rb index 0d346fe4659b..b7065bee591b 100644 --- a/app/components/settings/project_custom_fields/project_custom_field_mapping/row_component.rb +++ b/app/components/settings/project_custom_fields/project_custom_field_mapping/row_component.rb @@ -45,9 +45,9 @@ def more_menu_items def more_menu_detach_project if User.current.admin { - scheme: :danger, - icon: :trash, - label: I18n.t(:button_delete), + scheme: :default, + icon: nil, + label: I18n.t("projects.settings.project_custom_fields.actions.deactivate_for_project"), href: unlink_admin_settings_project_custom_field_path( id: @table.params[:custom_field].id, project_custom_field_project_mapping: { project_id: model.first.id } diff --git a/config/locales/en.yml b/config/locales/en.yml index e83f4cdbcded..25630f88bbc9 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -326,6 +326,7 @@ Project attributes and sections are defined in the Date: Mon, 27 May 2024 18:00:00 +0300 Subject: [PATCH 2/4] fix[Op#55195]: Render blank slate in place of project list for required CF --- .../project_mappings.html.erb | 17 +++++++++++++---- config/locales/en.yml | 3 +++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/app/views/admin/settings/project_custom_fields/project_mappings.html.erb b/app/views/admin/settings/project_custom_fields/project_mappings.html.erb index 4bdb9e3605de..81ea4a499670 100644 --- a/app/views/admin/settings/project_custom_fields/project_mappings.html.erb +++ b/app/views/admin/settings/project_custom_fields/project_mappings.html.erb @@ -37,8 +37,17 @@ See COPYRIGHT and LICENSE files for more details. %> <%= - render(Settings::ProjectCustomFields::ProjectCustomFieldMapping::TableComponent.new( - query: @project_custom_field_mappings_query, - params: { custom_field: @custom_field }) - ) + + if @custom_field.required? + render Primer::Beta::Blankslate.new(border: true) do |component| + component.with_visual_icon(icon: :checklist) + component.with_heading(tag: :h2).with_content(I18n.t("projects.settings.project_custom_fields.is_required_blank_slate.heading")) + component.with_description { I18n.t("projects.settings.project_custom_fields.is_required_blank_slate.description") } + end + else + render(Settings::ProjectCustomFields::ProjectCustomFieldMapping::TableComponent.new( + query: @project_custom_field_mappings_query, + params: { custom_field: @custom_field }) + ) + end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 25630f88bbc9..869d0ac23da5 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -329,6 +329,9 @@ Project attributes and sections are defined in the Date: Tue, 28 May 2024 13:15:24 +0300 Subject: [PATCH 3/4] tests[Op#55196]: update project custom field mappings feature tests --- .../project_custom_fields/project_mappings_spec.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/spec/features/admin/project_custom_fields/project_mappings_spec.rb b/spec/features/admin/project_custom_fields/project_mappings_spec.rb index 0d9f88287fcb..9eb5f65b0f7f 100644 --- a/spec/features/admin/project_custom_fields/project_mappings_spec.rb +++ b/spec/features/admin/project_custom_fields/project_mappings_spec.rb @@ -76,14 +76,22 @@ it "renders more menu list item" do project_custom_field_mappings_page.activate_menu_of(project) do |menu| - expect(menu).to have_link("Delete") + expect(menu).to have_link("Deactivate for this project") end end it "allows to unlink a project" do - project_custom_field_mappings_page.click_menu_item_of("Delete", project) + project_custom_field_mappings_page.click_menu_item_of("Deactivate for this project", project) expect(page).to have_no_text(project.name) end + + context "and the project custom field is required" do + shared_let(:project_custom_field) { create(:project_custom_field, is_required: true) } + + it "renders a blank slate" do + expect(page).to have_text("Required in all projects") + end + end end end From 14d343fb39197874e0a1892f2e0c73aa2926c1ba Mon Sep 17 00:00:00 2001 From: Kabiru Mwenja Date: Tue, 28 May 2024 13:28:32 +0300 Subject: [PATCH 4/4] tests[Op#55196]: collapse assertions for efficiency Avoid revisiting each page to run assertions. Instead, just run aggregated assertions. --- .../project_mappings_spec.rb | 46 +++++++++---------- 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/spec/features/admin/project_custom_fields/project_mappings_spec.rb b/spec/features/admin/project_custom_fields/project_mappings_spec.rb index 9eb5f65b0f7f..2491b114c14a 100644 --- a/spec/features/admin/project_custom_fields/project_mappings_spec.rb +++ b/spec/features/admin/project_custom_fields/project_mappings_spec.rb @@ -52,38 +52,34 @@ visit project_mappings_admin_settings_project_custom_field_path(project_custom_field) end - it "shows a correct breadcrumb menu" do - within ".PageHeader-breadcrumbs" do - expect(page).to have_link("Administration") - expect(page).to have_link("Projects") - expect(page).to have_link("Project attributes") - expect(page).to have_text(project_custom_field.name) + it "renders the project custom field mappings page" do + aggregate_failures "shows a correct breadcrumb menu" do + within ".PageHeader-breadcrumbs" do + expect(page).to have_link("Administration") + expect(page).to have_link("Projects") + expect(page).to have_link("Project attributes") + expect(page).to have_text(project_custom_field.name) + end end - end - it "shows tab navigation" do - within_test_selector("project_attribute_detail_header") do - expect(page).to have_link("Details") - expect(page).to have_link("Projects") + aggregate_failures "shows tab navigation" do + within_test_selector("project_attribute_detail_header") do + expect(page).to have_link("Details") + expect(page).to have_link("Projects") + end end - end - it "shows the correct project mappings" do - within "#project-table" do - expect(page).to have_text(project.name) + aggregate_failures "shows the correct project mappings" do + within "#project-table" do + expect(page).to have_text(project.name) + end end - end - it "renders more menu list item" do - project_custom_field_mappings_page.activate_menu_of(project) do |menu| - expect(menu).to have_link("Deactivate for this project") - end - end - - it "allows to unlink a project" do - project_custom_field_mappings_page.click_menu_item_of("Deactivate for this project", project) + aggregate_failures "allows to unlinking a project" do + project_custom_field_mappings_page.click_menu_item_of("Deactivate for this project", project) - expect(page).to have_no_text(project.name) + expect(page).to have_no_text(project.name) + end end context "and the project custom field is required" do