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

Reuse same items for both menus

Oliver Günther05ce906f1c9e
diff --git a/app/components/work_package_relations_tab/index_component.html.erb b/app/components/work_package_relations_tab/index_component.html.erb
index c12694bc30e..3682a3d76da 100644
--- a/app/components/work_package_relations_tab/index_component.html.erb
+++ b/app/components/work_package_relations_tab/index_component.html.erb
@@ -18,6 +18,8 @@
t(:label_relation)
end
+ render_child_items(menu)
+
if should_render_add_relations?
Relation::TYPES.each do |relation_type, type_configuration_hash|
label_key = "#{I18N_NAMESPACE}.relations.#{type_configuration_hash[:name]}_singular"
@@ -33,19 +35,6 @@
end
end
end
-
- if should_render_add_child?
- menu.with_item(
- label: t("#{I18N_NAMESPACE}.relations.label_child_singular").capitalize,
- href: new_work_package_children_relation_path(@work_package),
- test_selector: new_button_test_selector(relation_type: :child),
- content_arguments: {
- data: { turbo_stream: true }
- }
- ) do |item|
- item.with_description.with_content(t("#{I18N_NAMESPACE}.relations.child_description"))
- end
- end
end
end
end
diff --git a/app/components/work_package_relations_tab/index_component.rb b/app/components/work_package_relations_tab/index_component.rb
index 65ff1b97213..1360895a400 100644
--- a/app/components/work_package_relations_tab/index_component.rb
+++ b/app/components/work_package_relations_tab/index_component.rb
@@ -98,31 +98,37 @@ class WorkPackageRelationsTab::IndexComponent < ApplicationComponent
t("work_package_relations_tab.label_add_child_button")
end
- menu.with_item(
- label: t("work_package_relations_tab.relations.new_child"),
- href: "#",
- content_arguments: {
- data: { turbo_stream: true }
- }
- ) do |item|
- item.with_description.with_content(t("work_package_relations_tab.relations.new_child_text"))
- end
-
- menu.with_item(
- label: t("work_package_relations_tab.relations.existing_child"),
- href: "#",
- content_arguments: {
- data: { turbo_stream: true }
- }
- ) do |item|
- item.with_description.with_content(t("work_package_relations_tab.relations.child_description"))
- end
+ render_child_items(menu)
end
end
end
end
end
+ def render_child_items(menu)
+ return unless should_render_add_child?
+
+ menu.with_item(
+ label: t("work_package_relations_tab.relations.new_child"),
+ href: "#",
+ content_arguments: {
+ data: { turbo_stream: true }
+ }
+ ) do |item|
+ item.with_description.with_content(t("work_package_relations_tab.relations.new_child_text"))
+ end
+
+ menu.with_item(
+ label: t("work_package_relations_tab.relations.existing_child"),
+ href: new_work_package_children_relation_path(work_package),
+ content_arguments: {
+ data: { turbo_stream: true }
+ }
+ ) do |item|
+ item.with_description.with_content(t("work_package_relations_tab.relations.child_description"))
+ end
+ end
+
def render_items(border_box, items)
items.each do |item|
border_box.with_row(