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
Fix EffectHandler no longer being registerable on angular components
Oliver Günther3fae74af683e
diff --git a/frontend/src/app/core/state/effects/effect-handler.decorator.ts b/frontend/src/app/core/state/effects/effect-handler.decorator.tsindex e54720b8541..9b25a0b4999 100644--- a/frontend/src/app/core/state/effects/effect-handler.decorator.ts+++ b/frontend/src/app/core/state/effects/effect-handler.decorator.ts@@ -4,6 +4,8 @@ import { ActionsService } from 'core-app/core/state/actions/actions.service';import { ActionCreator } from 'ts-action/action';import { Action } from 'ts-action';import { takeWhile } from 'rxjs/operators';+import { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destroyed.mixin';+import { Observable } from 'rxjs';/*** This interface specifies a constraint on the classes that can@@ -16,10 +18,42 @@ export interface EffectClass {ngOnDestroy?():void;}+const EffectHandlers = Symbol('EffectHandlers');type EffectHandlerItem = { callback:(action:Action) => void, action:ActionCreator };+interface DecoratedEffectClass {+ [EffectHandlers]:Map<string, EffectHandlerItem>+}++export function registerEffectCallbacks(instance:EffectClass, untilDestroyed:(source:Observable<unknown>) => Observable<unknown>):void {+ // Access the handlers registered in the @EffectCallback method decorator+ // We're accessing a separate symbol on the base class that is not present+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access+ const handlers = (instance as unknown as DecoratedEffectClass)[EffectHandlers];+ if (handlers) {+ handlers.forEach((item:EffectHandlerItem, key:string) => {+ debugLog(`[${instance.constructor.name}] Subscribing to effect ${key}`);++ // Subscribe to the specified action for the duration of this service's life.+ instance.actions$+ .ofType(item.action)+ .pipe(+ untilDestroyed,+ )+ .subscribe((action) => {+ // Wrap callback in a try-catch to avoid completing the subscription.+ try {+ item.callback.call(instance, action);+ } catch (e) {+ console.error(`Error thrown in effect callback ${key}: ${e as string}`);+ }+ });+ });+ }+}+/*** The EffectHandler decorates a class to be used for effects callbacks* To use, add it to a store service like so@@ -46,30 +80,7 @@ export function EffectHandler<T extends { new(...args:any[]):EffectClass }>(consconstructor(...args:any[]) {super(...args);- // Access the handlers registered in the @EffectCallback method decorator- // We're accessing a separate symbol on the base class that is not present- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access- const handlers = constructor.prototype[EffectHandlers] as Map<string, EffectHandlerItem>;- if (handlers) {- handlers.forEach((item:EffectHandlerItem, key:string) => {- debugLog(`[${constructor.name}] Subscribing to effect ${key}`);-- // Subscribe to the specified action for the duration of this service's life.- this.actions$- .ofType(item.action)- .pipe(- takeWhile(() => !this.serviceDestroyed),- )- .subscribe((instance) => {- // Wrap callback in a try-catch to avoid completing the subscription.- try {- item.callback.call(this, instance);- } catch (e) {- console.error(`Error thrown in effect callback ${key}: ${e as string}`);- }- });- });- }+ registerEffectCallbacks(this, takeWhile(() => !this.serviceDestroyed));}ngOnDestroy():void {diff --git a/frontend/src/app/features/team-planner/team-planner/page/team-planner-page.component.ts b/frontend/src/app/features/team-planner/team-planner/page/team-planner-page.component.tsindex 0c81583b60b..aaa239e2c88 100644--- a/frontend/src/app/features/team-planner/team-planner/page/team-planner-page.component.ts+++ b/frontend/src/app/features/team-planner/team-planner/page/team-planner-page.component.ts@@ -20,6 +20,7 @@ import { OpProjectIncludeComponent } from 'core-app/shared/components/project-inimport {EffectCallback,EffectHandler,+ registerEffectCallbacks,} from 'core-app/core/state/effects/effect-handler.decorator';import {teamPlannerEventAdded,@@ -30,7 +31,6 @@ import { ActionsService } from 'core-app/core/state/actions/actions.service';import { OpWorkPackagesCalendarService } from 'core-app/features/calendar/op-work-packages-calendar.service';import { OpCalendarService } from 'core-app/features/calendar/op-calendar.service';-@EffectHandler@Component({templateUrl: '../../../work-packages/routing/partitioned-query-space-page/partitioned-query-space-page.component.html',styleUrls: [@@ -101,6 +101,8 @@ export class TeamPlannerPageComponent extends PartitionedQuerySpacePageComponentpublic ngOnInit():void {super.ngOnInit();+ registerEffectCallbacks(this, this.untilDestroyed());+this.wpTableFilters.hidden.push('assignee','startDate',diff --git a/frontend/src/app/features/team-planner/team-planner/planner/team-planner.component.ts b/frontend/src/app/features/team-planner/team-planner/planner/team-planner.component.tsindex 3a7cc1e7742..d412135950d 100644--- a/frontend/src/app/features/team-planner/team-planner/planner/team-planner.component.ts+++ b/frontend/src/app/features/team-planner/team-planner/planner/team-planner.component.ts@@ -74,9 +74,7 @@ import { FullCalendarComponent } from '@fullcalendar/angular';import { I18nService } from 'core-app/core/i18n/i18n.service';import { ConfigurationService } from 'core-app/core/config/configuration.service';import { EventViewLookupService } from 'core-app/features/team-planner/team-planner/planner/event-view-lookup.service';-import {- WorkPackageViewFiltersService,-} from 'core-app/features/work-packages/routing/wp-view-base/view-services/wp-view-filters.service';+import { WorkPackageViewFiltersService } from 'core-app/features/work-packages/routing/wp-view-base/view-services/wp-view-filters.service';import { IsolatedQuerySpace } from 'core-app/features/work-packages/directives/query-space/isolated-query-space';import { CurrentProjectService } from 'core-app/core/current-project/current-project.service';import { splitViewRoute } from 'core-app/features/work-packages/routing/split-view-routes.helper';@@ -90,18 +88,14 @@ import { WorkPackageResource } from 'core-app/features/hal/resources/work-packagimport { HalResource } from 'core-app/features/hal/resources/hal-resource';import { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destroyed.mixin';import { OpCalendarService } from 'core-app/features/calendar/op-calendar.service';-import {- HalResourceEditingService,-} from 'core-app/shared/components/fields/edit/services/hal-resource-editing.service';+import { HalResourceEditingService } from 'core-app/shared/components/fields/edit/services/hal-resource-editing.service';import { HalResourceNotificationService } from 'core-app/features/hal/services/hal-resource-notification.service';import { SchemaCacheService } from 'core-app/core/schemas/schema-cache.service';import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';import { CalendarDragDropService } from 'core-app/features/team-planner/team-planner/calendar-drag-drop.service';import { StatusResource } from 'core-app/features/hal/resources/status-resource';import { ResourceChangeset } from 'core-app/shared/components/fields/changeset/resource-changeset';-import {- KeepTabService,-} from 'core-app/features/work-packages/components/wp-single-view-tabs/keep-tab/keep-tab.service';+import { KeepTabService } from 'core-app/features/work-packages/components/wp-single-view-tabs/keep-tab/keep-tab.service';import { HalError } from 'core-app/features/hal/services/hal-error';import { ActionsService } from 'core-app/core/state/actions/actions.service';import {@@ -126,7 +120,7 @@ import { ResourceApi } from '@fullcalendar/resource';import { DeviceService } from 'core-app/core/browser/device.service';import {EffectCallback,- EffectHandler,+ registerEffectCallbacks,} from 'core-app/core/state/effects/effect-handler.decorator';import {addBackgroundEvents,@@ -137,7 +131,6 @@ import * as moment from 'moment-timezone';export type TeamPlannerViewOptionKey = 'resourceTimelineWorkWeek'|'resourceTimelineWeek'|'resourceTimelineTwoWeeks';export type TeamPlannerViewOptions = { [K in TeamPlannerViewOptionKey]:RawOptionsFromRefiners<Required<ViewOptionRefiners>> };-@EffectHandler@Component({selector: 'op-team-planner',templateUrl: './team-planner.component.html',@@ -405,6 +398,7 @@ export class TeamPlannerComponent extends UntilDestroyedMixin implements OnInit,}ngOnInit():void {+ registerEffectCallbacks(this, this.untilDestroyed());this.initializeCalendar();this.projectIdentifier = this.currentProject.identifier || undefined;