From 3a5416f5f07a4c504503f08c18a628cc24962729 Mon Sep 17 00:00:00 2001 From: Misra Aditya Date: Sat, 20 Jan 2024 12:43:35 +0800 Subject: [PATCH 1/6] Add whitespace validation --- src/app/phase-bug-reporting/new-issue/new-issue.component.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/app/phase-bug-reporting/new-issue/new-issue.component.ts b/src/app/phase-bug-reporting/new-issue/new-issue.component.ts index 58234c92c..3dbe8c775 100644 --- a/src/app/phase-bug-reporting/new-issue/new-issue.component.ts +++ b/src/app/phase-bug-reporting/new-issue/new-issue.component.ts @@ -41,6 +41,10 @@ export class NewIssueComponent implements OnInit { if (this.newIssueForm.invalid) { return; } + + if (this.title.value && this.title.value.trim() === '') { + throw new Error('Invalid title: Title cannot contain only whitespaces'); + } this.isFormPending = true; this.issueService .createIssue(this.title.value, Issue.updateDescription(this.description.value), this.severity.value, this.type.value) From 4b275ad2c82df4b47a47b0360db8666b775d6f59 Mon Sep 17 00:00:00 2001 From: Misra Aditya Date: Sat, 20 Jan 2024 16:01:00 +0800 Subject: [PATCH 2/6] Update whitespace validation for new issue --- .../new-issue/new-issue.component.html | 1 + .../new-issue/new-issue.component.ts | 8 +++----- src/app/validators/noWhitespace.validator.ts | 10 ++++++++++ 3 files changed, 14 insertions(+), 5 deletions(-) create mode 100644 src/app/validators/noWhitespace.validator.ts diff --git a/src/app/phase-bug-reporting/new-issue/new-issue.component.html b/src/app/phase-bug-reporting/new-issue/new-issue.component.html index 5af3d8332..dd98459dd 100644 --- a/src/app/phase-bug-reporting/new-issue/new-issue.component.html +++ b/src/app/phase-bug-reporting/new-issue/new-issue.component.html @@ -7,6 +7,7 @@

New Issue

Title required. + Title cannot contain only whitespaces. Title cannot exceed 256 characters. {{ 256 - title.value?.length }} characters remaining. diff --git a/src/app/phase-bug-reporting/new-issue/new-issue.component.ts b/src/app/phase-bug-reporting/new-issue/new-issue.component.ts index 3dbe8c775..3e13cd876 100644 --- a/src/app/phase-bug-reporting/new-issue/new-issue.component.ts +++ b/src/app/phase-bug-reporting/new-issue/new-issue.component.ts @@ -1,5 +1,5 @@ import { Component, OnInit } from '@angular/core'; -import { AbstractControl, FormBuilder, FormGroup, NgForm, Validators } from '@angular/forms'; +import { AbstractControl, FormBuilder, FormGroup, NgForm, Validators, ValidationErrors, ValidatorFn } from '@angular/forms'; import { Router } from '@angular/router'; import { finalize } from 'rxjs/operators'; import { Issue } from '../../core/models/issue.model'; @@ -7,6 +7,7 @@ import { ErrorHandlingService } from '../../core/services/error-handling.service import { IssueService } from '../../core/services/issue.service'; import { LabelService } from '../../core/services/label.service'; import { SUBMIT_BUTTON_TEXT } from '../../shared/view-issue/view-issue.component'; +import { noWhitespace } from '../../validators/noWhitespace.validator'; @Component({ selector: 'app-new-issue', @@ -28,7 +29,7 @@ export class NewIssueComponent implements OnInit { ngOnInit() { this.newIssueForm = this.formBuilder.group({ - title: ['', [Validators.required, Validators.maxLength(256)]], + title: ['', [Validators.required, Validators.maxLength(256), noWhitespace()]], description: [''], severity: ['', Validators.required], type: ['', Validators.required] @@ -42,9 +43,6 @@ export class NewIssueComponent implements OnInit { return; } - if (this.title.value && this.title.value.trim() === '') { - throw new Error('Invalid title: Title cannot contain only whitespaces'); - } this.isFormPending = true; this.issueService .createIssue(this.title.value, Issue.updateDescription(this.description.value), this.severity.value, this.type.value) diff --git a/src/app/validators/noWhitespace.validator.ts b/src/app/validators/noWhitespace.validator.ts new file mode 100644 index 000000000..696232327 --- /dev/null +++ b/src/app/validators/noWhitespace.validator.ts @@ -0,0 +1,10 @@ +import { AbstractControl, ValidationErrors, ValidatorFn } from '@angular/forms'; + +export function noWhitespace(): ValidatorFn { + return (title: AbstractControl): ValidationErrors | null => { + if (title.value && title.value.trim() === '') { + return { whitespace: true }; + } + return null; + }; +} From dbf91bde7e5db3a69f9b5a0fef8d0f3b93ab9aac Mon Sep 17 00:00:00 2001 From: Misra Aditya Date: Sat, 20 Jan 2024 16:09:11 +0800 Subject: [PATCH 3/6] Update whitespace validation for title of new issues --- src/app/phase-bug-reporting/new-issue/new-issue.component.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/phase-bug-reporting/new-issue/new-issue.component.ts b/src/app/phase-bug-reporting/new-issue/new-issue.component.ts index 3e13cd876..31e30de74 100644 --- a/src/app/phase-bug-reporting/new-issue/new-issue.component.ts +++ b/src/app/phase-bug-reporting/new-issue/new-issue.component.ts @@ -1,13 +1,13 @@ import { Component, OnInit } from '@angular/core'; -import { AbstractControl, FormBuilder, FormGroup, NgForm, Validators, ValidationErrors, ValidatorFn } from '@angular/forms'; +import { AbstractControl, FormBuilder, FormGroup, NgForm, Validators } from '@angular/forms'; import { Router } from '@angular/router'; import { finalize } from 'rxjs/operators'; import { Issue } from '../../core/models/issue.model'; import { ErrorHandlingService } from '../../core/services/error-handling.service'; import { IssueService } from '../../core/services/issue.service'; import { LabelService } from '../../core/services/label.service'; -import { SUBMIT_BUTTON_TEXT } from '../../shared/view-issue/view-issue.component'; import { noWhitespace } from '../../validators/noWhitespace.validator'; +import { SUBMIT_BUTTON_TEXT } from '../../shared/view-issue/view-issue.component'; @Component({ selector: 'app-new-issue', From 98dbc25a3c176d05a87cdddb9642db6cd3fa266d Mon Sep 17 00:00:00 2001 From: Misra Aditya Date: Sat, 20 Jan 2024 16:14:09 +0800 Subject: [PATCH 4/6] Update whitespace validation for title of new issues --- src/app/phase-bug-reporting/new-issue/new-issue.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/phase-bug-reporting/new-issue/new-issue.component.ts b/src/app/phase-bug-reporting/new-issue/new-issue.component.ts index 31e30de74..3c7474d77 100644 --- a/src/app/phase-bug-reporting/new-issue/new-issue.component.ts +++ b/src/app/phase-bug-reporting/new-issue/new-issue.component.ts @@ -6,8 +6,8 @@ import { Issue } from '../../core/models/issue.model'; import { ErrorHandlingService } from '../../core/services/error-handling.service'; import { IssueService } from '../../core/services/issue.service'; import { LabelService } from '../../core/services/label.service'; -import { noWhitespace } from '../../validators/noWhitespace.validator'; import { SUBMIT_BUTTON_TEXT } from '../../shared/view-issue/view-issue.component'; +import { noWhitespace } from '../../validators/noWhitespace.validator'; @Component({ selector: 'app-new-issue', From 554005051db0e7b63e081eed2b015e681b47ca49 Mon Sep 17 00:00:00 2001 From: Misra Aditya Date: Sun, 21 Jan 2024 16:48:25 +0800 Subject: [PATCH 5/6] Move validators into core --- src/app/{ => core}/validators/noWhitespace.validator.ts | 0 src/app/phase-bug-reporting/new-issue/new-issue.component.ts | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename src/app/{ => core}/validators/noWhitespace.validator.ts (100%) diff --git a/src/app/validators/noWhitespace.validator.ts b/src/app/core/validators/noWhitespace.validator.ts similarity index 100% rename from src/app/validators/noWhitespace.validator.ts rename to src/app/core/validators/noWhitespace.validator.ts diff --git a/src/app/phase-bug-reporting/new-issue/new-issue.component.ts b/src/app/phase-bug-reporting/new-issue/new-issue.component.ts index 3c7474d77..c0057665f 100644 --- a/src/app/phase-bug-reporting/new-issue/new-issue.component.ts +++ b/src/app/phase-bug-reporting/new-issue/new-issue.component.ts @@ -7,7 +7,7 @@ import { ErrorHandlingService } from '../../core/services/error-handling.service import { IssueService } from '../../core/services/issue.service'; import { LabelService } from '../../core/services/label.service'; import { SUBMIT_BUTTON_TEXT } from '../../shared/view-issue/view-issue.component'; -import { noWhitespace } from '../../validators/noWhitespace.validator'; +import { noWhitespace } from '../../core/validators/noWhitespace.validator'; @Component({ selector: 'app-new-issue', From 478b7d1bfd4de24fcc6c069362e9370b10b0d201 Mon Sep 17 00:00:00 2001 From: Misra Aditya Date: Sun, 21 Jan 2024 16:56:01 +0800 Subject: [PATCH 6/6] Update import order --- src/app/phase-bug-reporting/new-issue/new-issue.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/phase-bug-reporting/new-issue/new-issue.component.ts b/src/app/phase-bug-reporting/new-issue/new-issue.component.ts index c0057665f..cbd3e3c40 100644 --- a/src/app/phase-bug-reporting/new-issue/new-issue.component.ts +++ b/src/app/phase-bug-reporting/new-issue/new-issue.component.ts @@ -6,8 +6,8 @@ import { Issue } from '../../core/models/issue.model'; import { ErrorHandlingService } from '../../core/services/error-handling.service'; import { IssueService } from '../../core/services/issue.service'; import { LabelService } from '../../core/services/label.service'; -import { SUBMIT_BUTTON_TEXT } from '../../shared/view-issue/view-issue.component'; import { noWhitespace } from '../../core/validators/noWhitespace.validator'; +import { SUBMIT_BUTTON_TEXT } from '../../shared/view-issue/view-issue.component'; @Component({ selector: 'app-new-issue',