Skip to content

Commit

Permalink
[AC-2436] Fix flashing unassigned items banner (#8689)
Browse files Browse the repository at this point in the history
* Fix flashing banner for users who shouldn't see it

* Emit the right value the first time

* simplify further

* restore comment

(cherry picked from commit b843aa6)
  • Loading branch information
eliykat authored and addisonbeck committed Apr 11, 2024
1 parent c969b43 commit e47f46a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { MockProxy, mock } from "jest-mock-extended";
import { firstValueFrom, skip } from "rxjs";
import { firstValueFrom } from "rxjs";

import { FakeStateProvider, mockAccountServiceWith } from "@bitwarden/common/spec";
import { UserId } from "@bitwarden/common/types/guid";
Expand Down Expand Up @@ -44,10 +44,8 @@ describe("UnassignedItemsBanner", () => {
showBanner.nextState(undefined);

const sut = sutFactory();
// skip first value so we get the recomputed value after the server call
expect(await firstValueFrom(sut.showBanner$.pipe(skip(1)))).toBe(true);
// Expect to have updated local state
expect(await firstValueFrom(showBanner.state$)).toBe(true);

expect(await firstValueFrom(sut.showBanner$)).toBe(true);
expect(apiService.getShowUnassignedCiphersBanner).toHaveBeenCalledTimes(1);
});
});
10 changes: 5 additions & 5 deletions libs/angular/src/services/unassigned-items-banner.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable } from "@angular/core";
import { EMPTY, concatMap } from "rxjs";
import { concatMap } from "rxjs";

import {
StateProvider,
Expand All @@ -24,15 +24,15 @@ export class UnassignedItemsBannerService {
private _showBanner = this.stateProvider.getActive(SHOW_BANNER_KEY);

showBanner$ = this._showBanner.state$.pipe(
concatMap(async (showBanner) => {
concatMap(async (showBannerState) => {
// null indicates that the user has not seen or dismissed the banner yet - get the flag from server
if (showBanner == null) {
if (showBannerState == null) {
const showBannerResponse = await this.apiService.getShowUnassignedCiphersBanner();
await this._showBanner.update(() => showBannerResponse);
return EMPTY; // complete the inner observable without emitting any value; the update on the previous line will trigger another run
return showBannerResponse;
}

return showBanner;
return showBannerState;
}),
);

Expand Down

0 comments on commit e47f46a

Please sign in to comment.