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

Add ability to edit relations

Aaron Contreras38fa140d3fd4
diff --git a/app/components/work_package_relations_tab/edit_work_package_relation_dialog_component.html.erb b/app/components/work_package_relations_tab/edit_work_package_relation_dialog_component.html.erb
new file mode 100644
index 00000000000..ff850592a2d
--- /dev/null
+++ b/app/components/work_package_relations_tab/edit_work_package_relation_dialog_component.html.erb
@@ -0,0 +1,35 @@
+<%=
+ render(Primer::Alpha::Dialog.new(title: dialog_title,
+ size: :xlarge,
+ id: DIALOG_ID)) do |d|
+ d.with_header(variant: :large)
+ d.with_body do
+ # render(WorkPackageMeetingsTab::AddWorkPackageToMeetingFormComponent.new(
+ # work_package: @work_package,
+ # meeting_agenda_item: @meeting_agenda_item
+ # ))
+ render(WorkPackageRelationsTab::EditWorkPackageRelationFormComponent.new(
+ work_package: @work_package,
+ relation: @relation
+ ))
+ end
+ d.with_footer do
+ component_collection do |buttons|
+ buttons.with_component(Primer::ButtonComponent.new(
+ data: {
+ 'close-dialog-id': DIALOG_ID
+ }
+ )) do
+ t("button_cancel")
+ end
+ buttons.with_component(Primer::ButtonComponent.new(
+ scheme: :primary,
+ form: FORM_ID,
+ data: { turbo: true },
+ type: :submit)) do
+ t("button_save")
+ end
+ end
+ end
+ end
+%>
diff --git a/app/components/work_package_relations_tab/edit_work_package_relation_dialog_component.rb b/app/components/work_package_relations_tab/edit_work_package_relation_dialog_component.rb
new file mode 100644
index 00000000000..606e2bbc2cf
--- /dev/null
+++ b/app/components/work_package_relations_tab/edit_work_package_relation_dialog_component.rb
@@ -0,0 +1,55 @@
+# frozen_string_literal: true
+
+#-- 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.
+#++
+
+class WorkPackageRelationsTab::EditWorkPackageRelationDialogComponent < ApplicationComponent
+ include ApplicationHelper
+ include OpTurbo::Streamable
+ include OpPrimer::ComponentHelpers
+
+ I18N_NAMESPACE = "work_package_relations_tab"
+ DIALOG_ID = "edit-work-package-relation-dialog"
+ FORM_ID = "edit-work-package-relation-form"
+
+ attr_reader :relation, :work_package
+
+ def initialize(work_package:, relation:)
+ super()
+
+ @relation = relation
+ @work_package = work_package
+ end
+
+ private
+
+ def dialog_title
+ relation_label = t("#{I18N_NAMESPACE}.relations.#{relation.label_for(work_package)}_singular")
+ t("#{I18N_NAMESPACE}.label_edit_x", x: relation_label)
+ end
+end
diff --git a/app/components/work_package_relations_tab/edit_work_package_relation_form_component.html.erb b/app/components/work_package_relations_tab/edit_work_package_relation_form_component.html.erb
index 3d77adf5ae8..ba0b5a7a396 100644
--- a/app/components/work_package_relations_tab/edit_work_package_relation_form_component.html.erb
+++ b/app/components/work_package_relations_tab/edit_work_package_relation_form_component.html.erb
@@ -1,42 +1,61 @@
-<%=
- component_wrapper do
- primer_form_with(
- id: FORM_ID,
+<%= component_wrapper do %>
+ <%= primer_form_with(
+ id: FORM_ID,
model: @relation,
method: :patch,
- url: work_package_relation_path(@relation),
- ) do |f|
- flex_layout(my: 3) do |flex|
+ url: work_package_relation_path(@work_package, @relation),
+ data: { turbo: true,
+ controller: STIMULUS_CONTROLLER,
+ application_target: "dynamic" }
+ ) do |f| %>
+ <%# Form fields section %>
+ <%= flex_layout(my: 3) do |flex|
flex.with_row do
if @base_errors&.any?
render(Primer::Alpha::Banner.new(mb: 3, icon: :stop, scheme: :danger)) { @base_errors.join("\n") }
end
end
flex.with_row do
+ relation = @relation
+ target_work_package = related_work_package
+ stimulus_controller = STIMULUS_CONTROLLER
+ i18n_namespace = I18N_NAMESPACE
+ not_parent_child_relation = not_parent_child_relation?
render_inline_form(f) do |my_form|
- my_form.work_package_autocompleter(
+ my_form.text_field(
name: :to_id,
label: WorkPackage.model_name.human,
visually_hide_label: false,
- autocomplete_options: {
- resource: 'work_packages',
- searchKey: 'subjectOrId',
- openDirectly: false,
- focusDirectly: false,
- dropdownPosition: 'bottom',
- append_to: "##{WorkPackageRelationsTab::EditWorkPackageRelationDialogComponent::DIALOG_ID}"
- }
+ value: "#{target_work_package.type.name.upcase} ##{target_work_package.id} - #{target_work_package.subject}",
+ readonly: true
)
+
+ if not_parent_child_relation
+ my_form.text_field(
+ name: :description,
+ label: Relation.human_attribute_name(:description),
+ hidden: relation.description.blank?,
+ data: { "#{stimulus_controller}-target": "descriptionField" }
+ )
+ end
end
end
- flex.with_row(mt: 3) do
- flex_layout(justify_content: :flex_end) do |actions_row|
- actions_row.with_column do
- render(Primer::Beta::Button.new(scheme: :primary, type: :submit)) { t(:button_save) }
+ end %>
+ <%# Actions section %>
+ <%= flex_layout(my: 3) do |flex|
+ flex.with_row do
+ if not_parent_child_relation? && @relation.description.blank?
+ render(Primer::Beta::Button.new(
+ scheme: :secondary,
+ title: I18n.t("#{I18N_NAMESPACE}.label_add_description"),
+ data: { action: "#{STIMULUS_CONTROLLER}#toggleDescriptionField",
+ "#{STIMULUS_CONTROLLER}-target": "descriptionButton" }
+ )) do |button|
+ button.with_leading_visual_icon(icon: :plus)
+ I18n.t("#{I18N_NAMESPACE}.label_add_description")
end
end
end
- end
- end
- end
-%>
+ end %>
+ <% end %>
+<% end %>
diff --git a/app/components/work_package_relations_tab/edit_work_package_relation_form_component.rb b/app/components/work_package_relations_tab/edit_work_package_relation_form_component.rb
index af43d36314e..74ca83c8d69 100644
--- a/app/components/work_package_relations_tab/edit_work_package_relation_form_component.rb
+++ b/app/components/work_package_relations_tab/edit_work_package_relation_form_component.rb
@@ -34,11 +34,27 @@ class WorkPackageRelationsTab::EditWorkPackageRelationFormComponent < Applicatio
include OpPrimer::ComponentHelpers
FORM_ID = "edit-work-package-relation-form"
+ STIMULUS_CONTROLLER = "work-packages--relations-tab--relation-form"
+ I18N_NAMESPACE = "work_package_relations_tab"
- def initialize(relation:, base_errors: nil)
+ def initialize(work_package:, relation:, base_errors: nil)
super()
+ @work_package = work_package
@relation = relation
@base_errors = base_errors
end
+
+ def not_parent_child_relation?
+ @relation.is_a?(Relation)
+ end
+
+ def related_work_package
+ @related_work_package ||= case @relation
+ when Relation
+ @relation.to
+ when WorkPackage
+ @relation
+ end
+ end
end
diff --git a/app/components/work_package_relations_tab/relation_component.html.erb b/app/components/work_package_relations_tab/relation_component.html.erb
index 9030f8108fe..e78da4db38e 100644
--- a/app/components/work_package_relations_tab/relation_component.html.erb
+++ b/app/components/work_package_relations_tab/relation_component.html.erb
@@ -31,9 +31,10 @@
scheme: :invisible,
ml: 2)
menu.with_item(label: "Edit relation",
- href: "#",
+ href: edit_path,
+ test_selector: edit_button_test_selector,
content_arguments: {
- data: { "turbo-stream": true }
+ data: { turbo_stream: true }
}) do |item|
item.with_leading_visual_icon(icon: :pencil)
end
@@ -54,13 +55,16 @@
end
end
- if related_work_package.description.present?
+ if parent_child_relationship? && child.description.present?
flex.with_row(flex_layout: true, justify_content: :flex_start) do |description_row|
description_row.with_column do
- render(Primer::Beta::Text.new(font_size: :small,
- color: :muted)) do
- format_text(related_work_package, :description)
- end
+ render(Primer::Beta::Text.new(font_size: :small, color: :muted)) { format_text(child, :description) }
+ end
+ end
+ elsif !parent_child_relationship? && relation.description.present?
+ flex.with_row(flex_layout: true, justify_content: :flex_start) do |description_row|
+ description_row.with_column do
+ render(Primer::Beta::Text.new(font_size: :small, color: :muted)) { format_text(relation, :description) }
end
end
end
diff --git a/app/components/work_package_relations_tab/relation_component.rb b/app/components/work_package_relations_tab/relation_component.rb
index 433cf17d4ae..255becb1f65 100644
--- a/app/components/work_package_relations_tab/relation_component.rb
+++ b/app/components/work_package_relations_tab/relation_component.rb
@@ -2,7 +2,7 @@ class WorkPackageRelationsTab::RelationComponent < ApplicationComponent
include ApplicationHelper
include OpPrimer::ComponentHelpers
- attr_reader :work_package, :relation
+ attr_reader :work_package, :relation, :child
def initialize(work_package:,
relation:,
@@ -34,6 +34,14 @@ class WorkPackageRelationsTab::RelationComponent < ApplicationComponent
end
end
+ def edit_path
+ if parent_child_relationship?
+ "#" # TODO: Implement work package child edit path
+ else
+ edit_work_package_relation_path(@work_package, @relation)
+ end
+ end
+
def destroy_path
if parent_child_relationship?
work_package_child_path(@child)
@@ -46,6 +54,10 @@ class WorkPackageRelationsTab::RelationComponent < ApplicationComponent
"op-relation-row-#{underlying_resource_id}-action-menu"
end
+ def edit_button_test_selector
+ "op-relation-row-#{underlying_resource_id}-edit-button"
+ end
+
def delete_button_test_selector
"op-relation-row-#{underlying_resource_id}-delete-button"
end
diff --git a/app/controllers/work_package_relations_controller.rb b/app/controllers/work_package_relations_controller.rb
index 1e49d6d9a6e..3c0489390ac 100644
--- a/app/controllers/work_package_relations_controller.rb
+++ b/app/controllers/work_package_relations_controller.rb
@@ -30,11 +30,37 @@
class WorkPackageRelationsController < ApplicationController
include OpTurbo::ComponentStream
+ include OpTurbo::DialogStreamHelper
before_action :set_work_package
before_action :set_relation
before_action :authorize
+ def edit
+ respond_with_dialog(
+ WorkPackageRelationsTab::EditWorkPackageRelationDialogComponent
+ .new(work_package: @work_package, relation: @relation)
+ )
+ end
+
+ def update
+ service_result = Relations::UpdateService
+ .new(user: current_user,
+ model: @relation)
+ .call(relation_params)
+
+ if service_result.success?
+ @work_package.reload
+ component = WorkPackageRelationsTab::IndexComponent.new(work_package: @work_package,
+ relations: @work_package.relations,
+ children: @work_package.children)
+ replace_via_turbo_stream(component:)
+ respond_with_turbo_streams
+ else
+ respond_with_turbo_streams(status: :unprocessable_entity)
+ end
+ end
+
def destroy
service_result = Relations::DeleteService.new(user: current_user, model: @relation).call
@@ -63,4 +89,9 @@ class WorkPackageRelationsController < ApplicationController
def set_relation
@relation = @work_package.relations.find(params[:id])
end
+
+ def relation_params
+ params.require(:relation)
+ .permit(:description)
+ end
end
diff --git a/config/initializers/permissions.rb b/config/initializers/permissions.rb
index f2aea7ca0a4..0ca990fe50e 100644
--- a/config/initializers/permissions.rb
+++ b/config/initializers/permissions.rb
@@ -317,7 +317,7 @@ Rails.application.reloader.to_prepare do
wpt.permission :manage_work_package_relations,
{
- work_package_relations: %i[create destroy]
+ work_package_relations: %i[edit update create destroy]
},
permissible_on: %i[work_package project],
dependencies: :view_work_packages
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 00b8e1e6743..ed516c282af 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -711,6 +711,8 @@ en:
no_results_title_text: There are currently no relations available.
blankslate_heading: "No relations"
blankslate_description: "This work package does not yet have any relations."
+ label_edit_x: "Edit %{x}"
+ label_add_description: "Add description"
relations:
label_relates_singular: "related to"
label_relates_plural: "related to"
@@ -751,7 +753,7 @@ en:
label_parent_singular: "parent"
label_parent_plural: "parent"
-
+
label_invitation: Invitation
account:
delete: "Delete account"
diff --git a/config/routes.rb b/config/routes.rb
index a64e2842ef7..ebf546bf71a 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -603,7 +603,8 @@ Rails.application.routes.draw do
as: :work_package_progress
end
resources :relations_tab, only: %i[index], controller: "work_package_relations_tab"
- resources :relations, only: %i[destroy], controller: "work_package_relations"
+ resources :relations, only: %i[edit update destroy], controller: "work_package_relations"
+
get "/export_dialog" => "work_packages#export_dialog", on: :collection, as: "export_dialog"
get :show_conflict_flash_message, on: :collection # we don't need a specific work package for this
diff --git a/frontend/src/stimulus/controllers/dynamic/work-packages/relations-tab/relation-form.controller.ts b/frontend/src/stimulus/controllers/dynamic/work-packages/relations-tab/relation-form.controller.ts
new file mode 100644
index 00000000000..eda94428648
--- /dev/null
+++ b/frontend/src/stimulus/controllers/dynamic/work-packages/relations-tab/relation-form.controller.ts
@@ -0,0 +1,55 @@
+/*
+ * -- 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.
+ * ++
+ */
+
+import { Controller } from '@hotwired/stimulus';
+
+export default class RelationFormController extends Controller {
+ static targets = ['descriptionField', 'descriptionButton'];
+
+ declare readonly descriptionFieldTarget:HTMLDivElement;
+ declare readonly descriptionButtonTarget:HTMLButtonElement;
+
+ toggleDescriptionField():void {
+ const topLevelTextFieldElement = this.descriptionFieldTarget.closest('primer-text-field') as HTMLElement;
+ const elements = {
+ label: topLevelTextFieldElement.querySelector('label') as HTMLLabelElement,
+ formControl: topLevelTextFieldElement.querySelector('.FormControl-input-wrap') as HTMLElement,
+ textField: topLevelTextFieldElement,
+ input: this.descriptionFieldTarget,
+ };
+
+ // Show description field and its related elements
+ Object.values(elements).forEach((element) => {
+ element.hidden = false;
+ });
+ // Hide Add description button
+ this.descriptionButtonTarget.hidden = true;
+ }
+}
diff --git a/spec/features/work_packages/details/relations/primerized_relations_spec.rb b/spec/features/work_packages/details/relations/primerized_relations_spec.rb
index c9f7b1f91d7..77dcdb06e4a 100644
--- a/spec/features/work_packages/details/relations/primerized_relations_spec.rb
+++ b/spec/features/work_packages/details/relations/primerized_relations_spec.rb
@@ -35,6 +35,8 @@ RSpec.describe "Primerized work package relations tab",
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(:relations_panel_selector) { ".detail-panel--relations" }
+ let(:relations_panel) { find(relations_panel_selector) }
let(:work_packages_page) { Pages::PrimerizedSplitWorkPackage.new(work_package) }
let(:tabs) { Components::WorkPackages::PrimerizedTabs.new }
@@ -91,44 +93,48 @@ RSpec.describe "Primerized work package relations tab",
describe "rendering" do
it "renders the relations tab" do
- scroll_to_element find(".detail-panel--relations")
- expect(page).to have_css(".detail-panel--relations")
+ scroll_to_element relations_panel
+ expect(page).to have_css(relations_panel_selector)
[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))
+ within(relations_panel) do
+ 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
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))
+ within(relations_panel) do
+ 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
describe "deletion" do
it "can delete relations" do
- scroll_to_element find(".detail-panel--relations")
+ scroll_to_element relations_panel
# Find the first relation and delete it
- relation_row = page.find("[data-test-selector='op-relation-row-#{relation1.id}']")
+ relation_row = relations_panel.find("[data-test-selector='op-relation-row-#{relation1.id}']")
within(relation_row) do
page.find("[data-test-selector='op-relation-row-#{relation1.id}-action-menu']").click
@@ -146,10 +152,10 @@ RSpec.describe "Primerized work package relations tab",
end
it "can delete children" do
- scroll_to_element find(".detail-panel--relations")
+ scroll_to_element relations_panel
# Find the first relation and delete it
- child_row = page.find("[data-test-selector='op-relation-row-#{child_wp.id}']")
+ child_row = relations_panel.find("[data-test-selector='op-relation-row-#{child_wp.id}']")
within(child_row) do
page.find("[data-test-selector='op-relation-row-#{child_wp.id}-action-menu']").click
@@ -165,4 +171,61 @@ RSpec.describe "Primerized work package relations tab",
expect(child_wp.reload.parent).to be_nil
end
end
+
+ describe "editing" do
+ it "renders an edit form" do
+ scroll_to_element relations_panel
+
+ relation_row = relations_panel.find("[data-test-selector='op-relation-row-#{relation1.id}']")
+
+ within(relation_row) do
+ page.find("[data-test-selector='op-relation-row-#{relation1.id}-action-menu']").click
+ page.find("[data-test-selector='op-relation-row-#{relation1.id}-edit-button']").click
+ end
+
+ within "##{WorkPackageRelationsTab::EditWorkPackageRelationDialogComponent::DIALOG_ID}" do
+ wait_for_network_idle
+ expect(page).to have_text("Edit successor (after)")
+ expect(page).to have_button("Add description")
+ expect(page).to have_field("Description", visible: :hidden)
+
+ click_link_or_button "Add description"
+
+ expect(page).to have_field("Description")
+
+ fill_in "Description", with: "Discovered relations have descriptions!"
+
+ click_link_or_button "Save"
+ end
+
+ # Reflects new description
+ wait_for_reload
+ within(relation_row) do
+ expect(page).to have_text("Discovered relations have descriptions!")
+ end
+
+ # Edit again
+ within(relation_row) do
+ page.find("[data-test-selector='op-relation-row-#{relation1.id}-action-menu']").click
+ page.find("[data-test-selector='op-relation-row-#{relation1.id}-edit-button']").click
+ end
+
+ within "##{WorkPackageRelationsTab::EditWorkPackageRelationDialogComponent::DIALOG_ID}" do
+ wait_for_network_idle
+ expect(page).to have_text("Edit successor (after)")
+ expect(page).to have_no_button("Add description")
+ expect(page).to have_field("Description", visible: :visible, with: "Discovered relations have descriptions!")
+
+ fill_in "Description", with: "And they can be edited!"
+
+ click_link_or_button "Save"
+ end
+
+ # Reflects new description
+ wait_for_reload
+ within(relation_row) do
+ expect(page).to have_text("And they can be edited!")
+ end
+ end
+ end
end