Skip to content

Commit 906a280

Browse files
committed
remove nested pipes, cleanup
1 parent 0b3bb89 commit 906a280

File tree

4 files changed

+31
-34
lines changed

4 files changed

+31
-34
lines changed

apps/web/src/app/billing/services/free-families-policy.service.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -111,18 +111,18 @@ export class FreeFamiliesPolicyService {
111111
});
112112
}
113113

114-
return getUserId(this.accountService.activeAccount$).pipe(
114+
return this.accountService.activeAccount$.pipe(
115+
getUserId,
115116
switchMap((userId) =>
116-
this.policyService.getAll$(PolicyType.FreeFamiliesSponsorshipPolicy, userId).pipe(
117-
map((policies) => ({
118-
isFreeFamilyPolicyEnabled: policies.some(
119-
(policy) => policy.organizationId === organizationId && policy.enabled,
120-
),
121-
belongToOneEnterpriseOrgs,
122-
belongToMultipleEnterpriseOrgs,
123-
})),
124-
),
117+
this.policyService.getAll$(PolicyType.FreeFamiliesSponsorshipPolicy, userId),
125118
),
119+
map((policies) => ({
120+
isFreeFamilyPolicyEnabled: policies.some(
121+
(policy) => policy.organizationId === organizationId && policy.enabled,
122+
),
123+
belongToOneEnterpriseOrgs,
124+
belongToMultipleEnterpriseOrgs,
125+
})),
126126
);
127127
}
128128

apps/web/src/app/billing/settings/sponsoring-org-row.component.ts

+14-14
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// @ts-strict-ignore
33
import { formatDate } from "@angular/common";
44
import { Component, EventEmitter, Input, Output, OnInit } from "@angular/core";
5-
import { firstValueFrom, map, Observable } from "rxjs";
5+
import { firstValueFrom, map, Observable, switchMap } from "rxjs";
66

77
import { ApiService } from "@bitwarden/common/abstractions/api.service";
88
import { PolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction";
@@ -56,20 +56,20 @@ export class SponsoringOrgRowComponent implements OnInit {
5656
FeatureFlag.DisableFreeFamiliesSponsorship,
5757
);
5858

59-
const userId = await firstValueFrom(getUserId(this.accountService.activeAccount$));
60-
6159
if (this.isFreeFamilyFlagEnabled) {
62-
this.isFreeFamilyPolicyEnabled$ = this.policyService
63-
.getAll$(PolicyType.FreeFamiliesSponsorshipPolicy, userId)
64-
.pipe(
65-
map(
66-
(policies) =>
67-
Array.isArray(policies) &&
68-
policies.some(
69-
(policy) => policy.organizationId === this.sponsoringOrg.id && policy.enabled,
70-
),
71-
),
72-
);
60+
this.isFreeFamilyPolicyEnabled$ = this.accountService.activeAccount$.pipe(
61+
getUserId,
62+
switchMap((userId) =>
63+
this.policyService.getAll$(PolicyType.FreeFamiliesSponsorshipPolicy, userId),
64+
),
65+
map(
66+
(policies) =>
67+
Array.isArray(policies) &&
68+
policies.some(
69+
(policy) => policy.organizationId === this.sponsoringOrg.id && policy.enabled,
70+
),
71+
),
72+
);
7373
}
7474
}
7575

libs/angular/src/tools/send/add-edit.component.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,10 @@ export class AddEditComponent implements OnInit, OnDestroy {
165165
}
166166
});
167167

168-
const userId = await firstValueFrom(getUserId(this.accountService.activeAccount$));
169-
170-
this.policyService
171-
.getAll$(PolicyType.SendOptions, userId)
168+
this.accountService.activeAccount$
172169
.pipe(
170+
getUserId,
171+
switchMap((userId) => this.policyService.getAll$(PolicyType.SendOptions, userId)),
173172
map((policies) => policies?.some((p) => p.data.disableHideEmail)),
174173
takeUntil(this.destroy$),
175174
)

libs/tools/send/send-ui/src/send-form/components/options/send-options.component.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,12 @@ export class SendOptionsComponent implements OnInit {
9595
) {
9696
this.sendFormContainer.registerChildForm("sendOptionsForm", this.sendOptionsForm);
9797

98-
getUserId(this.accountService.activeAccount$)
98+
this.accountService.activeAccount$
9999
.pipe(
100+
getUserId,
101+
switchMap((userId) => this.policyService.getAll$(PolicyType.SendOptions, userId)),
102+
map((policies) => policies?.some((p) => p.data.disableHideEmail)),
100103
takeUntilDestroyed(),
101-
switchMap((userId) =>
102-
this.policyService
103-
.getAll$(PolicyType.SendOptions, userId)
104-
.pipe(map((policies) => policies?.some((p) => p.data.disableHideEmail))),
105-
),
106104
)
107105
.subscribe((disableHideEmail) => {
108106
this.disableHideEmail = disableHideEmail;

0 commit comments

Comments
 (0)