From a5bfff891bb2d5024cd7263a255fa062d4439ab3 Mon Sep 17 00:00:00 2001 From: vinith-kovan <156108204+vinith-kovan@users.noreply.github.com> Date: Wed, 22 May 2024 18:50:06 +0530 Subject: [PATCH] migrate policy edit component (#8914) --- .../policies/policies.component.ts | 36 ++++---- .../policies/policy-edit.component.html | 71 ++++++--------- .../policies/policy-edit.component.ts | 87 ++++++++++--------- 3 files changed, 88 insertions(+), 106 deletions(-) diff --git a/apps/web/src/app/admin-console/organizations/policies/policies.component.ts b/apps/web/src/app/admin-console/organizations/policies/policies.component.ts index 6f8bb27671..782db231c6 100644 --- a/apps/web/src/app/admin-console/organizations/policies/policies.component.ts +++ b/apps/web/src/app/admin-console/organizations/policies/policies.component.ts @@ -1,18 +1,19 @@ import { Component, OnInit, ViewChild, ViewContainerRef } from "@angular/core"; -import { ActivatedRoute, Router } from "@angular/router"; +import { ActivatedRoute } from "@angular/router"; +import { lastValueFrom } from "rxjs"; import { first } from "rxjs/operators"; -import { ModalService } from "@bitwarden/angular/services/modal.service"; import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction"; import { PolicyApiServiceAbstraction } from "@bitwarden/common/admin-console/abstractions/policy/policy-api.service.abstraction"; import { PolicyType } from "@bitwarden/common/admin-console/enums"; import { Organization } from "@bitwarden/common/admin-console/models/domain/organization"; import { PolicyResponse } from "@bitwarden/common/admin-console/models/response/policy.response"; +import { DialogService } from "@bitwarden/components"; import { PolicyListService } from "../../core/policy-list.service"; import { BasePolicy } from "../policies"; -import { PolicyEditComponent } from "./policy-edit.component"; +import { PolicyEditComponent, PolicyEditDialogResult } from "./policy-edit.component"; @Component({ selector: "app-org-policies", @@ -33,11 +34,10 @@ export class PoliciesComponent implements OnInit { constructor( private route: ActivatedRoute, - private modalService: ModalService, private organizationService: OrganizationService, private policyApiService: PolicyApiServiceAbstraction, private policyListService: PolicyListService, - private router: Router, + private dialogService: DialogService, ) {} async ngOnInit() { @@ -83,21 +83,17 @@ export class PoliciesComponent implements OnInit { } async edit(policy: BasePolicy) { - const [modal] = await this.modalService.openViewRef( - PolicyEditComponent, - this.editModalRef, - (comp) => { - comp.policy = policy; - comp.organizationId = this.organizationId; - comp.policiesEnabledMap = this.policiesEnabledMap; - // eslint-disable-next-line rxjs-angular/prefer-takeuntil - comp.onSavedPolicy.subscribe(() => { - modal.close(); - // FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling. - // eslint-disable-next-line @typescript-eslint/no-floating-promises - this.load(); - }); + const dialogRef = PolicyEditComponent.open(this.dialogService, { + data: { + policy: policy, + organizationId: this.organizationId, + policiesEnabledMap: this.policiesEnabledMap, }, - ); + }); + + const result = await lastValueFrom(dialogRef.closed); + if (result === PolicyEditDialogResult.Saved) { + await this.load(); + } } } diff --git a/apps/web/src/app/admin-console/organizations/policies/policy-edit.component.html b/apps/web/src/app/admin-console/organizations/policies/policy-edit.component.html index 5f5dc1d85e..063a8759e6 100644 --- a/apps/web/src/app/admin-console/organizations/policies/policy-edit.component.html +++ b/apps/web/src/app/admin-console/organizations/policies/policy-edit.component.html @@ -1,49 +1,28 @@ -