Skip to content

Commit

Permalink
[PM-17819] Replicate ReactiveForms and bit-* component changes to Blo…
Browse files Browse the repository at this point in the history
…cked Domains from Excluded Domains update [PM-13808].
  • Loading branch information
blackwood committed Jan 31, 2025
1 parent 3b8b9c9 commit 7751686
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,46 +10,50 @@
<bit-section *ngIf="!isLoading">
<bit-section-header>
<h2 bitTypography="h6">{{ "domainsTitle" | i18n }}</h2>
<span bitTypography="body2" slot="end">{{ blockedDomainsState?.length || 0 }}</span>
<span bitTypography="body2" slot="end">{{
blockedDomainsState.length + domainForms.value.length
}}</span>
</bit-section-header>

<ng-container *ngIf="blockedDomainsState">
<bit-item
*ngFor="let domain of blockedDomainsState; let i = index; trackBy: trackByFunction"
<bit-item *ngFor="let domain of blockedDomainsState; let i = index; trackBy: trackByFunction">
<bit-item-content *ngIf="i < fieldsEditThreshold">
<div id="blockedDomain{{ i }}">{{ domain }}</div>
</bit-item-content>
<button
*ngIf="i < fieldsEditThreshold"
appA11yTitle="{{ 'remove' | i18n }}"
bitIconButton="bwi-minus-circle"
buttonType="danger"
size="small"
slot="end"
type="button"
(click)="removeDomain(i)"
></button>
</bit-item>
<form [formGroup]="domainListForm">
<bit-card
formArrayName="domains"
*ngFor="let domain of domainForms.controls; let i = index"
>
<bit-item-content>
<bit-label *ngIf="i >= fieldsEditThreshold">{{
"websiteItemLabel" | i18n: i + 1
}}</bit-label>
<bit-form-field disableMargin>
<bit-label>{{ "websiteItemLabel" | i18n: i + fieldsEditThreshold + 1 }}</bit-label>
<input
*ngIf="i >= fieldsEditThreshold"
bitInput
#uriInput
appInputVerbatim
bitInput
id="excludedDomain{{ i }}"
id="blockedDomain{{ i + fieldsEditThreshold }}"
inputmode="url"
name="excludedDomain{{ i }}"
name="blockedDomain{{ i + fieldsEditThreshold }}"
type="text"
(change)="fieldChange()"
[(ngModel)]="blockedDomainsState[i]"
formControlName="{{ i }}"
/>
<div id="excludedDomain{{ i }}" *ngIf="i < fieldsEditThreshold">{{ domain }}</div>
</bit-item-content>
<button
*ngIf="i < fieldsEditThreshold"
appA11yTitle="{{ 'remove' | i18n }}"
bitIconButton="bwi-minus-circle"
buttonType="danger"
size="small"
slot="end"
type="button"
(click)="removeDomain(i)"
></button>
</bit-item>
</ng-container>
<button bitLink class="tw-pt-2" type="button" linkType="primary" (click)="addNewDomain()">
<i class="bwi bwi-plus-circle bwi-fw" aria-hidden="true"></i> {{ "addDomain" | i18n }}
</button>
</bit-form-field>
</bit-card>
<button bitLink class="tw-pt-2" type="button" linkType="primary" (click)="addNewDomain()">
<i class="bwi bwi-plus-circle bwi-fw" aria-hidden="true"></i> {{ "addDomain" | i18n }}
</button>
</form>
</bit-section>
</div>
<popup-footer slot="footer">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ import {
AfterViewInit,
ViewChildren,
} from "@angular/core";
import { FormsModule } from "@angular/forms";
import {

Check warning on line 10 in apps/browser/src/autofill/popup/settings/blocked-domains.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/autofill/popup/settings/blocked-domains.component.ts#L10

Added line #L10 was not covered by tests
FormsModule,
ReactiveFormsModule,
FormBuilder,
FormGroup,
FormArray,
} from "@angular/forms";
import { RouterModule } from "@angular/router";
import { Subject, takeUntil } from "rxjs";

Expand Down Expand Up @@ -44,6 +50,7 @@ import { PopupPageComponent } from "../../../platform/popup/layout/popup-page.co
CommonModule,
FormFieldModule,
FormsModule,
ReactiveFormsModule,
IconButtonModule,
ItemModule,
JslibModule,
Expand All @@ -66,6 +73,11 @@ export class BlockedDomainsComponent implements AfterViewInit, OnDestroy {
isLoading = false;
blockedDomainsState: string[] = [];
storedBlockedDomains: string[] = [];

protected domainListForm = new FormGroup({

Check warning on line 77 in apps/browser/src/autofill/popup/settings/blocked-domains.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/autofill/popup/settings/blocked-domains.component.ts#L77

Added line #L77 was not covered by tests
domains: this.formBuilder.array([]),
});

// How many fields should be non-editable before editable fields
fieldsEditThreshold: number = 0;

Expand All @@ -75,8 +87,13 @@ export class BlockedDomainsComponent implements AfterViewInit, OnDestroy {
private domainSettingsService: DomainSettingsService,
private i18nService: I18nService,
private toastService: ToastService,
private formBuilder: FormBuilder,

Check warning on line 90 in apps/browser/src/autofill/popup/settings/blocked-domains.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/autofill/popup/settings/blocked-domains.component.ts#L90

Added line #L90 was not covered by tests
) {}

get domainForms() {
return this.domainListForm.get("domains") as FormArray;

Check warning on line 94 in apps/browser/src/autofill/popup/settings/blocked-domains.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/autofill/popup/settings/blocked-domains.component.ts#L94

Added line #L94 was not covered by tests
}

async ngAfterViewInit() {
this.domainSettingsService.blockedInteractionsUris$
.pipe(takeUntil(this.destroy$))
Expand Down Expand Up @@ -113,8 +130,7 @@ export class BlockedDomainsComponent implements AfterViewInit, OnDestroy {
}

async addNewDomain() {
// add empty field to the Domains list interface
this.blockedDomainsState.push("");
this.domainForms.push(this.formBuilder.control(null));

Check warning on line 133 in apps/browser/src/autofill/popup/settings/blocked-domains.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/autofill/popup/settings/blocked-domains.component.ts#L133

Added line #L133 was not covered by tests

await this.fieldChange();
}
Expand Down Expand Up @@ -144,15 +160,16 @@ export class BlockedDomainsComponent implements AfterViewInit, OnDestroy {
this.isLoading = true;

const newBlockedDomainsSaveState: NeverDomains = {};
const uniqueBlockedDomains = new Set(this.blockedDomainsState);

const uniqueBlockedDomains = new Set([...this.blockedDomainsState, ...this.domainForms.value]);

Check warning on line 164 in apps/browser/src/autofill/popup/settings/blocked-domains.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/autofill/popup/settings/blocked-domains.component.ts#L164

Added line #L164 was not covered by tests

for (const uri of uniqueBlockedDomains) {
if (uri && uri !== "") {
const validatedHost = Utils.getHostname(uri);

if (!validatedHost) {
this.toastService.showToast({
message: this.i18nService.t("excludedDomainsInvalidDomain", uri),
message: this.i18nService.t("blockedDomainsInvalidDomain", uri),
title: "",
variant: "error",
});
Expand Down Expand Up @@ -190,13 +207,14 @@ export class BlockedDomainsComponent implements AfterViewInit, OnDestroy {
title: "",
variant: "success",
});

this.domainForms.clear();

Check warning on line 211 in apps/browser/src/autofill/popup/settings/blocked-domains.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/autofill/popup/settings/blocked-domains.component.ts#L211

Added line #L211 was not covered by tests
} catch {
this.toastService.showToast({
message: this.i18nService.t("unexpectedError"),
title: "",
variant: "error",
});

// Don't reset via `handleStateUpdate` to preserve input values
this.isLoading = false;
}
Expand Down

0 comments on commit 7751686

Please sign in to comment.