mirror of
https://github.com/bitwarden/browser
synced 2025-12-14 23:33:31 +00:00
Restrict angular imports (#5597)
* Refactor restricted imports eslint rule, add angular deps * Move FormValidationErrorsService into libs/angular * Remove angular decorators from configService * Remove angular decorator from anonymousHubService
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
import { AbstractControl } from "@angular/forms";
|
||||
export interface AllValidationErrors {
|
||||
controlName: string;
|
||||
errorName: string;
|
||||
}
|
||||
|
||||
export interface FormGroupControls {
|
||||
[key: string]: AbstractControl;
|
||||
}
|
||||
|
||||
export abstract class FormValidationErrorsService {
|
||||
getFormValidationErrors: (controls: FormGroupControls) => AllValidationErrors[];
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import { UntypedFormGroup, ValidationErrors } from "@angular/forms";
|
||||
|
||||
import {
|
||||
FormGroupControls,
|
||||
FormValidationErrorsService as FormValidationErrorsAbstraction,
|
||||
AllValidationErrors,
|
||||
} from "../abstractions/form-validation-errors.service";
|
||||
|
||||
export class FormValidationErrorsService implements FormValidationErrorsAbstraction {
|
||||
getFormValidationErrors(controls: FormGroupControls): AllValidationErrors[] {
|
||||
let errors: AllValidationErrors[] = [];
|
||||
Object.keys(controls).forEach((key) => {
|
||||
const control = controls[key];
|
||||
if (control instanceof UntypedFormGroup) {
|
||||
errors = errors.concat(this.getFormValidationErrors(control.controls));
|
||||
}
|
||||
|
||||
const controlErrors: ValidationErrors = controls[key].errors;
|
||||
if (controlErrors !== null) {
|
||||
Object.keys(controlErrors).forEach((keyError) => {
|
||||
errors.push({
|
||||
controlName: key,
|
||||
errorName: keyError,
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return errors;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user