Skip to content

Commit 57a147d

Browse files
committed
[DURACOM-271] Remove form validation for patterns
1 parent 74e1e67 commit 57a147d

4 files changed

Lines changed: 19 additions & 35 deletions

File tree

src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ <h1 class="flex-grow-1">{{ isNewService ? ('ldn-create-service.title' | translat
212212
<span> {{'ldn-service.control-constaint-select-none' | translate}} </span>
213213
</button>
214214
<button (click)="selectInboundItemFilter(constraint.id, i); $event.stopPropagation()"
215-
*ngFor="let constraint of (itemfiltersRD$ | async)?.payload?.page; let internalIndex = index"
215+
*ngFor="let constraint of (itemFiltersRD$ | async)?.payload?.page; let internalIndex = index"
216216
class="dropdown-item collection-item text-truncate w-100"
217217
ngbDropdownItem
218218
type="button">

src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,15 @@ describe('LdnServiceFormEditComponent', () => {
145145

146146
it('should init properties correctly', fakeAsync(() => {
147147
spyOn(component, 'fetchServiceData');
148-
spyOn(component, 'setItemfilters');
148+
spyOn(component, 'setItemFilters');
149149
component.ngOnInit();
150150
tick(100);
151151
expect((component as any).serviceId).toEqual(testId);
152152
expect(component.isNewService).toBeFalsy();
153153
expect(component.areControlsInitialized).toBeTruthy();
154154
expect(component.formModel.controls.notifyServiceInboundPatterns).toBeDefined();
155155
expect(component.fetchServiceData).toHaveBeenCalledWith(testId);
156-
expect(component.setItemfilters).toHaveBeenCalled();
156+
expect(component.setItemFilters).toHaveBeenCalled();
157157
}));
158158

159159
it('should unsubscribe on destroy', () => {

src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.ts

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export class LdnServiceFormComponent implements OnInit, OnDestroy {
9292
public inboundPatterns: string[] = notifyPatterns;
9393
public isNewService: boolean;
9494
public areControlsInitialized: boolean;
95-
public itemfiltersRD$: Observable<RemoteData<PaginatedList<Itemfilter>>>;
95+
public itemFiltersRD$: Observable<RemoteData<PaginatedList<Itemfilter>>>;
9696
public config: FindListOptions = Object.assign(new FindListOptions(), {
9797
elementsPerPage: 20,
9898
});
@@ -104,12 +104,12 @@ export class LdnServiceFormComponent implements OnInit, OnDestroy {
104104
private deletedInboundPatterns: number[] = [];
105105
private modalRef: any;
106106
private ldnService: LdnService;
107-
private selectPatternDefaultLabeli18Key = 'ldn-service.form.label.placeholder.default-select';
107+
private selectPatternDefaultLabelI18Key = 'ldn-service.form.label.placeholder.default-select';
108108
private routeSubscription: Subscription;
109109

110110
constructor(
111111
protected ldnServicesService: LdnServicesService,
112-
private ldnItemfiltersService: LdnItemfiltersService,
112+
private ldnItemFiltersService: LdnItemfiltersService,
113113
private formBuilder: FormBuilder,
114114
private router: Router,
115115
private route: ActivatedRoute,
@@ -147,7 +147,7 @@ export class LdnServiceFormComponent implements OnInit, OnDestroy {
147147
this.fetchServiceData(this.serviceId);
148148
}
149149
});
150-
this.setItemfilters();
150+
this.setItemFilters();
151151
}
152152

153153
ngOnDestroy(): void {
@@ -157,8 +157,8 @@ export class LdnServiceFormComponent implements OnInit, OnDestroy {
157157
/**
158158
* Sets item filters using LDN item filters service
159159
*/
160-
setItemfilters() {
161-
this.itemfiltersRD$ = this.ldnItemfiltersService.findAll().pipe(
160+
setItemFilters() {
161+
this.itemFiltersRD$ = this.ldnItemFiltersService.findAll().pipe(
162162
getFirstCompletedRemoteData());
163163
}
164164

@@ -168,21 +168,12 @@ export class LdnServiceFormComponent implements OnInit, OnDestroy {
168168
*/
169169
createService() {
170170
this.formModel.markAllAsTouched();
171-
const notifyServiceInboundPatterns = this.formModel.get('notifyServiceInboundPatterns') as FormArray;
172-
const hasInboundPattern = notifyServiceInboundPatterns?.length > 0 ? this.checkPatterns(notifyServiceInboundPatterns) : false;
173171

174172
if (this.formModel.invalid) {
175173
this.closeModal();
176174
return;
177175
}
178176

179-
if (!hasInboundPattern) {
180-
this.notificationService.warning(this.translateService.get('ldn-service-notification.created.warning.title'));
181-
this.closeModal();
182-
return;
183-
}
184-
185-
186177
this.formModel.value.notifyServiceInboundPatterns = this.formModel.value.notifyServiceInboundPatterns.map((pattern: {
187178
pattern: string;
188179
patternLabel: string,
@@ -272,20 +263,24 @@ export class LdnServiceFormComponent implements OnInit, OnDestroy {
272263
}
273264

274265
/**
275-
* 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..
266+
* 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.
276267
* @param formArrayName - The name of the form array to be populated
277268
*/
278269
filterPatternObjectsAndAssignLabel(formArrayName: string) {
279270
const PatternsArray = this.formModel.get(formArrayName) as FormArray;
280271
PatternsArray.clear();
281272

282-
const servicesToUse = this.ldnService.notifyServiceInboundPatterns;
273+
const servicesToUse = [...this.ldnService.notifyServiceInboundPatterns];
274+
if (servicesToUse.length === 0) {
275+
servicesToUse.push({ pattern: '', constraint: '', automatic: 'false' });
276+
}
283277

284278
servicesToUse.forEach((patternObj: NotifyServicePattern) => {
285279
const patternFormGroup = this.initializeInboundPatternFormGroup();
280+
const patternLabel = patternObj?.pattern ? 'ldn-service.form.pattern.' + patternObj?.pattern + '.label' : 'ldn-service.form.label.placeholder.default-select';
286281
const newPatternObjWithLabel = Object.assign(new NotifyServicePattern(), {
287282
...patternObj,
288-
patternLabel: this.translateService.instant('ldn-service.form.pattern.' + patternObj?.pattern + '.label'),
283+
patternLabel: this.translateService.instant(patternLabel),
289284
});
290285
patternFormGroup.patchValue(newPatternObjWithLabel);
291286

@@ -412,7 +407,7 @@ export class LdnServiceFormComponent implements OnInit, OnDestroy {
412407
}
413408

414409
/**
415-
* Patches the LDN service by retrieving and sending patch operations geenrated in generatePatchOperations()
410+
* Patches the LDN service by retrieving and sending patch operations generated in generatePatchOperations()
416411
*/
417412
patchService() {
418413
this.deleteMarkedInboundPatterns();
@@ -425,17 +420,6 @@ export class LdnServiceFormComponent implements OnInit, OnDestroy {
425420
return;
426421
}
427422

428-
const notifyServiceInboundPatterns = this.formModel.get('notifyServiceInboundPatterns') as FormArray;
429-
const deletedInboundPatternsLength = this.deletedInboundPatterns.length;
430-
// If no inbound patterns are specified, close the modal and return
431-
// notify the user that no patterns are specified
432-
if (notifyServiceInboundPatterns.length === deletedInboundPatternsLength) {
433-
this.notificationService.warning(this.translateService.get('ldn-service-notification.created.warning.title'));
434-
this.deletedInboundPatterns = [];
435-
this.closeModal();
436-
return;
437-
}
438-
439423
this.ldnServicesService.patch(this.ldnService, patchOperations).pipe(
440424
getFirstCompletedRemoteData(),
441425
).subscribe(
@@ -571,7 +555,7 @@ export class LdnServiceFormComponent implements OnInit, OnDestroy {
571555
private createInboundPatternFormGroup(): FormGroup {
572556
const inBoundFormGroup = {
573557
pattern: '',
574-
patternLabel: this.translateService.instant(this.selectPatternDefaultLabeli18Key),
558+
patternLabel: this.translateService.instant(this.selectPatternDefaultLabelI18Key),
575559
constraint: '',
576560
constraintFormatted: '',
577561
automatic: false,

src/assets/i18n/en.json5

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6218,7 +6218,7 @@
62186218
"ldn-new-service.form.error.patterns": "At least a pattern is required",
62196219
"ldn-new-service.form.error.score": "Please enter a valid score (between 0 and 1). Use the “.” as decimal separator",
62206220

6221-
"ldn-new-service.form.label.inboundPattern": "Inbound Pattern",
6221+
"ldn-new-service.form.label.inboundPattern": "Supported Pattern",
62226222
"ldn-new-service.form.label.addPattern": "+ Add more",
62236223
"ldn-new-service.form.label.removeItemFilter": "Remove",
62246224
"ldn-register-new-service.breadcrumbs": "New Service",

0 commit comments

Comments
 (0)