From 23ef1b16886897c094cdcd1e97380d386f5168dd Mon Sep 17 00:00:00 2001 From: Miles Blackwood Date: Wed, 19 Feb 2025 17:11:40 -0500 Subject: [PATCH] PM-13808 - Use new component in Excluded domains settings. (#13111) * Use new component in Excluded domains settings. Changing to new component necessitates modifying form to use ReactiveForms conventions. To handle this change, the deletable/uneditable domain state and new form control state are managed separately, including clearing the form state on save. Fields which compute vaules from the former state should now compute both values (see domain count); [formGroup], formArrayName, formControlName all necessary directives/properties on form and children. * Disables margin; Removes OnInit in favor of protected member (fixes lint, and type checks). * Ensure excludedDomain-based IDs are offset by the fieldsEditThreshold for form controls existing outside of stored values. * Remove unnecessary chaining. --- .../settings/excluded-domains.component.html | 66 ++++++++++--------- .../settings/excluded-domains.component.ts | 31 +++++++-- 2 files changed, 62 insertions(+), 35 deletions(-) diff --git a/apps/browser/src/autofill/popup/settings/excluded-domains.component.html b/apps/browser/src/autofill/popup/settings/excluded-domains.component.html index e3b6bf5f802..92abef3730c 100644 --- a/apps/browser/src/autofill/popup/settings/excluded-domains.component.html +++ b/apps/browser/src/autofill/popup/settings/excluded-domains.component.html @@ -14,46 +14,52 @@

{{ "domainsTitle" | i18n }}

- {{ excludedDomainsState?.length || 0 }} + {{ + excludedDomainsState.length + domainForms.value.length + }}
- - - + +
{{ domain }}
+
+ +
+
+ - - {{ - "websiteItemLabel" | i18n: i + 1 - }} + + {{ "websiteItemLabel" | i18n: i + fieldsEditThreshold + 1 }} -
{{ domain }}
-
- - - - + +
+ +
diff --git a/apps/browser/src/autofill/popup/settings/excluded-domains.component.ts b/apps/browser/src/autofill/popup/settings/excluded-domains.component.ts index 7d429bfe4f0..0447d8076c2 100644 --- a/apps/browser/src/autofill/popup/settings/excluded-domains.component.ts +++ b/apps/browser/src/autofill/popup/settings/excluded-domains.component.ts @@ -7,7 +7,13 @@ import { AfterViewInit, ViewChildren, } from "@angular/core"; -import { FormsModule } from "@angular/forms"; +import { + FormsModule, + ReactiveFormsModule, + FormBuilder, + FormGroup, + FormArray, +} from "@angular/forms"; import { RouterModule } from "@angular/router"; import { Subject, takeUntil } from "rxjs"; @@ -45,6 +51,7 @@ import { PopupPageComponent } from "../../../platform/popup/layout/popup-page.co CommonModule, FormFieldModule, FormsModule, + ReactiveFormsModule, IconButtonModule, ItemModule, JslibModule, @@ -68,6 +75,11 @@ export class ExcludedDomainsComponent implements AfterViewInit, OnDestroy { isLoading = false; excludedDomainsState: string[] = []; storedExcludedDomains: string[] = []; + + protected domainListForm = new FormGroup({ + domains: this.formBuilder.array([]), + }); + // How many fields should be non-editable before editable fields fieldsEditThreshold: number = 0; @@ -77,10 +89,15 @@ export class ExcludedDomainsComponent implements AfterViewInit, OnDestroy { private domainSettingsService: DomainSettingsService, private i18nService: I18nService, private toastService: ToastService, + private formBuilder: FormBuilder, ) { this.accountSwitcherEnabled = enableAccountSwitching(); } + get domainForms() { + return this.domainListForm.get("domains") as FormArray; + } + async ngAfterViewInit() { this.domainSettingsService.neverDomains$ .pipe(takeUntil(this.destroy$)) @@ -117,8 +134,7 @@ export class ExcludedDomainsComponent implements AfterViewInit, OnDestroy { } async addNewDomain() { - // add empty field to the Domains list interface - this.excludedDomainsState.push(""); + this.domainForms.push(this.formBuilder.control(null)); await this.fieldChange(); } @@ -148,7 +164,11 @@ export class ExcludedDomainsComponent implements AfterViewInit, OnDestroy { this.isLoading = true; const newExcludedDomainsSaveState: NeverDomains = {}; - const uniqueExcludedDomains = new Set(this.excludedDomainsState); + + const uniqueExcludedDomains = new Set([ + ...this.excludedDomainsState, + ...this.domainForms.value, + ]); for (const uri of uniqueExcludedDomains) { if (uri && uri !== "") { @@ -194,13 +214,14 @@ export class ExcludedDomainsComponent implements AfterViewInit, OnDestroy { title: "", variant: "success", }); + + this.domainForms.clear(); } catch { this.toastService.showToast({ message: this.i18nService.t("unexpectedError"), title: "", variant: "error", }); - // Don't reset via `handleStateUpdate` to preserve input values this.isLoading = false; }