[DURACOM-271] Remove form validation for patterns

This commit is contained in:
Giuseppe Digilio
2024-06-12 13:29:03 +02:00
parent 74e1e67126
commit 57a147d71a
4 changed files with 19 additions and 35 deletions

View File

@@ -212,7 +212,7 @@
<span> {{'ldn-service.control-constaint-select-none' | translate}} </span> <span> {{'ldn-service.control-constaint-select-none' | translate}} </span>
</button> </button>
<button (click)="selectInboundItemFilter(constraint.id, i); $event.stopPropagation()" <button (click)="selectInboundItemFilter(constraint.id, i); $event.stopPropagation()"
*ngFor="let constraint of (itemfiltersRD$ | async)?.payload?.page; let internalIndex = index" *ngFor="let constraint of (itemFiltersRD$ | async)?.payload?.page; let internalIndex = index"
class="dropdown-item collection-item text-truncate w-100" class="dropdown-item collection-item text-truncate w-100"
ngbDropdownItem ngbDropdownItem
type="button"> type="button">

View File

@@ -145,7 +145,7 @@ describe('LdnServiceFormEditComponent', () => {
it('should init properties correctly', fakeAsync(() => { it('should init properties correctly', fakeAsync(() => {
spyOn(component, 'fetchServiceData'); spyOn(component, 'fetchServiceData');
spyOn(component, 'setItemfilters'); spyOn(component, 'setItemFilters');
component.ngOnInit(); component.ngOnInit();
tick(100); tick(100);
expect((component as any).serviceId).toEqual(testId); expect((component as any).serviceId).toEqual(testId);
@@ -153,7 +153,7 @@ describe('LdnServiceFormEditComponent', () => {
expect(component.areControlsInitialized).toBeTruthy(); expect(component.areControlsInitialized).toBeTruthy();
expect(component.formModel.controls.notifyServiceInboundPatterns).toBeDefined(); expect(component.formModel.controls.notifyServiceInboundPatterns).toBeDefined();
expect(component.fetchServiceData).toHaveBeenCalledWith(testId); expect(component.fetchServiceData).toHaveBeenCalledWith(testId);
expect(component.setItemfilters).toHaveBeenCalled(); expect(component.setItemFilters).toHaveBeenCalled();
})); }));
it('should unsubscribe on destroy', () => { it('should unsubscribe on destroy', () => {

View File

@@ -92,7 +92,7 @@ export class LdnServiceFormComponent implements OnInit, OnDestroy {
public inboundPatterns: string[] = notifyPatterns; public inboundPatterns: string[] = notifyPatterns;
public isNewService: boolean; public isNewService: boolean;
public areControlsInitialized: boolean; public areControlsInitialized: boolean;
public itemfiltersRD$: Observable<RemoteData<PaginatedList<Itemfilter>>>; public itemFiltersRD$: Observable<RemoteData<PaginatedList<Itemfilter>>>;
public config: FindListOptions = Object.assign(new FindListOptions(), { public config: FindListOptions = Object.assign(new FindListOptions(), {
elementsPerPage: 20, elementsPerPage: 20,
}); });
@@ -104,12 +104,12 @@ export class LdnServiceFormComponent implements OnInit, OnDestroy {
private deletedInboundPatterns: number[] = []; private deletedInboundPatterns: number[] = [];
private modalRef: any; private modalRef: any;
private ldnService: LdnService; private ldnService: LdnService;
private selectPatternDefaultLabeli18Key = 'ldn-service.form.label.placeholder.default-select'; private selectPatternDefaultLabelI18Key = 'ldn-service.form.label.placeholder.default-select';
private routeSubscription: Subscription; private routeSubscription: Subscription;
constructor( constructor(
protected ldnServicesService: LdnServicesService, protected ldnServicesService: LdnServicesService,
private ldnItemfiltersService: LdnItemfiltersService, private ldnItemFiltersService: LdnItemfiltersService,
private formBuilder: FormBuilder, private formBuilder: FormBuilder,
private router: Router, private router: Router,
private route: ActivatedRoute, private route: ActivatedRoute,
@@ -147,7 +147,7 @@ export class LdnServiceFormComponent implements OnInit, OnDestroy {
this.fetchServiceData(this.serviceId); this.fetchServiceData(this.serviceId);
} }
}); });
this.setItemfilters(); this.setItemFilters();
} }
ngOnDestroy(): void { ngOnDestroy(): void {
@@ -157,8 +157,8 @@ export class LdnServiceFormComponent implements OnInit, OnDestroy {
/** /**
* Sets item filters using LDN item filters service * Sets item filters using LDN item filters service
*/ */
setItemfilters() { setItemFilters() {
this.itemfiltersRD$ = this.ldnItemfiltersService.findAll().pipe( this.itemFiltersRD$ = this.ldnItemFiltersService.findAll().pipe(
getFirstCompletedRemoteData()); getFirstCompletedRemoteData());
} }
@@ -168,21 +168,12 @@ export class LdnServiceFormComponent implements OnInit, OnDestroy {
*/ */
createService() { createService() {
this.formModel.markAllAsTouched(); this.formModel.markAllAsTouched();
const notifyServiceInboundPatterns = this.formModel.get('notifyServiceInboundPatterns') as FormArray;
const hasInboundPattern = notifyServiceInboundPatterns?.length > 0 ? this.checkPatterns(notifyServiceInboundPatterns) : false;
if (this.formModel.invalid) { if (this.formModel.invalid) {
this.closeModal(); this.closeModal();
return; return;
} }
if (!hasInboundPattern) {
this.notificationService.warning(this.translateService.get('ldn-service-notification.created.warning.title'));
this.closeModal();
return;
}
this.formModel.value.notifyServiceInboundPatterns = this.formModel.value.notifyServiceInboundPatterns.map((pattern: { this.formModel.value.notifyServiceInboundPatterns = this.formModel.value.notifyServiceInboundPatterns.map((pattern: {
pattern: string; pattern: string;
patternLabel: string, patternLabel: string,
@@ -272,20 +263,24 @@ export class LdnServiceFormComponent implements OnInit, OnDestroy {
} }
/** /**
* Filters pattern objects, initializes form groups, assigns labels, and adds them to the specified form array so the correct string is shown in the dropdown.. * Filters pattern objects, initializes form groups, assigns labels, and adds them to the specified form array so the correct string is shown in the dropdown.
* @param formArrayName - The name of the form array to be populated * @param formArrayName - The name of the form array to be populated
*/ */
filterPatternObjectsAndAssignLabel(formArrayName: string) { filterPatternObjectsAndAssignLabel(formArrayName: string) {
const PatternsArray = this.formModel.get(formArrayName) as FormArray; const PatternsArray = this.formModel.get(formArrayName) as FormArray;
PatternsArray.clear(); PatternsArray.clear();
const servicesToUse = this.ldnService.notifyServiceInboundPatterns; const servicesToUse = [...this.ldnService.notifyServiceInboundPatterns];
if (servicesToUse.length === 0) {
servicesToUse.push({ pattern: '', constraint: '', automatic: 'false' });
}
servicesToUse.forEach((patternObj: NotifyServicePattern) => { servicesToUse.forEach((patternObj: NotifyServicePattern) => {
const patternFormGroup = this.initializeInboundPatternFormGroup(); const patternFormGroup = this.initializeInboundPatternFormGroup();
const patternLabel = patternObj?.pattern ? 'ldn-service.form.pattern.' + patternObj?.pattern + '.label' : 'ldn-service.form.label.placeholder.default-select';
const newPatternObjWithLabel = Object.assign(new NotifyServicePattern(), { const newPatternObjWithLabel = Object.assign(new NotifyServicePattern(), {
...patternObj, ...patternObj,
patternLabel: this.translateService.instant('ldn-service.form.pattern.' + patternObj?.pattern + '.label'), patternLabel: this.translateService.instant(patternLabel),
}); });
patternFormGroup.patchValue(newPatternObjWithLabel); patternFormGroup.patchValue(newPatternObjWithLabel);
@@ -412,7 +407,7 @@ export class LdnServiceFormComponent implements OnInit, OnDestroy {
} }
/** /**
* Patches the LDN service by retrieving and sending patch operations geenrated in generatePatchOperations() * Patches the LDN service by retrieving and sending patch operations generated in generatePatchOperations()
*/ */
patchService() { patchService() {
this.deleteMarkedInboundPatterns(); this.deleteMarkedInboundPatterns();
@@ -425,17 +420,6 @@ export class LdnServiceFormComponent implements OnInit, OnDestroy {
return; return;
} }
const notifyServiceInboundPatterns = this.formModel.get('notifyServiceInboundPatterns') as FormArray;
const deletedInboundPatternsLength = this.deletedInboundPatterns.length;
// If no inbound patterns are specified, close the modal and return
// notify the user that no patterns are specified
if (notifyServiceInboundPatterns.length === deletedInboundPatternsLength) {
this.notificationService.warning(this.translateService.get('ldn-service-notification.created.warning.title'));
this.deletedInboundPatterns = [];
this.closeModal();
return;
}
this.ldnServicesService.patch(this.ldnService, patchOperations).pipe( this.ldnServicesService.patch(this.ldnService, patchOperations).pipe(
getFirstCompletedRemoteData(), getFirstCompletedRemoteData(),
).subscribe( ).subscribe(
@@ -571,7 +555,7 @@ export class LdnServiceFormComponent implements OnInit, OnDestroy {
private createInboundPatternFormGroup(): FormGroup { private createInboundPatternFormGroup(): FormGroup {
const inBoundFormGroup = { const inBoundFormGroup = {
pattern: '', pattern: '',
patternLabel: this.translateService.instant(this.selectPatternDefaultLabeli18Key), patternLabel: this.translateService.instant(this.selectPatternDefaultLabelI18Key),
constraint: '', constraint: '',
constraintFormatted: '', constraintFormatted: '',
automatic: false, automatic: false,

View File

@@ -6218,7 +6218,7 @@
"ldn-new-service.form.error.patterns": "At least a pattern is required", "ldn-new-service.form.error.patterns": "At least a pattern is required",
"ldn-new-service.form.error.score": "Please enter a valid score (between 0 and 1). Use the “.” as decimal separator", "ldn-new-service.form.error.score": "Please enter a valid score (between 0 and 1). Use the “.” as decimal separator",
"ldn-new-service.form.label.inboundPattern": "Inbound Pattern", "ldn-new-service.form.label.inboundPattern": "Supported Pattern",
"ldn-new-service.form.label.addPattern": "+ Add more", "ldn-new-service.form.label.addPattern": "+ Add more",
"ldn-new-service.form.label.removeItemFilter": "Remove", "ldn-new-service.form.label.removeItemFilter": "Remove",
"ldn-register-new-service.breadcrumbs": "New Service", "ldn-register-new-service.breadcrumbs": "New Service",