remove user match strategy on the web (#11385)

This commit is contained in:
Nick Krantz 2024-10-08 10:53:20 -05:00 committed by GitHub
parent 2c8f09d547
commit 22b16b20a7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 24 additions and 2 deletions

View File

@ -7,6 +7,7 @@ import { AutofillSettingsServiceAbstraction } from "@bitwarden/common/autofill/s
import { DomainSettingsService } from "@bitwarden/common/autofill/services/domain-settings.service";
import { UriMatchStrategy } from "@bitwarden/common/models/domain/domain-service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view";
import { LoginUriView } from "@bitwarden/common/vault/models/view/login-uri.view";
import { LoginView } from "@bitwarden/common/vault/models/view/login.view";
@ -23,10 +24,12 @@ describe("AutofillOptionsComponent", () => {
let liveAnnouncer: MockProxy<LiveAnnouncer>;
let domainSettingsService: MockProxy<DomainSettingsService>;
let autofillSettingsService: MockProxy<AutofillSettingsServiceAbstraction>;
let platformUtilsService: MockProxy<PlatformUtilsService>;
beforeEach(async () => {
cipherFormContainer = mock<CipherFormContainer>();
liveAnnouncer = mock<LiveAnnouncer>();
platformUtilsService = mock<PlatformUtilsService>();
domainSettingsService = mock<DomainSettingsService>();
domainSettingsService.defaultUriMatchStrategy$ = new BehaviorSubject(null);
@ -45,6 +48,7 @@ describe("AutofillOptionsComponent", () => {
{ provide: LiveAnnouncer, useValue: liveAnnouncer },
{ provide: DomainSettingsService, useValue: domainSettingsService },
{ provide: AutofillSettingsServiceAbstraction, useValue: autofillSettingsService },
{ provide: PlatformUtilsService, useValue: platformUtilsService },
],
}).compileComponents();

View File

@ -3,13 +3,15 @@ import { AsyncPipe, NgForOf, NgIf } from "@angular/common";
import { Component, OnInit, QueryList, ViewChildren } from "@angular/core";
import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
import { FormBuilder, ReactiveFormsModule } from "@angular/forms";
import { Subject, switchMap, take } from "rxjs";
import { filter, Subject, switchMap, take } from "rxjs";
import { JslibModule } from "@bitwarden/angular/jslib.module";
import { AutofillSettingsServiceAbstraction } from "@bitwarden/common/autofill/services/autofill-settings.service";
import { DomainSettingsService } from "@bitwarden/common/autofill/services/domain-settings.service";
import { ClientType } from "@bitwarden/common/enums";
import { UriMatchStrategySetting } from "@bitwarden/common/models/domain/domain-service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { LoginUriView } from "@bitwarden/common/vault/models/view/login-uri.view";
import { LoginView } from "@bitwarden/common/vault/models/view/login.view";
import {
@ -69,7 +71,10 @@ export class AutofillOptionsComponent implements OnInit {
return this.autofillOptionsForm.controls.uris.controls;
}
protected defaultMatchDetection$ = this.domainSettingsService.defaultUriMatchStrategy$;
protected defaultMatchDetection$ = this.domainSettingsService.defaultUriMatchStrategy$.pipe(
// The default match detection should only be shown when used on the browser
filter(() => this.platformUtilsService.getClientType() == ClientType.Browser),
);
protected autofillOnPageLoadEnabled$ = this.autofillSettingsService.autofillOnPageLoad$;
protected autofillOptions: { label: string; value: boolean | null }[] = [
@ -90,6 +95,7 @@ export class AutofillOptionsComponent implements OnInit {
private liveAnnouncer: LiveAnnouncer,
private domainSettingsService: DomainSettingsService,
private autofillSettingsService: AutofillSettingsServiceAbstraction,
private platformUtilsService: PlatformUtilsService,
) {
this.cipherFormContainer.registerChildForm("autoFillOptions", this.autofillOptionsForm);

View File

@ -51,6 +51,13 @@ describe("UriOptionComponent", () => {
expect(component).toBeTruthy();
});
it("should not update the default uri match strategy label when it is null", () => {
component.defaultMatchDetection = null;
fixture.detectChanges();
expect(component["uriMatchOptions"][0].label).toBe("default");
});
it("should update the default uri match strategy label", () => {
component.defaultMatchDetection = UriMatchStrategy.Exact;
fixture.detectChanges();

View File

@ -83,6 +83,11 @@ export class UriOptionComponent implements ControlValueAccessor {
*/
@Input({ required: true })
set defaultMatchDetection(value: UriMatchStrategySetting) {
// The default selection has a value of `null` avoid showing "Default (Default)"
if (!value) {
return;
}
this.uriMatchOptions[0].label = this.i18nService.t(
"defaultLabel",
this.uriMatchOptions.find((o) => o.value === value)?.label,