Skip to content

Commit

Permalink
Merge pull request #1232 from DSD-DBS/fix-t4c-repo-warnings
Browse files Browse the repository at this point in the history
fix: Properly show T4C repo deletion warnings
  • Loading branch information
MoritzWeber0 authored Dec 12, 2023
2 parents f6e8fb9 + 204b971 commit f6d7c3d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,12 @@ def create_single_warning_response_model(
title: str, reason: str | tuple[str, ...], technical: str
) -> core_models.ResponseModel:
return core_models.ResponseModel(
errors=[],
warnings=[
core_models.Message(
title=title,
reason=reason,
technical=technical,
)
]
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,9 @@ export class ErrorHandlingInterceptor implements HttpInterceptor {
);
}
}
if (body?.warnings) {
for (const warning of body.warnings) {
if (warning.reason && Array.isArray(warning.reason)) {
warning.reason = warning.reason.join(' ');
}
this.toastService.showWarning(
warning.title || '',
warning.reason || '',
);
}
const warnings = body?.warnings;
if (warnings) {
this.displayWarningInToaster(warnings);
}
}
},
Expand Down Expand Up @@ -97,10 +90,15 @@ export class ErrorHandlingInterceptor implements HttpInterceptor {
'Please check your internet connection and refresh the page!',
);
} else {
this.toastService.showError(
'An error occurred!',
'Please try again!',
);
const warnings = err.error?.warnings;
if (warnings) {
this.displayWarningInToaster(warnings);
} else {
this.toastService.showError(
'An error occurred!',
'Please try again!',
);
}
}
},
}),
Expand Down Expand Up @@ -163,6 +161,15 @@ export class ErrorHandlingInterceptor implements HttpInterceptor {
throw err;
}

private displayWarningInToaster(warnings: ErrorDetail[]): void {
for (const warning of warnings) {
if (warning.reason && Array.isArray(warning.reason)) {
warning.reason = warning.reason.join(' ');
}
this.toastService.showWarning(warning.title || '', warning.reason || '');
}
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
private isErrorHandlingSkipped(request: HttpRequest<any>) {
return request.context.get(SKIP_ERROR_HANDLING);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ <h1>Remove T4C repository</h1>
<p><b>The deletion cannot be undone!</b></p>
</div>
Please type in the name of the repository to confirm the deletion: <br />
<form (submit)="remoteRepository()">
<form (submit)="removeRepository()">
<mat-form-field appearance="fill">
<mat-label>Repository name</mat-label>
<input
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
Validators,
} from '@angular/forms';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { finalize } from 'rxjs';
import {
T4CRepoService,
T4CRepository,
Expand All @@ -34,13 +35,17 @@ export class T4CRepoDeletionDialogComponent {
@Inject(MAT_DIALOG_DATA) public repo: T4CRepository,
) {}

remoteRepository(): void {
removeRepository(): void {
if (this.repositoryNameForm.valid) {
this.repoService
.deleteRepository(this.repo.instance.id, this.repo.id)
.subscribe(() => {
this.dialogRef.close(true);
});
.pipe(
finalize(() => {
this.repoService.loadRepositories(this.repo.instance.id);
this.dialogRef.close(true);
}),
)
.subscribe();
}
}

Expand Down

0 comments on commit f6d7c3d

Please sign in to comment.