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

[#61885] Sort relations in relations tab by created_at

Alexander Brandon Colesae9e95943ef0
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 a087cd35bf9..6a3fdfe3ad0 100644
--- a/app/components/work_package_relations_tab/index_component.html.erb
+++ b/app/components/work_package_relations_tab/index_component.html.erb
@@ -57,6 +57,7 @@
# Combine visible and invisible relations into a single list
all_relations = relation_group.visible_relations.map { |r| [r, :visible] } +
relation_group.ghost_relations.map { |r| [r, :ghost] }
+ all_relations.sort_by! { |r| r[0].id }
flex.with_row(mb: 4) do
render_relation_group(
@@ -84,6 +85,7 @@
# Combine visible and invisible children into a single list
all_children = visible_children.map { |r| [r, :visible] } +
ghost_children.map { |r| [r, :ghost] }
+ all_children.sort_by! { |r| r[0].created_at }
flex.with_row do
render_relation_group(
diff --git a/spec/components/work_package_relations_tab/index_component_spec.rb b/spec/components/work_package_relations_tab/index_component_spec.rb
index 0b6460bf057..ccde984654d 100644
--- a/spec/components/work_package_relations_tab/index_component_spec.rb
+++ b/spec/components/work_package_relations_tab/index_component_spec.rb
@@ -31,6 +31,8 @@
require "rails_helper"
RSpec.describe WorkPackageRelationsTab::IndexComponent, type: :component do
+ create_shared_association_defaults_for_work_package_factory
+
shared_let(:user) { create(:admin) }
shared_let(:work_package) { create(:work_package) }
@@ -60,11 +62,13 @@ RSpec.describe WorkPackageRelationsTab::IndexComponent, type: :component do
expect(render_component).to have_test_selector("op-relation-group-children")
end
- it "renders the relations" do
+ it "renders the relations in child creation order" do
expect(render_component).to have_list "Children"
list = page.find(:list, "Children")
expect(list).to have_list_item count: 2, text: /child\d/
+ expect(list).to have_list_item position: 1, text: "child1"
+ expect(list).to have_list_item position: 2, text: "child2"
end
end
@@ -82,11 +86,28 @@ RSpec.describe WorkPackageRelationsTab::IndexComponent, type: :component do
expect(render_component).to have_test_selector("op-relation-group-follows")
end
- it "renders the relations" do
+ it "renders the relations in relation creation order" do
expect(render_component).to have_list "Predecessors (before)"
list = page.find(:list, "Predecessors (before)")
expect(list).to have_list_item count: 4, text: /predecessor\d/
+ expect(list).to have_list_item position: 1, text: "predecessor1"
+ expect(list).to have_list_item position: 2, text: "predecessor2"
+ expect(list).to have_list_item position: 3, text: "predecessor3"
+ expect(list).to have_list_item position: 4, text: "predecessor4"
+
+ # delete and recreate relation to predecessor2.
+ relation_attributes = predecessor2.relations.first.attributes
+ predecessor2.relations.first.destroy
+ Relation.create!(relation_attributes.without("id"))
+
+ # predecessor2 should now be at last position
+ render_component
+ list = page.find(:list, "Predecessors (before)")
+ expect(list).to have_list_item position: 1, text: "predecessor1"
+ expect(list).to have_list_item position: 2, text: "predecessor3"
+ expect(list).to have_list_item position: 3, text: "predecessor4"
+ expect(list).to have_list_item position: 4, text: "predecessor2"
end
it "renders the closest relation" do