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

Simplify the Project settings project custom fields page.

Dombi Attilabeed93d15485
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 9e23142ac9e..93fd9e55e32 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
@@ -19,12 +19,13 @@
}
))
end
- @project_custom_fields_grouped_by_section.each do |section_id, project_custom_fields|
+
+ @project_custom_field_sections.each do |project_custom_field_section|
flex.with_row do
render(Projects::Settings::ProjectCustomFieldSections::ShowComponent.new(
project: @project,
- project_custom_field_section: get_eager_loaded_project_custom_field_section(section_id),
- project_custom_fields:,
+ project_custom_field_section:,
+ project_custom_fields: project_custom_field_section.custom_fields,
project_custom_field_project_mappings: @project_custom_field_project_mappings
))
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 d635000fc71..3eeb7667442 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
@@ -37,14 +37,12 @@ module Projects
def initialize(
project:,
project_custom_field_sections:,
- project_custom_fields_grouped_by_section:,
project_custom_field_project_mappings:
)
super
@project = project
@project_custom_field_sections = project_custom_field_sections
- @project_custom_fields_grouped_by_section = project_custom_fields_grouped_by_section
@project_custom_field_project_mappings = project_custom_field_project_mappings
end
@@ -56,10 +54,6 @@ module Projects
'application-target': 'dynamic'
}
end
-
- def get_eager_loaded_project_custom_field_section(section_id)
- @project_custom_field_sections.find { |section| section.id == section_id }
- end
end
end
end
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 1e1f1cd5f2d..1ed5c490542 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
@@ -36,14 +36,12 @@ module Projects
def update_sections_via_turbo_stream(
project: @project,
project_custom_field_sections: @project_custom_field_sections,
- project_custom_fields_grouped_by_section: @project_custom_fields_grouped_by_section,
project_custom_field_project_mappings: @project_custom_field_project_mappings
)
update_via_turbo_stream(
component: ::Projects::Settings::ProjectCustomFieldSections::IndexComponent.new(
project:,
project_custom_field_sections:,
- project_custom_fields_grouped_by_section:,
project_custom_field_project_mappings:
)
)
diff --git a/app/controllers/projects/settings/project_custom_fields_controller.rb b/app/controllers/projects/settings/project_custom_fields_controller.rb
index 07dc498dfaa..950e0d4566c 100644
--- a/app/controllers/projects/settings/project_custom_fields_controller.rb
+++ b/app/controllers/projects/settings/project_custom_fields_controller.rb
@@ -82,13 +82,13 @@ class Projects::Settings::ProjectCustomFieldsController < Projects::SettingsCont
private
def eager_load_project_custom_field_data
- @project_custom_field_sections = ProjectCustomFieldSection.all.to_a
-
- @project_custom_fields_grouped_by_section = ProjectCustomField
- .visible
- .includes(:project_custom_field_section)
- .sort_by { |pcf| pcf.project_custom_field_section.position }
- .group_by(&:custom_field_section_id)
+ # Load only the sections that have custom_fields associated
+ @project_custom_field_sections =
+ ProjectCustomFieldSection
+ .joins(:custom_fields)
+ .includes(:custom_fields)
+ .group(:id, "custom_fields.id")
+ .order(:position)
@project_custom_field_project_mappings = ProjectCustomFieldProjectMapping
.where(project_id: @project.id)
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 0941aa2111f..4ec951b20b7 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_fields_grouped_by_section: @project_custom_fields_grouped_by_section,
project_custom_field_project_mappings: @project_custom_field_project_mappings,
)) %>
</div>