diff --git a/src/app/features/issue/providers/jira/jira-view-components/dialog-jira-transition/dialog-jira-transition.component.ts b/src/app/features/issue/providers/jira/jira-view-components/dialog-jira-transition/dialog-jira-transition.component.ts index 29104f3acad..c4a257cbdf9 100644 --- a/src/app/features/issue/providers/jira/jira-view-components/dialog-jira-transition/dialog-jira-transition.component.ts +++ b/src/app/features/issue/providers/jira/jira-view-components/dialog-jira-transition/dialog-jira-transition.component.ts @@ -2,15 +2,16 @@ import { ChangeDetectionStrategy, Component, Inject } from '@angular/core'; import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; import { IssueLocalState, IssueProviderJira } from '../../../../issue.model'; import { JiraIssueReduced } from '../../jira-issue/jira-issue.model'; -import { Observable } from 'rxjs'; +import { Observable, of } from 'rxjs'; import { JiraApiService } from '../../jira-api.service'; import { JiraOriginalTransition } from '../../jira-api-responses'; import { SnackService } from '../../../../../../core/snack/snack.service'; -import { concatMap, first, switchMap } from 'rxjs/operators'; +import { concatMap, first, map, switchMap } from 'rxjs/operators'; import { T } from '../../../../../../t.const'; import { Task } from '../../../../../tasks/task.model'; import { IssueService } from '../../../../issue.service'; import { IssueProviderService } from '../../../../issue-provider.service'; +import { TaskService } from '../../../../../tasks/task.service'; @Component({ selector: 'dialog-jira-transition', @@ -22,9 +23,21 @@ import { IssueProviderService } from '../../../../issue-provider.service'; export class DialogJiraTransitionComponent { T: typeof T = T; - _jiraCfg$: Observable = this._issueProviderService.getCfgOnce$( - this.data.task.issueProviderId!, - 'JIRA', + _issueProviderIdOnce$: Observable = this.data.task.issueProviderId + ? of(this.data.task.issueProviderId) + : this._taskService.getByIdOnce$(this.data.task.parentId as string).pipe( + map((parentTask) => { + if (!parentTask.issueProviderId) { + throw new Error('No issue provider id found'); + } + return parentTask.issueProviderId; + }), + ); + + _jiraCfg$: Observable = this._issueProviderIdOnce$.pipe( + switchMap((issueProviderId) => + this._issueProviderService.getCfgOnce$(issueProviderId, 'JIRA'), + ), ); availableTransitions$: Observable = this._jiraCfg$.pipe( @@ -42,17 +55,14 @@ export class DialogJiraTransitionComponent { private _issueProviderService: IssueProviderService, private _matDialogRef: MatDialogRef, private _snackService: SnackService, + private _taskService: TaskService, @Inject(MAT_DIALOG_DATA) public data: { issue: JiraIssueReduced; localState: IssueLocalState; task: Task; }, - ) { - if (!this.data.task.issueProviderId) { - throw new Error('No issueProviderId for task'); - } - } + ) {} close(): void { this._matDialogRef.close(); diff --git a/src/app/features/issue/providers/open-project/open-project-view-components/dialog-open-project-track-time/dialog-open-project-track-time.component.ts b/src/app/features/issue/providers/open-project/open-project-view-components/dialog-open-project-track-time/dialog-open-project-track-time.component.ts index 009001f0379..b66a5dce2fa 100644 --- a/src/app/features/issue/providers/open-project/open-project-view-components/dialog-open-project-track-time/dialog-open-project-track-time.component.ts +++ b/src/app/features/issue/providers/open-project/open-project-view-components/dialog-open-project-track-time/dialog-open-project-track-time.component.ts @@ -12,19 +12,20 @@ import { JIRA_WORK_LOG_EXPORT_CHECKBOXES, JIRA_WORK_LOG_EXPORT_FORM_OPTIONS, } from '../../../jira/jira.const'; -import { Observable, Subscription } from 'rxjs'; +import { Observable, of, Subscription } from 'rxjs'; import { expandFadeAnimation } from '../../../../../../ui/animations/expand.ani'; import { DateService } from 'src/app/core/date/date.service'; import { IssueProviderService } from '../../../../issue-provider.service'; import { OpenProjectCfg } from '../../open-project.model'; import { formatOpenProjectWorkPackageSubjectForSnack } from '../../format-open-project-work-package-subject.util'; -import { concatMap, first } from 'rxjs/operators'; +import { concatMap, first, map, switchMap } from 'rxjs/operators'; import { Store } from '@ngrx/store'; import { IssueProviderActions } from '../../../../store/issue-provider.actions'; import { assertTruthy } from '../../../../../../util/assert-truthy'; import { UiModule } from '../../../../../../ui/ui.module'; import { FormsModule } from '@angular/forms'; import { AsyncPipe, NgForOf, NgIf } from '@angular/common'; +import { TaskService } from '../../../../../tasks/task.service'; @Component({ selector: 'dialog-open-project-track-time', @@ -52,7 +53,7 @@ export class DialogOpenProjectTrackTimeComponent { timeSpentLoggedDelta: number; activityId: number = 1; - activities$ = this._getCfgOnce$(assertTruthy(this.data.task.issueProviderId)).pipe( + activities$ = this._getCfgOnce$().pipe( concatMap((cfg) => { return this._openProjectApiService.getActivitiesForTrackTime$( this.workPackage.id, @@ -60,6 +61,16 @@ export class DialogOpenProjectTrackTimeComponent { ); }), ); + _issueProviderIdOnce$: Observable = this.data.task.issueProviderId + ? of(this.data.task.issueProviderId) + : this._taskService.getByIdOnce$(this.data.task.parentId as string).pipe( + map((parentTask) => { + if (!parentTask.issueProviderId) { + throw new Error('No issue provider id found'); + } + return parentTask.issueProviderId; + }), + ); private _subs = new Subscription(); constructor( @@ -68,6 +79,7 @@ export class DialogOpenProjectTrackTimeComponent { private _snackService: SnackService, private _store: Store, private _issueProviderService: IssueProviderService, + private _taskService: TaskService, @Inject(MAT_DIALOG_DATA) public data: { workPackage: OpenProjectWorkPackage; @@ -89,7 +101,7 @@ export class DialogOpenProjectTrackTimeComponent { ); this._subs.add( - this._getCfgOnce$(assertTruthy(this.data.task.issueProviderId)) + this._getCfgOnce$() .pipe(first()) .subscribe((cfg) => { if (cfg.timeTrackingDialogDefaultTime) { @@ -111,9 +123,7 @@ export class DialogOpenProjectTrackTimeComponent { this.timeSpent && this.data.task.issueProviderId ) { - const cfg = await this._getCfgOnce$(this.data.task.issueProviderId) - .pipe(first()) - .toPromise(); + const cfg = await this._getCfgOnce$().pipe(first()).toPromise(); if (this.defaultTimeCheckboxContent?.isChecked === true) { this._store.dispatch( @@ -190,7 +200,11 @@ export class DialogOpenProjectTrackTimeComponent { } } - private _getCfgOnce$(issueProviderId: string): Observable { - return this._issueProviderService.getCfgOnce$(issueProviderId, 'OPEN_PROJECT'); + private _getCfgOnce$(): Observable { + return this._issueProviderIdOnce$.pipe( + switchMap((issueProviderId) => + this._issueProviderService.getCfgOnce$(issueProviderId, 'OPEN_PROJECT'), + ), + ); } } diff --git a/src/app/features/issue/providers/open-project/open-project-view-components/dialog-openproject-transition/dialog-open-project-transition.component.ts b/src/app/features/issue/providers/open-project/open-project-view-components/dialog-openproject-transition/dialog-open-project-transition.component.ts index e095294d1ee..8db22855872 100644 --- a/src/app/features/issue/providers/open-project/open-project-view-components/dialog-openproject-transition/dialog-open-project-transition.component.ts +++ b/src/app/features/issue/providers/open-project/open-project-view-components/dialog-openproject-transition/dialog-open-project-transition.component.ts @@ -1,7 +1,7 @@ import { ChangeDetectionStrategy, Component, Inject } from '@angular/core'; import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; -import { Observable } from 'rxjs'; -import { concatMap, first, switchMap } from 'rxjs/operators'; +import { Observable, of } from 'rxjs'; +import { concatMap, first, map, switchMap } from 'rxjs/operators'; import { SnackService } from 'src/app/core/snack/snack.service'; import { IssueLocalState, @@ -19,6 +19,7 @@ import { UiModule } from '../../../../../../ui/ui.module'; import { FormsModule } from '@angular/forms'; import { AsyncPipe, NgForOf } from '@angular/common'; import { MatSlider } from '@angular/material/slider'; +import { TaskService } from '../../../../../tasks/task.service'; @Component({ selector: 'dialog-open-project-transition', @@ -30,10 +31,25 @@ import { MatSlider } from '@angular/material/slider'; export class DialogOpenProjectTransitionComponent { T: typeof T = T; + _issueProviderIdOnce$: Observable = this.data.task.issueProviderId + ? of(this.data.task.issueProviderId) + : this._taskService.getByIdOnce$(this.data.task.parentId as string).pipe( + map((parentTask) => { + if (!parentTask.issueProviderId) { + throw new Error('No issue provider id found'); + } + return parentTask.issueProviderId; + }), + ); + _openProjectCfg$: Observable = - this._issueProviderService.getCfgOnce$( - assertTruthy(this.data.task.issueProviderId), - 'OPEN_PROJECT', + this._issueProviderIdOnce$.pipe( + switchMap(() => + this._issueProviderService.getCfgOnce$( + assertTruthy(this.data.task.issueProviderId), + 'OPEN_PROJECT', + ), + ), ); availableTransitions$: Observable = @@ -56,6 +72,7 @@ export class DialogOpenProjectTransitionComponent { private _issueProviderService: IssueProviderService, private _matDialogRef: MatDialogRef, private _snackService: SnackService, + private _taskService: TaskService, @Inject(MAT_DIALOG_DATA) public data: { issue: OpenProjectWorkPackage; @@ -63,9 +80,6 @@ export class DialogOpenProjectTransitionComponent { task: Task; }, ) { - if (!this.data.task.issueProviderId) { - throw new Error('No issueProviderId for task'); - } this.percentageDone = data.issue.percentageDone; }