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
Limit the event listener to cases where we actually want to update the data. Further, when manually updating the objects do not execute the observable again
Henriette Dargefa8e583956ba
diff --git a/app/components/work_package_relations_tab/add_work_package_child_form_component.html.erb b/app/components/work_package_relations_tab/add_work_package_child_form_component.html.erbindex b5e01efe338..affa7550c3e 100644--- a/app/components/work_package_relations_tab/add_work_package_child_form_component.html.erb+++ b/app/components/work_package_relations_tab/add_work_package_child_form_component.html.erb@@ -3,7 +3,10 @@id: FORM_ID,model: WorkPackage.new,**submit_url_options,- data: { turbo: true }+ data: {+ turbo: true,+ update_work_package: true+ }) do |f| %><%# Form fields section %><%= flex_layout(my: 3) do |flex|diff --git a/app/components/work_package_relations_tab/relation_component.html.erb b/app/components/work_package_relations_tab/relation_component.html.erbindex 1ac7054f246..4591f935dc1 100644--- a/app/components/work_package_relations_tab/relation_component.html.erb+++ b/app/components/work_package_relations_tab/relation_component.html.erb@@ -51,7 +51,8 @@ flex_layout(direction: :column, style: "gap: 0.25rem;") do |flex|method: :delete,data: {confirm: t("text_are_you_sure"),- turbo_stream: true+ turbo_stream: true,+ update_work_package: true}},test_selector: delete_button_test_selector) do |item|diff --git a/app/components/work_package_relations_tab/work_package_relation_form_component.html.erb b/app/components/work_package_relations_tab/work_package_relation_form_component.html.erbindex e22f3ce0ade..e1706c8e919 100644--- a/app/components/work_package_relations_tab/work_package_relation_form_component.html.erb+++ b/app/components/work_package_relations_tab/work_package_relation_form_component.html.erb@@ -3,7 +3,10 @@id: FORM_ID,model: @relation,**submit_url_options,- data: { turbo: true }+ data: {+ turbo: true,+ update_work_package: true+ }) do |f| %><%# Form fields section %><%= flex_layout(my: 3) do |flex|diff --git a/frontend/src/app/features/work-packages/components/wp-relations/wp-relations.component.ts b/frontend/src/app/features/work-packages/components/wp-relations/wp-relations.component.tsindex 9ee94b59932..e71628d3f5b 100644--- a/frontend/src/app/features/work-packages/components/wp-relations/wp-relations.component.ts+++ b/frontend/src/app/features/work-packages/components/wp-relations/wp-relations.component.ts@@ -62,6 +62,12 @@ export class WorkPackageRelationsComponent extends UntilDestroyedMixin implementturboFrameSrc:string;+ // This is some sort of hack due to the mixing of Angular and rails. The component has two event listeners on WP and relation changes.+ // Everytime one of the triggers, the tab is re-rendered. However, when the inside the turboFrame a form was successfully submitted, we also update the WP and the relation to keep Angular informed about the changes in the frame.+ // To avoid that the tab is then rendered multiple times, I introduced these flags.+ wpChangeManuallyTriggered = false;+ relationChangeManuallyTriggered = false;+constructor(private wpRelations:WorkPackageRelationsService,private apiV3Service:ApiV3Service,@@ -85,7 +91,12 @@ export class WorkPackageRelationsComponent extends UntilDestroyedMixin implementtakeUntil(componentDestroyed(this)),debounceTime(500),).subscribe(() => {- this.updateRelationsTab();+ // When the change was triggered by the turbo:submit-end listener below, we will not udpate the tab again+ if (this.relationChangeManuallyTriggered) {+ this.relationChangeManuallyTriggered = false;+ } else {+ this.updateRelationsTab();+ }});// Listen to changes to this WP@@ -98,7 +109,12 @@ export class WorkPackageRelationsComponent extends UntilDestroyedMixin implement).subscribe((wp:WorkPackageResource) => {this.workPackage = wp;- this.updateRelationsTab();+ // When the change was triggered by the turbo:submit-end listener below, we will not udpate the tab again+ if (this.wpChangeManuallyTriggered) {+ this.wpChangeManuallyTriggered = false;+ } else {+ this.updateRelationsTab();+ }});/*@@ -114,23 +130,21 @@ export class WorkPackageRelationsComponent extends UntilDestroyedMixin implement*/document.addEventListener('turbo:submit-end', (event:CustomEvent) => {const form = event.target as HTMLFormElement;- const requestIsWithinFrame = form.action?.includes('relation') || form.action?.includes('child');-- if (requestIsWithinFrame) {- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment- const { fetchResponse } = event.detail;+ const updateWorkPackage = !!form.dataset?.updateWorkPackage;+ if (updateWorkPackage) {// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access- if (fetchResponse?.succeeded) {- // eslint-disable-next-line @typescript-eslint/no-unsafe-call-+ if (event.detail && event.detail.success) {// Update the work package+ this.wpChangeManuallyTriggered = true;void this.apiV3Service.work_packages.id(this.workPackage.id!).refresh();this.halEvents.push(this.workPackage, { eventType: 'updated' });+// Refetch relations+ this.relationChangeManuallyTriggered = true;void this.wpRelations.require(this.workPackage.id!, true);this.updateCounter();