Skip to content

Commit

Permalink
remove nested pipes, cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
BTreston committed Jan 24, 2025
1 parent 0b3bb89 commit 906a280
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 34 deletions.
20 changes: 10 additions & 10 deletions apps/web/src/app/billing/services/free-families-policy.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,18 @@ export class FreeFamiliesPolicyService {
});
}

return getUserId(this.accountService.activeAccount$).pipe(
return this.accountService.activeAccount$.pipe(

Check warning on line 114 in apps/web/src/app/billing/services/free-families-policy.service.ts

View check run for this annotation

Codecov / codecov/patch

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

Added line #L114 was not covered by tests
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),

Check warning on line 117 in apps/web/src/app/billing/services/free-families-policy.service.ts

View check run for this annotation

Codecov / codecov/patch

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

Added line #L117 was not covered by tests
),
map((policies) => ({
isFreeFamilyPolicyEnabled: policies.some(
(policy) => policy.organizationId === organizationId && policy.enabled,
),
belongToOneEnterpriseOrgs,
belongToMultipleEnterpriseOrgs,
})),
);
}

Expand Down
28 changes: 14 additions & 14 deletions apps/web/src/app/billing/settings/sponsoring-org-row.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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(

Check warning on line 60 in apps/web/src/app/billing/settings/sponsoring-org-row.component.ts

View check run for this annotation

Codecov / codecov/patch

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

Added line #L60 was not covered by tests
getUserId,
switchMap((userId) =>
this.policyService.getAll$(PolicyType.FreeFamiliesSponsorshipPolicy, userId),

Check warning on line 63 in apps/web/src/app/billing/settings/sponsoring-org-row.component.ts

View check run for this annotation

Codecov / codecov/patch

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

Added line #L63 was not covered by tests
),
map(
(policies) =>
Array.isArray(policies) &&
policies.some(
(policy) => policy.organizationId === this.sponsoringOrg.id && policy.enabled,
),
),
);
}
}

Expand Down
7 changes: 3 additions & 4 deletions libs/angular/src/tools/send/add-edit.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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$

Check warning on line 168 in libs/angular/src/tools/send/add-edit.component.ts

View check run for this annotation

Codecov / codecov/patch

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

Added line #L168 was not covered by tests
.pipe(
getUserId,
switchMap((userId) => this.policyService.getAll$(PolicyType.SendOptions, userId)),

Check warning on line 171 in libs/angular/src/tools/send/add-edit.component.ts

View check run for this annotation

Codecov / codecov/patch

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

Added line #L171 was not covered by tests
map((policies) => policies?.some((p) => p.data.disableHideEmail)),
takeUntil(this.destroy$),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,12 @@ export class SendOptionsComponent implements OnInit {
) {
this.sendFormContainer.registerChildForm("sendOptionsForm", this.sendOptionsForm);

getUserId(this.accountService.activeAccount$)
this.accountService.activeAccount$

Check warning on line 98 in libs/tools/send/send-ui/src/send-form/components/options/send-options.component.ts

View check run for this annotation

Codecov / codecov/patch

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

Added line #L98 was not covered by tests
.pipe(
getUserId,
switchMap((userId) => this.policyService.getAll$(PolicyType.SendOptions, userId)),

Check warning on line 101 in libs/tools/send/send-ui/src/send-form/components/options/send-options.component.ts

View check run for this annotation

Codecov / codecov/patch

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

Added line #L101 was not covered by tests
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;
Expand Down

0 comments on commit 906a280

Please sign in to comment.