From a725f48870600bfb137c5a1637dafe7c29b7a680 Mon Sep 17 00:00:00 2001 From: MoritzWeber Date: Fri, 4 Oct 2024 15:37:14 +0200 Subject: [PATCH] fix: Git component form fields aren't activated properly Add `resultUrlPrefixAsyncValidator` again. Was removed in https://github.com/DSD-DBS/capella-collab-manager/pull/1838 --- .../manage-git-model.component.ts | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/frontend/src/app/projects/models/model-source/git/manage-git-model/manage-git-model.component.ts b/frontend/src/app/projects/models/model-source/git/manage-git-model/manage-git-model.component.ts index 21528c5544..abd44e9cf6 100644 --- a/frontend/src/app/projects/models/model-source/git/manage-git-model/manage-git-model.component.ts +++ b/frontend/src/app/projects/models/model-source/git/manage-git-model/manage-git-model.component.ts @@ -16,6 +16,9 @@ import { FormBuilder, FormsModule, ReactiveFormsModule, + AsyncValidatorFn, + AbstractControl, + ValidationErrors, } from '@angular/forms'; import { MatAutocompleteTrigger, @@ -36,7 +39,7 @@ import { MatSelect } from '@angular/material/select'; import { MatSlideToggle } from '@angular/material/slide-toggle'; import { ActivatedRoute, Router } from '@angular/router'; import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy'; -import { filter, map } from 'rxjs'; +import { filter, map, Observable, of } from 'rxjs'; import { BreadcrumbsService } from 'src/app/general/breadcrumbs/breadcrumbs.service'; import { ConfirmationDialogComponent } from 'src/app/helpers/confirmation-dialog/confirmation-dialog.component'; import { ToastService } from 'src/app/helpers/toast/toast.service'; @@ -170,6 +173,9 @@ export class ManageGitModelComponent implements OnInit, OnDestroy { if (gitInstances?.length) { this.urls.baseUrl.setValidators([Validators.required]); this.urls.inputUrl.setValidators([absoluteOrRelativeValidators()]); + this.form.controls.urls.setAsyncValidators([ + this.resultUrlPrefixAsyncValidator(), + ]); } else { this.urls.inputUrl.addValidators([Validators.required]); } @@ -470,4 +476,28 @@ export class ManageGitModelComponent implements OnInit, OnDestroy { return longestMatchingGitInstance; } + + private resultUrlPrefixAsyncValidator(): AsyncValidatorFn { + return (_: AbstractControl): Observable => { + this.updateResultUrl(); + + if (!this.resultUrl) return of({ required: true }); + + return this.settingsModelsourcesGitService + .validatePath({ url: this.resultUrl }) + .pipe( + map((prefixExists: boolean) => { + if (prefixExists) { + this.enableAllExceptUrls(); + return null; + } + + this.disableAllExpectUrls(); + return { + urlPrefixError: true, + }; + }), + ); + }; + } }