From dd7378cc05dc44ceb1fdbee0ea15850b6523008c Mon Sep 17 00:00:00 2001 From: ulferts Date: Wed, 26 Nov 2025 17:03:55 +0100 Subject: [PATCH] hide parent selection on portfolio creation --- app/components/projects/new_component.html.erb | 2 +- app/components/projects/new_component.rb | 4 ++++ app/models/project.rb | 2 -- app/models/projects/hierarchy.rb | 6 ++++++ spec/features/portfolios/create_spec.rb | 6 +++--- 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/app/components/projects/new_component.html.erb b/app/components/projects/new_component.html.erb index 5b5bd5ef4e0..73ac8e1c768 100644 --- a/app/components/projects/new_component.html.erb +++ b/app/components/projects/new_component.html.erb @@ -40,7 +40,7 @@ See COPYRIGHT and LICENSE files for more details. Primer::Forms::FormList.new( Projects::Settings::NameForm.new(f), Projects::Settings::DescriptionForm.new(f), - Projects::Settings::RelationsForm.new(f, visible: params[:parent_id].blank?), + Projects::Settings::RelationsForm.new(f, visible: relation_form_visible?), Projects::Settings::TypeForm.new(f) ) ) diff --git a/app/components/projects/new_component.rb b/app/components/projects/new_component.rb index 977992a2524..f537b67698b 100644 --- a/app/components/projects/new_component.rb +++ b/app/components/projects/new_component.rb @@ -53,5 +53,9 @@ module Projects url_for(workspace_type.pluralize.to_sym) end + + def relation_form_visible? + project.parent_allowed? && params[:parent_id].blank? + end end end diff --git a/app/models/project.rb b/app/models/project.rb index 37a381cd8bf..b96e53146c5 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -279,8 +279,6 @@ class Project < ApplicationRecord name end - def allowed_parent_workspace_types = ALLOWED_PARENT_WORKSPACE_TYPES[workspace_type] || [] - def workspace_label case workspace_type when "program" diff --git a/app/models/projects/hierarchy.rb b/app/models/projects/hierarchy.rb index d1ab5a48e35..aba7deb4e5d 100644 --- a/app/models/projects/hierarchy.rb +++ b/app/models/projects/hierarchy.rb @@ -171,5 +171,11 @@ module Projects::Hierarchy end stmt end + + def allowed_parent_workspace_types = Project::ALLOWED_PARENT_WORKSPACE_TYPES[workspace_type] || [] + + def parent_allowed? + allowed_parent_workspace_types.any? + end end end diff --git a/spec/features/portfolios/create_spec.rb b/spec/features/portfolios/create_spec.rb index 91e97508246..eb5ff96b60c 100644 --- a/spec/features/portfolios/create_spec.rb +++ b/spec/features/portfolios/create_spec.rb @@ -65,9 +65,9 @@ RSpec.describe "Portfolios", # Step 2: Fill in project details fill_in "Name", with: "Foo bar" - expect(page).to have_combo_box "Subproject of" - parent_field.expect_no_option "Other portfolio" - parent_field.expect_no_option "Root portfolio" # Since no a project cannot have a parent + # No parent field since portfolios are always root elements + expect(page) + .not_to have_combo_box "Subproject of" click_on "Complete"