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
Group relations by directional semantics
Aaron Contreras34fea8ed145b
diff --git a/app/components/work_package_relations_tab/index_component.html.erb b/app/components/work_package_relations_tab/index_component.html.erbindex 4a6762e0403..bebeff3d9c1 100644--- a/app/components/work_package_relations_tab/index_component.html.erb+++ b/app/components/work_package_relations_tab/index_component.html.erb@@ -3,7 +3,7 @@flex_layout(justify_content: :space_between, align_items: :center, mb: 4) do |action_bar|action_bar.with_column dorender(Primer::Beta::Text.new(color: :muted)) do- t("work_package_relations_tab.index.action_bar_title")+ t("#{I18N_NAMESPACE}.index.action_bar_title")endendaction_bar.with_column do@@ -13,9 +13,9 @@button.with_trailing_action_icon(icon: :"triangle-down")t(:label_relation)end- Relation::TYPES.values.each do |type_configuration_hash|+ Relation::TYPES.each do |relation_type, type_configuration_hash|menu.with_item(label: t(type_configuration_hash[:name]).capitalize) do |item|- item.with_description.with_content("blugh")+ item.with_description.with_content(t("#{I18N_NAMESPACE}.relations.#{relation_type}_description"))endendend@@ -23,34 +23,35 @@end%><%=- if relations.any?+ if any_relations?flex_layout(classes: "work-package-relations-tab--list-container") do |flex|- relations.group_by(&:relation_type).each do |relation_type, relations_of_type|- relation_relative_to_work_package = relation_type- key_namespace = "work_package_relations_tab.relations"+ key_namespace = "#{I18N_NAMESPACE}.relations"++ # Relations+ directionally_aware_grouped_relations.each do |relation_type, relations_of_type|base_key = "#{key_namespace}.label_#{relation_type}"flex.with_row do- render(border_box_container(padding: :condensed)) do |border_box|- border_box.with_header(py: 3) do- flex_layout(align_items: :center) do |flex|- flex.with_column(mr: 2) do- render(Primer::Beta::Text.new(font_size: :normal, font_weight: :bold)) do- t("#{base_key}_plural").capitalize- end- end- flex.with_column do- render(Primer::Beta::Counter.new(count: relations_of_type.size,- round: true,- scheme: :primary))- end- end- end- relations_of_type.each do |relation|- border_box.with_row(style: "padding-top: 12px; padding-bottom: 12px;") do- render(WorkPackageRelationsTab::RelationComponent.new(work_package: relation.to))- end- end+ render_relation_group(+ title: t("#{base_key}_plural").capitalize,+ items: relations_of_type+ ) do |relation|+ related_work_package = relation.from == work_package ? relation.to : relation.from+ render(WorkPackageRelationsTab::RelationComponent.new(work_package: related_work_package))+ end+ end+ end++ # Children+ if children.any?+ base_key = "#{key_namespace}.label_child"++ flex.with_row do+ render_relation_group(+ title: t("#{base_key}_plural").capitalize,+ items: children+ ) do |child|+ render(WorkPackageRelationsTab::RelationComponent.new(work_package: child))endendend@@ -58,8 +59,8 @@elserender Primer::Beta::Blankslate.new(border: true) do |component|component.with_visual_icon(icon: "package-dependents")- component.with_heading(tag: :h2).with_content(t("work_package_relations_tab.index.blankslate_heading"))- component.with_description { t("work_package_relations_tab.index.blankslate_description") }+ component.with_heading(tag: :h2).with_content(t("#{I18N_NAMESPACE}.index.blankslate_heading"))+ component.with_description { t("#{I18N_NAMESPACE}.index.blankslate_description") }endend%>diff --git a/app/components/work_package_relations_tab/index_component.rb b/app/components/work_package_relations_tab/index_component.rbindex b771da97621..740f907e5b2 100644--- a/app/components/work_package_relations_tab/index_component.rb+++ b/app/components/work_package_relations_tab/index_component.rb@@ -2,21 +2,56 @@class WorkPackageRelationsTab::IndexComponent < ApplicationComponentFRAME_ID = "work-package-relations-tab-content"+ I18N_NAMESPACE = "work_package_relations_tab"include ApplicationHelperinclude OpPrimer::ComponentHelpersinclude Turbo::FramesHelperinclude OpTurbo::Streamable- attr_reader :work_package, :relations+ attr_reader :work_package, :relations, :children, :directionally_aware_grouped_relations- def initialize(work_package:, relations:)+ def initialize(work_package:, relations:, children:)super()@work_package = work_package@relations = relations+ @children = children+ @directionally_aware_grouped_relations = group_relations_by_directional_contextenddef self.wrapper_keyFRAME_IDend++ private++ def group_relations_by_directional_context+ relations.group_by do |relation|+ target = relation.to == work_package ? "from" : "to"+ target == "from" ? relation.reverse_type : relation.relation_type+ end+ end++ def any_relations? = relations.any? || children.any?++ def render_relation_group(title:, items:, &_block)+ render(border_box_container(padding: :condensed)) do |border_box|+ border_box.with_header(py: 3) do+ flex_layout(align_items: :center) do |flex|+ flex.with_column(mr: 2) do+ render(Primer::Beta::Text.new(font_size: :normal, font_weight: :bold)) { title }+ end+ flex.with_column do+ render(Primer::Beta::Counter.new(count: items.size, round: true, scheme: :primary))+ end+ end+ end++ items.each do |item|+ border_box.with_row(py: 2) do+ yield(item)+ end+ end+ end+ endenddiff --git a/app/components/work_package_relations_tab/index_component.sass b/app/components/work_package_relations_tab/index_component.sassindex 439628c939c..2adb6f50b0d 100644--- a/app/components/work_package_relations_tab/index_component.sass+++ b/app/components/work_package_relations_tab/index_component.sass@@ -5,4 +5,5 @@// We reference an ID as one is required to be specified for the action menu list.// It can't be nested inside the BEM model as it's placed as a #top-layer element.#relations-list-action-menu-list- max-height: 300px+ max-height: 380px+ max-width: 280pxdiff --git a/app/components/work_package_relations_tab/relation_component.html.erb b/app/components/work_package_relations_tab/relation_component.html.erbindex 8ace8af5eb2..96d92cb6712 100644--- a/app/components/work_package_relations_tab/relation_component.html.erb+++ b/app/components/work_package_relations_tab/relation_component.html.erb@@ -4,19 +4,13 @@align_items: :center,style: "gap: 0.5rem;") do |meta_information_row|meta_information_row.with_column do- render(Primer::Beta::Text.new(font_size: :small,- font_weight: :bold,- color: :muted)) { "#{work_package.type.name.upcase}" }+ render(WorkPackages::HighlightedTypeComponent.new(work_package: @work_package, font_size: :small))end-meta_information_row.with_column do- render(Primer::Beta::Text.new(font_size: :small,- color: :muted)) { "##{work_package.id}" }+ render(Primer::Beta::Text.new(font_size: :small,color: :muted)) { "##{work_package.id}" }endmeta_information_row.with_column do- render(Primer::Beta::Text.new(classes: "__hl_inline_status_#{work_package.status.id}")) do- work_package.status.name- end+ render WorkPackages::StatusBadgeComponent.new(status: work_package.status)endenddiff --git a/app/controllers/work_package_relations_tab_controller.rb b/app/controllers/work_package_relations_tab_controller.rbindex 8de82799fb6..d65842ae6ec 100644--- a/app/controllers/work_package_relations_tab_controller.rb+++ b/app/controllers/work_package_relations_tab_controller.rb@@ -35,25 +35,23 @@ class WorkPackageRelationsTabController < ApplicationControllerbefore_action :authorize_globaldef index+ @children = WorkPackage.where(parent_id: @work_package.id)@relations = @work_package.relations.includes(:to, :from)+ component = WorkPackageRelationsTab::IndexComponent.new(+ work_package: @work_package,+ relations: @relations,+ children: @children+ )+respond_to do |format|format.html do- render(- WorkPackageRelationsTab::IndexComponent.new(- work_package: @work_package,- relations: @relations- ),- layout: false- )+ render(component, layout: false)endformat.turbo_stream do- replace_via_turbo_stream(component: WorkPackageRelationsTab::IndexComponent.new(- work_package: @work_package,- relations: @relations- ))+ replace_via_turbo_stream(component:)render turbo_stream: turbo_streamsendenddiff --git a/app/models/relation.rb b/app/models/relation.rbindex ed47264e7d8..947312b1c21 100644--- a/app/models/relation.rb+++ b/app/models/relation.rb@@ -31,12 +31,12 @@ class Relation < ApplicationRecordbelongs_to :to, class_name: "WorkPackage"TYPE_RELATES = "relates".freeze- TYPE_DUPLICATES = "duplicates".freeze- TYPE_DUPLICATED = "duplicated".freeze- TYPE_BLOCKS = "blocks".freeze- TYPE_BLOCKED = "blocked".freezeTYPE_PRECEDES = "precedes".freezeTYPE_FOLLOWS = "follows".freeze+ TYPE_BLOCKS = "blocks".freeze+ TYPE_BLOCKED = "blocked".freeze+ TYPE_DUPLICATES = "duplicates".freeze+ TYPE_DUPLICATED = "duplicated".freezeTYPE_INCLUDES = "includes".freezeTYPE_PARTOF = "partof".freezeTYPE_REQUIRES = "requires".freezediff --git a/config/locales/en.yml b/config/locales/en.ymlindex 1f97029fd87..00b8e1e6743 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -720,12 +720,16 @@ en:precedes_description: "The related work package necessarily needs to finish before this one can start"label_follows_singular: "successor (after)"label_follows_plural: "successors (after)"+ follows_description: "The related work package necessarily needs to start after this one finishes"label_child_singular: "child"- label_child_plural: "child"+ label_child_plural: "children"+ child_description: "Makes the related a work package a sub-item of the current (parent) work package"label_blocks_singular: "blocks"label_blocks_plural: "blocks"+ blocks_description: "The related work package cannot be closed until this one is closed first"label_blocked_singular: "blocked by"label_blocked_plural: "blocked by"+ blocked_description: "This work package cannot be closed until the related one is closed first"label_duplicates_singular: "duplicates"label_duplicates_plural: "duplicates"duplicates_description: "This is a copy of the related work package"@@ -734,12 +738,16 @@ en:duplicated_description: "The related work package is a copy of this."label_includes_singular: "includes"label_includes_plural: "includes"+ includes_description: "Marks the related work package as including this one with no additional effect"label_partof_singular: "part of"label_partof_plural: "part of"+ partof_description: "Marks the related work package as being part of this one with no additional effect"label_requires_singular: "requires"label_requires_plural: "requires"+ requires_description: "Marks the related work package as a requirement to this one"label_required_singular: "required by"label_required_plural: "required by"+ required_description: "Marks this work package as being a requirement to the related one"label_parent_singular: "parent"label_parent_plural: "parent"diff --git a/spec/features/work_packages/details/relations/primerized_relations_spec.rb b/spec/features/work_packages/details/relations/primerized_relations_spec.rbnew file mode 100644index 00000000000..3798ae260c7--- /dev/null+++ b/spec/features/work_packages/details/relations/primerized_relations_spec.rb@@ -0,0 +1,120 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+#++++require "spec_helper"++RSpec.describe "Primerized work package relations tab",+ :cuprite,+ :js do+ let(:user) { create(:admin) }+ let(:project) { create(:project) }+ let(:work_package) { create(:work_package, project:) }+ let(:full_wp_view) { Pages::FullWorkPackage.new(work_package) }+ let(:relations_tab) { Components::WorkPackages::Relations.new(work_package) }+ let(:work_packages_page) { Pages::PrimerizedSplitWorkPackage.new(work_package) }+ let(:tabs) { Components::WorkPackages::PrimerizedTabs.new }++ let(:type1) { create(:type) }+ let(:type2) { create(:type) }++ let(:to1) { create(:work_package, type: type1, project:) }+ let(:to2) { create(:work_package, type: type2, project:) }+ let(:from1) { create(:work_package, type: type1, project:) }++ let!(:relation1) do+ create(:relation,+ from: work_package,+ to: to1,+ relation_type: Relation::TYPE_FOLLOWS)+ end+ let!(:relation2) do+ create(:relation,+ from: work_package,+ to: to2,+ relation_type: Relation::TYPE_RELATES)+ end+ let!(:relation3) do+ create(:relation,+ from: from1,+ to: work_package,+ relation_type: Relation::TYPE_BLOCKED)+ end+ let!(:relation4) do+ create(:relation,+ from: to1,+ to: from1,+ relation_type: Relation::TYPE_FOLLOWS)+ end++ current_user { user }++ def label_for_relation_type(relation_type)+ I18n.t("work_package_relations_tab.relations.label_#{relation_type}_plural").capitalize+ end++ before do+ work_packages_page.visit_tab!("relations")+ expect_angular_frontend_initialized+ work_packages_page.expect_subject+ loading_indicator_saveguard+ end++ describe "rendering" do+ it "renders the relations tab" do+ scroll_to_element find(".detail-panel--relations")+ expect(page).to have_css(".detail-panel--relations")++ [relation1, relation2].each do |relation|+ target = relation.to == work_package ? "from" : "to"+ target_relation_type = target == "from" ? relation.reverse_type : relation.relation_type++ expect(page).to have_text(relation.to.type.name.upcase)+ expect(page).to have_text(relation.to.id)+ expect(page).to have_text(relation.to.status.name)+ expect(page).to have_text(relation.to.subject)+ # We reference the reverse type as the "from" node of the relation+ # is the currently visited work package, and the "to" node is the+ # relation target. From the current user's perspective on the work package's+ # page, this is the "reverse" relation.+ expect(page).to have_text(label_for_relation_type(target_relation_type))+ end++ target = relation3.to == work_package ? "from" : "to"+ target_relation_type = target == "from" ? relation3.reverse_type : relation3.relation_type++ expect(page).to have_text(relation3.to.type.name.upcase)+ expect(page).to have_text(relation3.to.id)+ expect(page).to have_text(relation3.to.status.name)+ expect(page).to have_text(relation3.to.subject)+ # We reference the relation type as the "from" node of the relation+ # is not the currently visited work package. From the current user's+ # perspective on the work package's page, this is the "forward" relation.+ expect(page).to have_text(label_for_relation_type(target_relation_type))+ end+ end+end