Skip to content

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

Do not pass down the project.project_custom_field_project_mappings to the CustomFieldRowComponent but call it from the project object.

Dombi Attilad05351b1d812
diff --git a/app/components/projects/settings/project_custom_field_sections/custom_field_row_component.rb b/app/components/projects/settings/project_custom_field_sections/custom_field_row_component.rb
index 4186ad637aa..3cb77666b6d 100644
--- a/app/components/projects/settings/project_custom_field_sections/custom_field_row_component.rb
+++ b/app/components/projects/settings/project_custom_field_sections/custom_field_row_component.rb
@@ -34,12 +34,12 @@ module Projects
include OpPrimer::ComponentHelpers
include OpTurbo::Streamable
- def initialize(project:, project_custom_field:, project_custom_field_project_mappings:)
+ def initialize(project:, project_custom_field:)
super
@project = project
@project_custom_field = project_custom_field
- @project_custom_field_project_mappings = project_custom_field_project_mappings
+ @project_custom_field_project_mappings = project.project_custom_field_project_mappings
end
private
diff --git a/app/components/projects/settings/project_custom_field_sections/index_component.html.erb b/app/components/projects/settings/project_custom_field_sections/index_component.html.erb
index 93fd9e55e32..5da79313acf 100644
--- a/app/components/projects/settings/project_custom_field_sections/index_component.html.erb
+++ b/app/components/projects/settings/project_custom_field_sections/index_component.html.erb
@@ -24,9 +24,7 @@
flex.with_row do
render(Projects::Settings::ProjectCustomFieldSections::ShowComponent.new(
project: @project,
- project_custom_field_section:,
- project_custom_fields: project_custom_field_section.custom_fields,
- project_custom_field_project_mappings: @project_custom_field_project_mappings
+ project_custom_field_section:
))
end
end
diff --git a/app/components/projects/settings/project_custom_field_sections/index_component.rb b/app/components/projects/settings/project_custom_field_sections/index_component.rb
index 3eeb7667442..38f061e9a5f 100644
--- a/app/components/projects/settings/project_custom_field_sections/index_component.rb
+++ b/app/components/projects/settings/project_custom_field_sections/index_component.rb
@@ -34,16 +34,11 @@ module Projects
include OpPrimer::ComponentHelpers
include OpTurbo::Streamable
- def initialize(
- project:,
- project_custom_field_sections:,
- project_custom_field_project_mappings:
- )
+ def initialize(project:, project_custom_field_sections:)
super
@project = project
@project_custom_field_sections = project_custom_field_sections
- @project_custom_field_project_mappings = project_custom_field_project_mappings
end
private
diff --git a/app/components/projects/settings/project_custom_field_sections/show_component.html.erb b/app/components/projects/settings/project_custom_field_sections/show_component.html.erb
index 3571e88b9e7..58f145a2f55 100644
--- a/app/components/projects/settings/project_custom_field_sections/show_component.html.erb
+++ b/app/components/projects/settings/project_custom_field_sections/show_component.html.erb
@@ -64,7 +64,6 @@
render(Projects::Settings::ProjectCustomFieldSections::CustomFieldRowComponent.new(
project: @project,
project_custom_field:,
- project_custom_field_project_mappings: @project_custom_field_project_mappings,
))
end
end
diff --git a/app/components/projects/settings/project_custom_field_sections/show_component.rb b/app/components/projects/settings/project_custom_field_sections/show_component.rb
index a1ef3289deb..df2b2c634ae 100644
--- a/app/components/projects/settings/project_custom_field_sections/show_component.rb
+++ b/app/components/projects/settings/project_custom_field_sections/show_component.rb
@@ -34,18 +34,12 @@ module Projects
include OpPrimer::ComponentHelpers
include OpTurbo::Streamable
- def initialize(
- project:,
- project_custom_field_section:,
- project_custom_fields:,
- project_custom_field_project_mappings:
- )
+ def initialize(project:, project_custom_field_section:)
super
@project = project
@project_custom_field_section = project_custom_field_section
- @project_custom_fields = project_custom_fields
- @project_custom_field_project_mappings = project_custom_field_project_mappings
+ @project_custom_fields = project_custom_field_section.custom_fields
end
private
diff --git a/app/controllers/concerns/admin/settings/project_custom_fields/component_streams.rb b/app/controllers/concerns/admin/settings/project_custom_fields/component_streams.rb
index a9b35de02cf..7acd2087bb5 100644
--- a/app/controllers/concerns/admin/settings/project_custom_fields/component_streams.rb
+++ b/app/controllers/concerns/admin/settings/project_custom_fields/component_streams.rb
@@ -42,6 +42,9 @@ module Admin
def update_section_via_turbo_stream(project_custom_field_section:)
update_via_turbo_stream(
component: ::Settings::ProjectCustomFieldSections::ShowComponent.new(
+ # Note: `first_and_last:` argument is necessary here, because we render
+ # a single custom field section, and not a list of sections. Calling first?
+ # and last? method in the component will not result in an N+1 in this case.
project_custom_field_section:
)
)
diff --git a/app/controllers/concerns/projects/settings/project_custom_fields/component_streams.rb b/app/controllers/concerns/projects/settings/project_custom_fields/component_streams.rb
index 1ed5c490542..0b126e565c4 100644
--- a/app/controllers/concerns/projects/settings/project_custom_fields/component_streams.rb
+++ b/app/controllers/concerns/projects/settings/project_custom_fields/component_streams.rb
@@ -35,14 +35,12 @@ module Projects
included do
def update_sections_via_turbo_stream(
project: @project,
- project_custom_field_sections: @project_custom_field_sections,
- project_custom_field_project_mappings: @project_custom_field_project_mappings
+ project_custom_field_sections: @project_custom_field_sections
)
update_via_turbo_stream(
component: ::Projects::Settings::ProjectCustomFieldSections::IndexComponent.new(
project:,
- project_custom_field_sections:,
- project_custom_field_project_mappings:
+ project_custom_field_sections:
)
)
end
diff --git a/app/controllers/projects/settings/project_custom_fields_controller.rb b/app/controllers/projects/settings/project_custom_fields_controller.rb
index b4c3e7527a0..9dbcb329fe5 100644
--- a/app/controllers/projects/settings/project_custom_fields_controller.rb
+++ b/app/controllers/projects/settings/project_custom_fields_controller.rb
@@ -90,10 +90,6 @@ class Projects::Settings::ProjectCustomFieldsController < Projects::SettingsCont
.merge(ProjectCustomField.visible)
.group(:id, "custom_fields.id")
.order(:position, :position_in_custom_field_section)
-
- @project_custom_field_project_mappings = ProjectCustomFieldProjectMapping
- .where(project_id: @project.id)
- .to_a
end
def set_project_custom_field_section
diff --git a/app/views/projects/settings/project_custom_fields/show.html.erb b/app/views/projects/settings/project_custom_fields/show.html.erb
index 4ec951b20b7..c6fae909ca8 100644
--- a/app/views/projects/settings/project_custom_fields/show.html.erb
+++ b/app/views/projects/settings/project_custom_fields/show.html.erb
@@ -37,7 +37,6 @@ See COPYRIGHT and LICENSE files for more details.
<%= render(Projects::Settings::ProjectCustomFieldSections::IndexComponent.new(
project: @project,
project_custom_field_sections: @project_custom_field_sections,
- project_custom_field_project_mappings: @project_custom_field_project_mappings,
)) %>
</div>