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

properly destroy form configuration component

ulferts7c3f6a902a76
diff --git a/frontend/src/app/features/admin/types/type-form-configuration.component.ts b/frontend/src/app/features/admin/types/type-form-configuration.component.ts
index b5984421959..94c498e4885 100644
--- a/frontend/src/app/features/admin/types/type-form-configuration.component.ts
+++ b/frontend/src/app/features/admin/types/type-form-configuration.component.ts
@@ -1,12 +1,10 @@
-import { AfterViewInit, Component, ElementRef, OnInit } from '@angular/core';
+import { AfterViewInit, Component, ElementRef, OnInit, OnDestroy } from '@angular/core';
import { I18nService } from 'core-app/core/i18n/i18n.service';
-import { ToastService } from 'core-app/shared/components/toaster/toast.service';
import {
ExternalRelationQueryConfigurationService,
} from 'core-app/features/work-packages/components/wp-table/external-configuration/external-relation-query-configuration.service';
import { DomAutoscrollService } from 'core-app/shared/helpers/drag-and-drop/dom-autoscroll.service';
import { DragulaService, DrakeWithModels } from 'ng2-dragula';
-import { GonService } from 'core-app/core/gon/gon.service';
import { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destroyed.mixin';
import { installMenuLogic } from 'core-app/core/setup/globals/global-listeners/action-menu';
import { ConfirmDialogService } from 'core-app/shared/components/modals/confirm-dialog/confirm-dialog.service';
@@ -39,7 +37,7 @@ export const emptyTypeGroup = '__empty';
TypeBannerService,
],
})
-export class TypeFormConfigurationComponent extends UntilDestroyedMixin implements OnInit, AfterViewInit {
+export class TypeFormConfigurationComponent extends UntilDestroyedMixin implements OnInit, AfterViewInit, OnDestroy {
public text = {
drag_to_activate: this.I18n.t('js.admin.type_form.drag_to_activate'),
reset: this.I18n.t('js.admin.type_form.reset_to_defaults'),
@@ -72,10 +70,8 @@ export class TypeFormConfigurationComponent extends UntilDestroyedMixin implemen
constructor(
private elementRef:ElementRef,
private I18n:I18nService,
- private Gon:GonService,
private dragula:DragulaService,
private confirmDialog:ConfirmDialogService,
- private toastService:ToastService,
private externalRelationQuery:ExternalRelationQueryConfigurationService,
readonly typeBanner:TypeBannerService,
) {
@@ -83,6 +79,13 @@ export class TypeFormConfigurationComponent extends UntilDestroyedMixin implemen
}
ngOnInit():void {
+ // For unclear reasons, this component is initialized twice if used in conjunction with
+ // turbo drive. This then leads to the groups defined in this component being duplicated.
+ // It does not harm to remove them if they exist but it would of course be better if that hack
+ // would not be necessary. The functionality should all be handled in ngOnDestroy.
+ this.dragula.destroy('groups');
+ this.dragula.destroy('attributes');
+
// Hook on form submit
this.element = this.elementRef.nativeElement;
this.no_filter_query = this.element.dataset.noFilterQuery!;
@@ -161,6 +164,12 @@ export class TypeFormConfigurationComponent extends UntilDestroyedMixin implemen
installMenuLogic(menu);
}
+ ngOnDestroy():void {
+ this.dragula.destroy('groups');
+ this.dragula.destroy('attributes');
+ this.autoscroll.destroy();
+ }
+
deactivateAttribute(attribute:TypeFormAttribute):void {
this.updateInactives(this.inactives.concat(attribute));
}