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

Avoid StateService.go on every type switch

Oliver Günther9c1935a8a8ee
diff --git a/frontend/src/app/shared/components/fields/edit/field-types/select-edit-field/select-edit-field.component.ts b/frontend/src/app/shared/components/fields/edit/field-types/select-edit-field/select-edit-field.component.ts
index ab0be6f9e2b..ae08ab9d9e7 100644
--- a/frontend/src/app/shared/components/fields/edit/field-types/select-edit-field/select-edit-field.component.ts
+++ b/frontend/src/app/shared/components/fields/edit/field-types/select-edit-field/select-edit-field.component.ts
@@ -26,25 +26,19 @@
// See COPYRIGHT and LICENSE files for more details.
//++
-import {
- Component,
- InjectFlags,
- OnInit,
-} from '@angular/core';
+import { Component, InjectFlags, OnInit, } from '@angular/core';
import { HalResource } from 'core-app/features/hal/resources/hal-resource';
-import { SelectAutocompleterRegisterService } from 'core-app/shared/components/fields/edit/field-types/select-edit-field/select-autocompleter-register.service';
-import {
- from,
- Observable,
-} from 'rxjs';
import {
- map,
- tap,
-} from 'rxjs/operators';
+ SelectAutocompleterRegisterService
+} from 'core-app/shared/components/fields/edit/field-types/select-edit-field/select-autocompleter-register.service';
+import { from, Observable, } from 'rxjs';
+import { map, tap, } from 'rxjs/operators';
import { InjectField } from 'core-app/shared/helpers/angular/inject-field.decorator';
-import { CreateAutocompleterComponent } from 'core-app/shared/components/autocompleter/create-autocompleter/create-autocompleter.component';
+import {
+ CreateAutocompleterComponent
+} from 'core-app/shared/components/autocompleter/create-autocompleter/create-autocompleter.component';
import { EditFormComponent } from 'core-app/shared/components/fields/edit/edit-form/edit-form.component';
-import { StateService } from '@uirouter/core';
+import { StateService, UIRouterGlobals } from '@uirouter/core';
import { CollectionResource } from 'core-app/features/hal/resources/collection-resource';
import { HalResourceNotificationService } from 'core-app/features/hal/services/hal-resource-notification.service';
import { HalResourceSortingService } from 'core-app/features/hal/services/hal-resource-sorting.service';
@@ -68,6 +62,8 @@ export class SelectEditFieldComponent extends EditFieldComponent implements OnIn
@InjectField() $state:StateService;
+ @InjectField() uiRouterGlobals:UIRouterGlobals;
+
@InjectField(EditFormComponent, null, InjectFlags.Optional) editFormComponent:EditFormComponent;
public availableOptions:any[];
@@ -304,10 +300,12 @@ export class SelectEditFieldComponent extends EditFieldComponent implements OnIn
// in order to keep the form changes (changeset) between route/state changes
if (fieldName === 'type' && editMode) {
this.handler.registerOnBeforeSubmit(() => {
- const newType = this.value?.$source?.id;
+ const oldType = this.uiRouterGlobals.params.type as string|null;
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
+ const newType = (this.value as HalResource)?.$source?.id as string;
- if (newType) {
- this.$state.go('.', { type: newType }, { notify: false });
+ if (oldType && newType) {
+ void this.$state.go('.', { type: newType }, { notify: false });
}
});
}