Skip to content

Commit

Permalink
Address review feedback on UnassignedBannerService (#8680)
Browse files Browse the repository at this point in the history
* Introduce `UnassignedItemsBannerApiService`

* Delete `WebUnassignedItemsBannerService`
  • Loading branch information
addisonbeck committed Apr 11, 2024
1 parent 4e7103f commit c969b43
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 117 deletions.
4 changes: 2 additions & 2 deletions apps/web/src/app/layouts/header/web-header.component.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<bit-banner
class="-tw-m-6 tw-flex tw-flex-col tw-pb-6"
(onClose)="webUnassignedItemsBannerService.hideBanner()"
(onClose)="unassignedItemsBannerService.hideBanner()"
*ngIf="
(unassignedItemsBannerEnabled$ | async) && (webUnassignedItemsBannerService.showBanner$ | async)
(unassignedItemsBannerEnabled$ | async) && (unassignedItemsBannerService.showBanner$ | async)
"
>
{{ "unassignedItemsBanner" | i18n }}
Expand Down
5 changes: 2 additions & 3 deletions apps/web/src/app/layouts/header/web-header.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Component, Input } from "@angular/core";
import { ActivatedRoute } from "@angular/router";
import { combineLatest, map, Observable } from "rxjs";

import { UnassignedItemsBannerService } from "@bitwarden/angular/services/unassigned-items-banner.service";
import { VaultTimeoutSettingsService } from "@bitwarden/common/abstractions/vault-timeout/vault-timeout-settings.service";
import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
import { VaultTimeoutAction } from "@bitwarden/common/enums/vault-timeout-action.enum";
Expand All @@ -11,8 +12,6 @@ import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/pl
import { StateService } from "@bitwarden/common/platform/abstractions/state.service";
import { AccountProfile } from "@bitwarden/common/platform/models/domain/account";

import { WebUnassignedItemsBannerService } from "./web-unassigned-items-banner.service";

@Component({
selector: "app-header",
templateUrl: "./web-header.component.html",
Expand Down Expand Up @@ -43,7 +42,7 @@ export class WebHeaderComponent {
private platformUtilsService: PlatformUtilsService,
private vaultTimeoutSettingsService: VaultTimeoutSettingsService,
private messagingService: MessagingService,
protected webUnassignedItemsBannerService: WebUnassignedItemsBannerService,
protected unassignedItemsBannerService: UnassignedItemsBannerService,
private configService: ConfigServiceAbstraction,
) {
this.routeData$ = this.route.data.pipe(
Expand Down

This file was deleted.

This file was deleted.

19 changes: 19 additions & 0 deletions libs/angular/src/services/unassigned-items-banner.api.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Injectable } from "@angular/core";

import { ApiService } from "@bitwarden/common/abstractions/api.service";

@Injectable({ providedIn: "root" })
export class UnassignedItemsBannerApiService {
constructor(private apiService: ApiService) {}

async getShowUnassignedCiphersBanner(): Promise<boolean> {
const r = await this.apiService.send(
"GET",
"/ciphers/has-unassigned-ciphers",
null,
true,
true,
);
return r;
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { MockProxy, mock } from "jest-mock-extended";
import { firstValueFrom, skip } from "rxjs";

import { ApiService } from "@bitwarden/common/abstractions/api.service";
import { FakeStateProvider, mockAccountServiceWith } from "@bitwarden/common/spec";
import { UserId } from "@bitwarden/common/types/guid";

import { UnassignedItemsBannerApiService } from "./unassigned-items-banner.api.service";
import { SHOW_BANNER_KEY, UnassignedItemsBannerService } from "./unassigned-items-banner.service";

describe("UnassignedItemsBanner", () => {
let stateProvider: FakeStateProvider;
let apiService: MockProxy<ApiService>;
let apiService: MockProxy<UnassignedItemsBannerApiService>;

const sutFactory = () => new UnassignedItemsBannerService(stateProvider, apiService);

Expand Down
5 changes: 3 additions & 2 deletions libs/angular/src/services/unassigned-items-banner.service.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { Injectable } from "@angular/core";
import { EMPTY, concatMap } from "rxjs";

import { ApiService } from "@bitwarden/common/abstractions/api.service";
import {
StateProvider,
UNASSIGNED_ITEMS_BANNER_DISK,
UserKeyDefinition,
} from "@bitwarden/common/platform/state";

import { UnassignedItemsBannerApiService } from "./unassigned-items-banner.api.service";

export const SHOW_BANNER_KEY = new UserKeyDefinition<boolean>(
UNASSIGNED_ITEMS_BANNER_DISK,
"showBanner",
Expand Down Expand Up @@ -37,7 +38,7 @@ export class UnassignedItemsBannerService {

constructor(
private stateProvider: StateProvider,
private apiService: ApiService,
private apiService: UnassignedItemsBannerApiService,
) {}

async hideBanner() {
Expand Down
1 change: 0 additions & 1 deletion libs/common/src/abstractions/api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ export abstract class ApiService {
emergencyAccessId?: string,
) => Promise<AttachmentResponse>;
getCiphersOrganization: (organizationId: string) => Promise<ListResponse<CipherResponse>>;
getShowUnassignedCiphersBanner: () => Promise<boolean>;
postCipher: (request: CipherRequest) => Promise<CipherResponse>;
postCipherCreate: (request: CipherCreateRequest) => Promise<CipherResponse>;
postCipherAdmin: (request: CipherCreateRequest) => Promise<CipherResponse>;
Expand Down
5 changes: 0 additions & 5 deletions libs/common/src/services/api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -506,11 +506,6 @@ export class ApiService implements ApiServiceAbstraction {
return new ListResponse(r, CipherResponse);
}

async getShowUnassignedCiphersBanner(): Promise<boolean> {
const r = await this.send("GET", "/ciphers/has-unassigned-ciphers", null, true, true);
return r;
}

async postCipher(request: CipherRequest): Promise<CipherResponse> {
const r = await this.send("POST", "/ciphers", request, true, true);
return new CipherResponse(r);
Expand Down

0 comments on commit c969b43

Please sign in to comment.