From 906a280620ed1931b3393eed7f87b7fedacecd11 Mon Sep 17 00:00:00 2001 From: Brandon Date: Thu, 23 Jan 2025 21:22:51 -0500 Subject: [PATCH] remove nested pipes, cleanup --- .../services/free-families-policy.service.ts | 20 ++++++------- .../settings/sponsoring-org-row.component.ts | 28 +++++++++---------- .../src/tools/send/add-edit.component.ts | 7 ++--- .../options/send-options.component.ts | 10 +++---- 4 files changed, 31 insertions(+), 34 deletions(-) diff --git a/apps/web/src/app/billing/services/free-families-policy.service.ts b/apps/web/src/app/billing/services/free-families-policy.service.ts index c845b9924a9..b07ccefdbab 100644 --- a/apps/web/src/app/billing/services/free-families-policy.service.ts +++ b/apps/web/src/app/billing/services/free-families-policy.service.ts @@ -111,18 +111,18 @@ export class FreeFamiliesPolicyService { }); } - return getUserId(this.accountService.activeAccount$).pipe( + return this.accountService.activeAccount$.pipe( + getUserId, switchMap((userId) => - this.policyService.getAll$(PolicyType.FreeFamiliesSponsorshipPolicy, userId).pipe( - map((policies) => ({ - isFreeFamilyPolicyEnabled: policies.some( - (policy) => policy.organizationId === organizationId && policy.enabled, - ), - belongToOneEnterpriseOrgs, - belongToMultipleEnterpriseOrgs, - })), - ), + this.policyService.getAll$(PolicyType.FreeFamiliesSponsorshipPolicy, userId), ), + map((policies) => ({ + isFreeFamilyPolicyEnabled: policies.some( + (policy) => policy.organizationId === organizationId && policy.enabled, + ), + belongToOneEnterpriseOrgs, + belongToMultipleEnterpriseOrgs, + })), ); } diff --git a/apps/web/src/app/billing/settings/sponsoring-org-row.component.ts b/apps/web/src/app/billing/settings/sponsoring-org-row.component.ts index de07232b6d5..6e9e00b0ee1 100644 --- a/apps/web/src/app/billing/settings/sponsoring-org-row.component.ts +++ b/apps/web/src/app/billing/settings/sponsoring-org-row.component.ts @@ -2,7 +2,7 @@ // @ts-strict-ignore import { formatDate } from "@angular/common"; import { Component, EventEmitter, Input, Output, OnInit } from "@angular/core"; -import { firstValueFrom, map, Observable } from "rxjs"; +import { firstValueFrom, map, Observable, switchMap } from "rxjs"; import { ApiService } from "@bitwarden/common/abstractions/api.service"; import { PolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction"; @@ -56,20 +56,20 @@ export class SponsoringOrgRowComponent implements OnInit { FeatureFlag.DisableFreeFamiliesSponsorship, ); - const userId = await firstValueFrom(getUserId(this.accountService.activeAccount$)); - if (this.isFreeFamilyFlagEnabled) { - this.isFreeFamilyPolicyEnabled$ = this.policyService - .getAll$(PolicyType.FreeFamiliesSponsorshipPolicy, userId) - .pipe( - map( - (policies) => - Array.isArray(policies) && - policies.some( - (policy) => policy.organizationId === this.sponsoringOrg.id && policy.enabled, - ), - ), - ); + this.isFreeFamilyPolicyEnabled$ = this.accountService.activeAccount$.pipe( + getUserId, + switchMap((userId) => + this.policyService.getAll$(PolicyType.FreeFamiliesSponsorshipPolicy, userId), + ), + map( + (policies) => + Array.isArray(policies) && + policies.some( + (policy) => policy.organizationId === this.sponsoringOrg.id && policy.enabled, + ), + ), + ); } } diff --git a/libs/angular/src/tools/send/add-edit.component.ts b/libs/angular/src/tools/send/add-edit.component.ts index 3ae40781949..4f7d4b6b600 100644 --- a/libs/angular/src/tools/send/add-edit.component.ts +++ b/libs/angular/src/tools/send/add-edit.component.ts @@ -165,11 +165,10 @@ export class AddEditComponent implements OnInit, OnDestroy { } }); - const userId = await firstValueFrom(getUserId(this.accountService.activeAccount$)); - - this.policyService - .getAll$(PolicyType.SendOptions, userId) + this.accountService.activeAccount$ .pipe( + getUserId, + switchMap((userId) => this.policyService.getAll$(PolicyType.SendOptions, userId)), map((policies) => policies?.some((p) => p.data.disableHideEmail)), takeUntil(this.destroy$), ) diff --git a/libs/tools/send/send-ui/src/send-form/components/options/send-options.component.ts b/libs/tools/send/send-ui/src/send-form/components/options/send-options.component.ts index fa124bc60dd..22f1deb2fac 100644 --- a/libs/tools/send/send-ui/src/send-form/components/options/send-options.component.ts +++ b/libs/tools/send/send-ui/src/send-form/components/options/send-options.component.ts @@ -95,14 +95,12 @@ export class SendOptionsComponent implements OnInit { ) { this.sendFormContainer.registerChildForm("sendOptionsForm", this.sendOptionsForm); - getUserId(this.accountService.activeAccount$) + this.accountService.activeAccount$ .pipe( + getUserId, + switchMap((userId) => this.policyService.getAll$(PolicyType.SendOptions, userId)), + map((policies) => policies?.some((p) => p.data.disableHideEmail)), takeUntilDestroyed(), - switchMap((userId) => - this.policyService - .getAll$(PolicyType.SendOptions, userId) - .pipe(map((policies) => policies?.some((p) => p.data.disableHideEmail))), - ), ) .subscribe((disableHideEmail) => { this.disableHideEmail = disableHideEmail;