1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-10 13:23:34 +00:00

[PM-6194] Refactor injection of services in browser services module (#8380)

* refactored injector of services on the browser service module

* refactored the search and popup serach service to use state provider

* renamed back to default

* removed token service that was readded during merge conflict

* Updated search service construction on the cli

* updated to use user key definition

* Reafctored all components that refernce issearchable

* removed commented variable

* added uncommited code to remove dependencies not needed anymore

* added uncommited code to remove dependencies not needed anymore
This commit is contained in:
SmithThe4th
2024-04-10 14:02:46 +01:00
committed by GitHub
parent 560033cb88
commit 2bce6c538c
30 changed files with 393 additions and 182 deletions

View File

@@ -726,7 +726,7 @@ const safeProviders: SafeProvider[] = [
safeProvider({
provide: SearchServiceAbstraction,
useClass: SearchService,
deps: [LogService, I18nServiceAbstraction],
deps: [LogService, I18nServiceAbstraction, StateProvider],
}),
safeProvider({
provide: NotificationsServiceAbstraction,

View File

@@ -1,5 +1,13 @@
import { Directive, NgZone, OnDestroy, OnInit } from "@angular/core";
import { Subject, firstValueFrom, mergeMap, takeUntil } from "rxjs";
import {
BehaviorSubject,
Subject,
firstValueFrom,
mergeMap,
from,
switchMap,
takeUntil,
} from "rxjs";
import { SearchService } from "@bitwarden/common/abstractions/search.service";
import { PolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction";
@@ -24,7 +32,6 @@ export class SendComponent implements OnInit, OnDestroy {
expired = false;
type: SendType = null;
sends: SendView[] = [];
searchText: string;
selectedType: SendType;
selectedAll: boolean;
filter: (cipher: SendView) => boolean;
@@ -39,6 +46,8 @@ export class SendComponent implements OnInit, OnDestroy {
private searchTimeout: any;
private destroy$ = new Subject<void>();
private _filteredSends: SendView[];
private _searchText$ = new BehaviorSubject<string>("");
protected isSearchable: boolean = false;
get filteredSends(): SendView[] {
return this._filteredSends;
@@ -48,6 +57,14 @@ export class SendComponent implements OnInit, OnDestroy {
this._filteredSends = filteredSends;
}
get searchText() {
return this._searchText$.value;
}
set searchText(value: string) {
this._searchText$.next(value);
}
constructor(
protected sendService: SendService,
protected i18nService: I18nService,
@@ -68,6 +85,15 @@ export class SendComponent implements OnInit, OnDestroy {
.subscribe((policyAppliesToActiveUser) => {
this.disableSend = policyAppliesToActiveUser;
});
this._searchText$
.pipe(
switchMap((searchText) => from(this.searchService.isSearchable(searchText))),
takeUntil(this.destroy$),
)
.subscribe((isSearchable) => {
this.isSearchable = isSearchable;
});
}
ngOnDestroy() {
@@ -122,14 +148,14 @@ export class SendComponent implements OnInit, OnDestroy {
clearTimeout(this.searchTimeout);
}
if (timeout == null) {
this.hasSearched = this.searchService.isSearchable(this.searchText);
this.hasSearched = this.isSearchable;
this.filteredSends = this.sends.filter((s) => this.filter == null || this.filter(s));
this.applyTextSearch();
return;
}
this.searchPending = true;
this.searchTimeout = setTimeout(async () => {
this.hasSearched = this.searchService.isSearchable(this.searchText);
this.hasSearched = this.isSearchable;
this.filteredSends = this.sends.filter((s) => this.filter == null || this.filter(s));
this.applyTextSearch();
this.searchPending = false;

View File

@@ -1,4 +1,5 @@
import { Directive, EventEmitter, Input, Output } from "@angular/core";
import { Directive, EventEmitter, Input, OnDestroy, OnInit, Output } from "@angular/core";
import { BehaviorSubject, Subject, from, switchMap, takeUntil } from "rxjs";
import { SearchService } from "@bitwarden/common/abstractions/search.service";
import { Organization } from "@bitwarden/common/admin-console/models/domain/organization";
@@ -6,7 +7,7 @@ import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.servi
import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view";
@Directive()
export class VaultItemsComponent {
export class VaultItemsComponent implements OnInit, OnDestroy {
@Input() activeCipherId: string = null;
@Output() onCipherClicked = new EventEmitter<CipherView>();
@Output() onCipherRightClicked = new EventEmitter<CipherView>();
@@ -23,13 +24,15 @@ export class VaultItemsComponent {
protected searchPending = false;
private destroy$ = new Subject<void>();
private searchTimeout: any = null;
private _searchText: string = null;
private isSearchable: boolean = false;
private _searchText$ = new BehaviorSubject<string>("");
get searchText() {
return this._searchText;
return this._searchText$.value;
}
set searchText(value: string) {
this._searchText = value;
this._searchText$.next(value);
}
constructor(
@@ -37,6 +40,21 @@ export class VaultItemsComponent {
protected cipherService: CipherService,
) {}
ngOnInit(): void {
this._searchText$
.pipe(
switchMap((searchText) => from(this.searchService.isSearchable(searchText))),
takeUntil(this.destroy$),
)
.subscribe((isSearchable) => {
this.isSearchable = isSearchable;
});
}
ngOnDestroy(): void {
throw new Error("Method not implemented.");
}
async load(filter: (cipher: CipherView) => boolean = null, deleted = false) {
this.deleted = deleted ?? false;
await this.applyFilter(filter);
@@ -90,7 +108,7 @@ export class VaultItemsComponent {
}
isSearching() {
return !this.searchPending && this.searchService.isSearchable(this.searchText);
return !this.searchPending && this.isSearchable;
}
protected deletedFilter: (cipher: CipherView) => boolean = (c) => c.isDeleted === this.deleted;