Skip to content

Commit

Permalink
update search state to show contextual no results view messages
Browse files Browse the repository at this point in the history
  • Loading branch information
jprusik committed Oct 15, 2024
1 parent 32d12b3 commit 93c8864
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 16 deletions.
26 changes: 18 additions & 8 deletions apps/browser/src/autofill/popup/fido2/fido2.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,22 @@ <h2 bitTypography="h6">{{ "chooseCipherForPasskeySave" | i18n }}</h2>
<!-- Display when no matching ciphers exist -->
<ng-container *ngIf="!displayedCiphers.length">
<bit-no-items class="tw-text-main" [icon]="noResultsIcon">
<ng-container slot="title">{{ "noMatchingLoginsForSite" | i18n }}</ng-container>
<ng-container slot="description">{{ "searchSavePasskeyNewLogin" | i18n }}</ng-container>
<ng-container slot="title">{{
(hasSearched ? "noItemsMatchSearch" : "noMatchingLoginsForSite") | i18n
}}</ng-container>
<ng-container slot="description">{{
(hasSearched ? "searchSavePasskeyNewLogin" : "clearFiltersOrTryAnother") | i18n
}}</ng-container>

<button
bitButton
buttonType="primary"
slot="button"
type="button"
(click)="saveNewLogin()"
(click)="hasSearched ? clearSearch() : saveNewLogin()"
[loading]="loading"
>
{{ "savePasskeyNewLogin" | i18n }}
{{ (hasSearched ? "multiSelectClearAll" : "savePasskeyNewLogin") | i18n }}
</button>
</bit-no-items>
</ng-container>
Expand Down Expand Up @@ -100,17 +105,22 @@ <h2 bitTypography="h6">{{ "chooseCipherForPasskeySave" | i18n }}</h2>
<!-- Display when no matching ciphers exist -->
<ng-container *ngIf="!displayedCiphers.length">
<bit-no-items class="tw-text-main" [icon]="noResultsIcon">
<ng-container slot="title">{{ "noItemsMatchSearch" | i18n }}</ng-container>
<ng-container slot="description">{{ "clearFiltersOrTryAnother" | i18n }}</ng-container>
<ng-container slot="title">{{
(hasSearched ? "noItemsMatchSearch" : "noMatchingLoginsForSite") | i18n
}}</ng-container>
<ng-container slot="description">{{
(hasSearched ? "searchSavePasskeyNewLogin" : "clearFiltersOrTryAnother") | i18n
}}</ng-container>

<button
bitButton
buttonType="primary"
slot="button"
type="button"
(click)="saveNewLogin()"
(click)="hasSearched ? clearSearch() : saveNewLogin()"
[loading]="loading"
>
{{ "savePasskeyNewLogin" | i18n }}
{{ (hasSearched ? "multiSelectClearAll" : "savePasskeyNewLogin") | i18n }}
</button>
</bit-no-items>
</ng-container>
Expand Down
27 changes: 19 additions & 8 deletions apps/browser/src/autofill/popup/fido2/fido2.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ interface ViewData {
export class Fido2Component implements OnInit, OnDestroy {
private destroy$ = new Subject<void>();
private message$ = new BehaviorSubject<BrowserFido2Message>(null);
private hasSearched = false;
protected BrowserFido2MessageTypes = BrowserFido2MessageTypes;
protected cipher: CipherView;
protected ciphers?: CipherView[] = [];
Expand All @@ -104,7 +103,8 @@ export class Fido2Component implements OnInit, OnDestroy {
protected noResultsIcon = Icons.NoResults;
protected passkeyAction: PasskeyActionValue = PasskeyActions.Register;
protected PasskeyActions = PasskeyActions;
protected searchText: string;
protected hasSearched = false;
protected searchText: string = null;

Check warning on line 107 in apps/browser/src/autofill/popup/fido2/fido2.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/autofill/popup/fido2/fido2.component.ts#L106-L107

Added lines #L106 - L107 were not covered by tests
protected searchTypeSearch = false;
protected senderTabId?: string;
protected sessionId?: string;
Expand Down Expand Up @@ -370,19 +370,30 @@ export class Fido2Component implements OnInit, OnDestroy {
return this.equivalentDomains;
}

async clearSearch() {
this.searchText = "";
await this.setDisplayedCiphersToAllDomainMatch();

Check warning on line 375 in apps/browser/src/autofill/popup/fido2/fido2.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/autofill/popup/fido2/fido2.component.ts#L374-L375

Added lines #L374 - L375 were not covered by tests
}

protected async setDisplayedCiphersToAllDomainMatch() {
const equivalentDomains = await this.getEquivalentDomains();
this.displayedCiphers = this.ciphers.filter((cipher) =>
cipher.login.matchesUri(this.url, equivalentDomains),

Check warning on line 381 in apps/browser/src/autofill/popup/fido2/fido2.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/autofill/popup/fido2/fido2.component.ts#L379-L381

Added lines #L379 - L381 were not covered by tests
);
}

protected async search() {
this.hasSearched = await this.searchService.isSearchable(this.searchText);
if (this.hasSearched) {
this.hasSearched = true;
const isSearchable = await this.searchService.isSearchable(this.searchText);

Check warning on line 387 in apps/browser/src/autofill/popup/fido2/fido2.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/autofill/popup/fido2/fido2.component.ts#L386-L387

Added lines #L386 - L387 were not covered by tests

if (isSearchable) {
this.displayedCiphers = await this.searchService.searchCiphers(
this.searchText,
null,
this.ciphers,
);
} else {
const equivalentDomains = await this.getEquivalentDomains();
this.displayedCiphers = this.ciphers.filter((cipher) =>
cipher.login.matchesUri(this.url, equivalentDomains),
);
await this.setDisplayedCiphersToAllDomainMatch();

Check warning on line 396 in apps/browser/src/autofill/popup/fido2/fido2.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/autofill/popup/fido2/fido2.component.ts#L396

Added line #L396 was not covered by tests
}
}

Expand Down

0 comments on commit 93c8864

Please sign in to comment.