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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
[62607] Always display relations in the relations tab in a fixed order
Christophe Bliard957a91cc697d
diff --git a/app/components/work_package_relations_tab/index_component.html.erb b/app/components/work_package_relations_tab/index_component.html.erbindex 94f4d422bc3..2c063f7f633 100644--- a/app/components/work_package_relations_tab/index_component.html.erb+++ b/app/components/work_package_relations_tab/index_component.html.erb@@ -47,16 +47,11 @@<%=flex_layout(mb: 3) do |flex|- if any_relations?- key_namespace = "#{I18N_NAMESPACE}.relations"-- # Relations- directionally_aware_grouped_relations.each do |relation_group|- base_key = "#{key_namespace}.label_#{relation_group.type}"-+ if relation_groups.any?+ relation_groups.each do |relation_group|flex.with_row(mb: 4) dorender_relation_group(- title: t("#{base_key}_plural").upcase_first,+ title: t("#{I18N_NAMESPACE}.relations.label_#{relation_group.type}_plural").upcase_first,relation_group:) do |relation_item|render(@@ -65,22 +60,6 @@endendend-- # Children- if any_children?- base_key = "#{key_namespace}.label_child"-- flex.with_row do- render_relation_group(- title: t("#{base_key}_plural").upcase_first,- relation_group: relations_mediator.relation_group("children")- ) do |relation_item|- render(- WorkPackageRelationsTab::RelationComponent.new(relation_item:)- )- end- end- endelseflex.with_row dorender Primer::Beta::Blankslate.new(border: true) do |component|diff --git a/app/components/work_package_relations_tab/index_component.rb b/app/components/work_package_relations_tab/index_component.rbindex 21183fb6a2e..def78ca9cf1 100644--- a/app/components/work_package_relations_tab/index_component.rb+++ b/app/components/work_package_relations_tab/index_component.rb@@ -21,9 +21,7 @@ class WorkPackageRelationsTab::IndexComponent < ApplicationComponentdelegate :work_package,:visible_children,:ghost_children,- :directionally_aware_grouped_relations,- :any_relations?,- :any_children?,+ :relation_groups,to: :relations_mediator# Initialize the component with required data@@ -62,7 +60,7 @@ class WorkPackageRelationsTab::IndexComponent < ApplicationComponentpadding: :condensed,data: { test_selector: "op-relation-group-#{relation_group.type}" })) do |border_box|- if relation_group.type.children? && should_render_add_child?+ if relation_group.type.child? && should_render_add_child?render_children_header(border_box, title, relation_group.count)elserender_header(border_box, title, relation_group.count)diff --git a/app/components/work_package_relations_tab/relations_mediator.rb b/app/components/work_package_relations_tab/relations_mediator.rbindex 822fc2bff7a..50ccced51a4 100644--- a/app/components/work_package_relations_tab/relations_mediator.rb+++ b/app/components/work_package_relations_tab/relations_mediator.rb@@ -121,33 +121,28 @@ class WorkPackageRelationsTab::RelationsMediatorenddef visible_relations- @visible_relations ||= work_package.relations.visible.includes(:to, :from)+ @visible_relations ||= work_package.relations.visible.includes(:to, :from).loadenddef visible_children- @visible_children ||= work_package.children.visible+ @visible_children ||= work_package.children.visible.loadenddef ghost_relations- @ghost_relations = work_package.relations.includes(:to, :from).where.not(id: visible_relations.select(:id))+ @ghost_relations ||= work_package.relations.includes(:to, :from).where.not(id: visible_relations.select(:id)).loadenddef ghost_children- @ghost_children ||= work_package.children.where.not(id: visible_children.select(:id))+ @ghost_children ||= work_package.children.where.not(id: visible_children.select(:id)).loadend- def directionally_aware_grouped_relations- # Collect all unique relation types- all_relation_types = collect_all_relation_types-- # Group visible and invisible relations by type- all_relation_types.map do |type|- relation_group(type)- end+ def relation_groups+ @relation_groups ||= Relation::ORDERED_TYPES.map { |type| relation_group(type) }+ .filter(&:any?)enddef relation_group(type)- if type == "children"+ if type == Relation::TYPE_CHILDRelationGroup.new(type:,work_package:,@@ -164,26 +159,12 @@ class WorkPackageRelationsTab::RelationsMediatorendend- def any_relations?- visible_relations.any? || ghost_relations.any? || visible_children.any? || ghost_children.any?- end-def all_relations_countvisible_relations.count + ghost_relations.count + visible_children.count + ghost_children.countend- def any_children?- visible_children.any? || ghost_children.any?- end-private- def collect_all_relation_types- (visible_relations + ghost_relations).map do |relation|- relation.relation_type_for(work_package)- end.uniq- end-def filter_relations_by_type(relations, type)relations.select do |relation|relation.relation_type_for(work_package) == typediff --git a/app/components/work_packages/date_picker/dialog_content_component.rb b/app/components/work_packages/date_picker/dialog_content_component.rbindex 3ea9c6db35b..b29d21fe535 100644--- a/app/components/work_packages/date_picker/dialog_content_component.rb+++ b/app/components/work_packages/date_picker/dialog_content_component.rb@@ -82,9 +82,9 @@ module WorkPackagesdef additional_tabsmediator = WorkPackageRelationsTab::RelationsMediator.new(work_package:)[- Tab.new("predecessors", mediator.relation_group("follows")),- Tab.new("successors", mediator.relation_group("precedes")),- Tab.new("children", mediator.relation_group("children"))+ Tab.new("predecessors", mediator.relation_group(Relation::TYPE_FOLLOWS)),+ Tab.new("successors", mediator.relation_group(Relation::TYPE_PRECEDES)),+ Tab.new("children", mediator.relation_group(Relation::TYPE_CHILD))]enddiff --git a/app/models/relation.rb b/app/models/relation.rbindex 768166d918d..9d0bc7e40b9 100644--- a/app/models/relation.rb+++ b/app/models/relation.rb@@ -49,6 +49,9 @@ class Relation < ApplicationRecordTYPE_PARENT = "parent"TYPE_CHILD = "child"+ # The order of the types is important. It's used to build up `ORDERED_TYPES`+ # which is used to order relations of different kind like in the "Add relation"+ # menu or the relations tab.TYPES = {TYPE_RELATES => {name: :label_relates_to, sym_name: :label_relates_to, order: 1, sym: TYPE_RELATES@@ -93,6 +96,8 @@ class Relation < ApplicationRecord}}.freeze+ ORDERED_TYPES = [*TYPES.keys, TYPE_CHILD].freeze+include ::Scopes::Scopedscopes :used_for_scheduling_of,diff --git a/spec/components/work_package_relations_tab/index_component_spec.rb b/spec/components/work_package_relations_tab/index_component_spec.rbindex ccde984654d..050ecbcc4de 100644--- a/spec/components/work_package_relations_tab/index_component_spec.rb+++ b/spec/components/work_package_relations_tab/index_component_spec.rb@@ -59,7 +59,7 @@ RSpec.describe WorkPackageRelationsTab::IndexComponent, type: :component doTABLEit "renders the relations group" do- expect(render_component).to have_test_selector("op-relation-group-children")+ expect(render_component).to have_test_selector("op-relation-group-child")endit "renders the relations in child creation order" dodiff --git a/spec/components/work_package_relations_tab/relation_component_spec.rb b/spec/components/work_package_relations_tab/relation_component_spec.rbindex 61d158f07e2..5b5942cce91 100644--- a/spec/components/work_package_relations_tab/relation_component_spec.rb+++ b/spec/components/work_package_relations_tab/relation_component_spec.rb@@ -53,7 +53,7 @@ RSpec.describe WorkPackageRelationsTab::RelationComponent, type: :component docontext "with child relation item" docontext "when visible" do- let(:relation_item) { build_relation_item(type: "children", relation: child, visibility: :visible) }+ let(:relation_item) { build_relation_item(type: Relation::TYPE_CHILD, relation: child, visibility: :visible) }it "renders a title link" doexpect(render_component(relation_item:))@@ -77,7 +77,7 @@ RSpec.describe WorkPackageRelationsTab::RelationComponent, type: :component doendcontext "when ghost" do- let(:relation_item) { build_relation_item(type: "children", relation: child, visibility: :ghost) }+ let(:relation_item) { build_relation_item(type: Relation::TYPE_CHILD, relation: child, visibility: :ghost) }it "does not render a title link" doexpect(render_component(relation_item:))@@ -99,7 +99,7 @@ RSpec.describe WorkPackageRelationsTab::RelationComponent, type: :component docontext "with follows relations" dolet(:relation) { _table.relation(predecessor: predecessor) }- let(:relation_item) { build_relation_item(type: "follows", relation:, visibility: :visible) }+ let(:relation_item) { build_relation_item(type: Relation::TYPE_FOLLOWS, relation:, visibility: :visible) }context "when visible" doit "renders a title link" do@@ -130,7 +130,7 @@ RSpec.describe WorkPackageRelationsTab::RelationComponent, type: :component doendcontext "when ghost" do- let(:relation_item) { build_relation_item(type: "follows", relation:, visibility: :ghost) }+ let(:relation_item) { build_relation_item(type: Relation::TYPE_FOLLOWS, relation:, visibility: :ghost) }subject(:rendered_component) { render_component(relation_item:) }@@ -150,11 +150,11 @@ RSpec.describe WorkPackageRelationsTab::RelationComponent, type: :component docontext "when closest" doit "always renders a closest label" do- relation_item = build_relation_item(type: "follows", relation:, visibility: :visible, closest: true)+ relation_item = build_relation_item(type: Relation::TYPE_FOLLOWS, relation:, visibility: :visible, closest: true)expect(render_component(relation_item:)).to have_primer_label "Closest", scheme: :primary- relation_item = build_relation_item(type: "follows", relation:, visibility: :ghost, closest: true)+ relation_item = build_relation_item(type: Relation::TYPE_FOLLOWS, relation:, visibility: :ghost, closest: true)expect(render_component(relation_item:)).to have_primer_label "Closest", scheme: :primaryenddiff --git a/spec/components/work_package_relations_tab/relations_mediator_spec.rb b/spec/components/work_package_relations_tab/relations_mediator_spec.rbindex 07d926a71d0..bde386288a6 100644--- a/spec/components/work_package_relations_tab/relations_mediator_spec.rb+++ b/spec/components/work_package_relations_tab/relations_mediator_spec.rb@@ -51,18 +51,22 @@ RSpec.describe WorkPackageRelationsTab::RelationsMediator doTABLEit "returns all relations of the work package" do- expect(mediator.relation_group("children").all_relation_items).to contain_exactly(- have_attributes(class: described_class::RelationItem, type: "children", related: child, visibility: :visible)+ expect(mediator.relation_group(Relation::TYPE_CHILD).all_relation_items).to contain_exactly(+ have_attributes(class: described_class::RelationItem, type: Relation::TYPE_CHILD, related: child, visibility: :visible))- expect(mediator.relation_group("precedes").all_relation_items).to contain_exactly(- have_attributes(class: described_class::RelationItem, type: "precedes", related: successor, visibility: :visible)+ expect(mediator.relation_group(Relation::TYPE_PRECEDES).all_relation_items).to contain_exactly(+ have_attributes(class: described_class::RelationItem, type: Relation::TYPE_PRECEDES, related: successor,+ visibility: :visible))- expect(mediator.relation_group("follows").all_relation_items).to contain_exactly(- have_attributes(class: described_class::RelationItem, type: "follows", related: predecessor, visibility: :visible)+ expect(mediator.relation_group(Relation::TYPE_FOLLOWS).all_relation_items).to contain_exactly(+ have_attributes(class: described_class::RelationItem, type: Relation::TYPE_FOLLOWS, related: predecessor,+ visibility: :visible))- expect(mediator.relation_group("relates").all_relation_items).to contain_exactly(- have_attributes(class: described_class::RelationItem, type: "relates", related: related1, visibility: :visible),- have_attributes(class: described_class::RelationItem, type: "relates", related: related2, visibility: :visible)+ expect(mediator.relation_group(Relation::TYPE_RELATES).all_relation_items).to contain_exactly(+ have_attributes(class: described_class::RelationItem, type: Relation::TYPE_RELATES, related: related1,+ visibility: :visible),+ have_attributes(class: described_class::RelationItem, type: Relation::TYPE_RELATES, related: related2,+ visibility: :visible))endenddiff --git a/spec/support/components/work_packages/relations.rb b/spec/support/components/work_packages/relations.rbindex c0a2b1681c7..e7d33eefcea 100644--- a/spec/support/components/work_packages/relations.rb+++ b/spec/support/components/work_packages/relations.rb@@ -312,7 +312,7 @@ module Componentsenddef children_table- page.find_test_selector("op-relation-group-children")+ page.find_test_selector("op-relation-group-child")enddef add_existing_child(work_package)