Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PM-13808 - Use new <bit-form-field> component in Excluded domains settings. #13111

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,46 +14,52 @@
<bit-section *ngIf="!isLoading">
<bit-section-header>
<h2 bitTypography="h6">{{ "domainsTitle" | i18n }}</h2>
<span bitTypography="body2" slot="end">{{ excludedDomainsState?.length || 0 }}</span>
<span bitTypography="body2" slot="end">{{
excludedDomainsState.length + domainForms.value.length
}}</span>
</bit-section-header>

<ng-container *ngIf="excludedDomainsState">
<bit-item
*ngFor="let domain of excludedDomainsState; let i = index; trackBy: trackByFunction"
<bit-item
*ngFor="let domain of excludedDomainsState; let i = index; trackBy: trackByFunction"
>
<bit-item-content *ngIf="i < fieldsEditThreshold">
<div id="excludedDomain{{ 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="excludedDomain{{ i + fieldsEditThreshold }}"
inputmode="url"
name="excludedDomain{{ i }}"
name="excludedDomain{{ i + fieldsEditThreshold }}"
type="text"
(change)="fieldChange()"
[(ngModel)]="excludedDomainsState[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 @@
AfterViewInit,
ViewChildren,
} from "@angular/core";
import { FormsModule } from "@angular/forms";
import {

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

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/autofill/popup/settings/excluded-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 @@ -45,6 +51,7 @@
CommonModule,
FormFieldModule,
FormsModule,
ReactiveFormsModule,
IconButtonModule,
ItemModule,
JslibModule,
Expand All @@ -68,6 +75,11 @@
isLoading = false;
excludedDomainsState: string[] = [];
storedExcludedDomains: string[] = [];

protected domainListForm = new FormGroup({

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

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/autofill/popup/settings/excluded-domains.component.ts#L79

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

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

Expand All @@ -77,10 +89,15 @@
private domainSettingsService: DomainSettingsService,
private i18nService: I18nService,
private toastService: ToastService,
private formBuilder: FormBuilder,

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

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/autofill/popup/settings/excluded-domains.component.ts#L92

Added line #L92 was not covered by tests
) {
this.accountSwitcherEnabled = enableAccountSwitching();
}

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

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

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/autofill/popup/settings/excluded-domains.component.ts#L98

Added line #L98 was not covered by tests
}

async ngAfterViewInit() {
this.domainSettingsService.neverDomains$
.pipe(takeUntil(this.destroy$))
Expand Down Expand Up @@ -117,8 +134,7 @@
}

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

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

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/autofill/popup/settings/excluded-domains.component.ts#L137

Added line #L137 was not covered by tests

await this.fieldChange();
}
Expand Down Expand Up @@ -148,7 +164,11 @@
this.isLoading = true;

const newExcludedDomainsSaveState: NeverDomains = {};
const uniqueExcludedDomains = new Set(this.excludedDomainsState);

const uniqueExcludedDomains = new Set([

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

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/autofill/popup/settings/excluded-domains.component.ts#L168

Added line #L168 was not covered by tests
...this.excludedDomainsState,
...this.domainForms.value,
]);

for (const uri of uniqueExcludedDomains) {
if (uri && uri !== "") {
Expand Down Expand Up @@ -194,13 +214,14 @@
title: "",
variant: "success",
});

this.domainForms.clear();

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

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/autofill/popup/settings/excluded-domains.component.ts#L218

Added line #L218 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
Loading