Skip to content

Commit

Permalink
fix(issueProvider): crash on task done and related #3779
Browse files Browse the repository at this point in the history
  • Loading branch information
johannesjo committed Dec 21, 2024
1 parent 0cea914 commit bc4123e
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -22,9 +23,21 @@ import { IssueProviderService } from '../../../../issue-provider.service';
export class DialogJiraTransitionComponent {
T: typeof T = T;

_jiraCfg$: Observable<IssueProviderJira> = this._issueProviderService.getCfgOnce$(
this.data.task.issueProviderId!,
'JIRA',
_issueProviderIdOnce$: Observable<string> = 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<IssueProviderJira> = this._issueProviderIdOnce$.pipe(
switchMap((issueProviderId) =>
this._issueProviderService.getCfgOnce$(issueProviderId, 'JIRA'),
),
);

availableTransitions$: Observable<JiraOriginalTransition[]> = this._jiraCfg$.pipe(
Expand All @@ -42,17 +55,14 @@ export class DialogJiraTransitionComponent {
private _issueProviderService: IssueProviderService,
private _matDialogRef: MatDialogRef<DialogJiraTransitionComponent>,
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -52,14 +53,24 @@ 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,
cfg,
);
}),
);
_issueProviderIdOnce$: Observable<string> = 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(
Expand All @@ -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;
Expand All @@ -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) {
Expand All @@ -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(
Expand Down Expand Up @@ -190,7 +200,11 @@ export class DialogOpenProjectTrackTimeComponent {
}
}

private _getCfgOnce$(issueProviderId: string): Observable<OpenProjectCfg> {
return this._issueProviderService.getCfgOnce$(issueProviderId, 'OPEN_PROJECT');
private _getCfgOnce$(): Observable<OpenProjectCfg> {
return this._issueProviderIdOnce$.pipe(
switchMap((issueProviderId) =>
this._issueProviderService.getCfgOnce$(issueProviderId, 'OPEN_PROJECT'),
),
);
}
}
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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',
Expand All @@ -30,10 +31,25 @@ import { MatSlider } from '@angular/material/slider';
export class DialogOpenProjectTransitionComponent {
T: typeof T = T;

_issueProviderIdOnce$: Observable<string> = 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<IssueProviderOpenProject> =
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<OpenProjectOriginalStatus[]> =
Expand All @@ -56,16 +72,14 @@ export class DialogOpenProjectTransitionComponent {
private _issueProviderService: IssueProviderService,
private _matDialogRef: MatDialogRef<DialogOpenProjectTransitionComponent>,
private _snackService: SnackService,
private _taskService: TaskService,
@Inject(MAT_DIALOG_DATA)
public data: {
issue: OpenProjectWorkPackage;
localState: IssueLocalState;
task: Task;
},
) {
if (!this.data.task.issueProviderId) {
throw new Error('No issueProviderId for task');
}
this.percentageDone = data.issue.percentageDone;
}

Expand Down

0 comments on commit bc4123e

Please sign in to comment.