mirror of
https://github.com/bitwarden/browser
synced 2025-12-16 16:23:44 +00:00
refactor dialogRef to be optional as the service can be used from the context of a dialog and without it (#16581)
This commit is contained in:
@@ -98,6 +98,7 @@ import {
|
|||||||
DefaultThemeStateService,
|
DefaultThemeStateService,
|
||||||
ThemeStateService,
|
ThemeStateService,
|
||||||
} from "@bitwarden/common/platform/theming/theme-state.service";
|
} from "@bitwarden/common/platform/theming/theme-state.service";
|
||||||
|
import { PremiumUpgradePromptService } from "@bitwarden/common/vault/abstractions/premium-upgrade-prompt.service";
|
||||||
import { DialogService, ToastService } from "@bitwarden/components";
|
import { DialogService, ToastService } from "@bitwarden/components";
|
||||||
import { PasswordGenerationServiceAbstraction } from "@bitwarden/generator-legacy";
|
import { PasswordGenerationServiceAbstraction } from "@bitwarden/generator-legacy";
|
||||||
import {
|
import {
|
||||||
@@ -109,6 +110,7 @@ import { LockComponentService } from "@bitwarden/key-management-ui";
|
|||||||
import { SerializedMemoryStorageService } from "@bitwarden/storage-core";
|
import { SerializedMemoryStorageService } from "@bitwarden/storage-core";
|
||||||
import { DefaultSshImportPromptService, SshImportPromptService } from "@bitwarden/vault";
|
import { DefaultSshImportPromptService, SshImportPromptService } from "@bitwarden/vault";
|
||||||
import { WebOrganizationInviteService } from "@bitwarden/web-vault/app/auth/core/services/organization-invite/web-organization-invite.service";
|
import { WebOrganizationInviteService } from "@bitwarden/web-vault/app/auth/core/services/organization-invite/web-organization-invite.service";
|
||||||
|
import { WebVaultPremiumUpgradePromptService } from "@bitwarden/web-vault/app/vault/services/web-premium-upgrade-prompt.service";
|
||||||
|
|
||||||
import { flagEnabled } from "../../utils/flags";
|
import { flagEnabled } from "../../utils/flags";
|
||||||
import {
|
import {
|
||||||
@@ -403,6 +405,11 @@ const safeProviders: SafeProvider[] = [
|
|||||||
useClass: DefaultDeviceManagementComponentService,
|
useClass: DefaultDeviceManagementComponentService,
|
||||||
deps: [],
|
deps: [],
|
||||||
}),
|
}),
|
||||||
|
safeProvider({
|
||||||
|
provide: PremiumUpgradePromptService,
|
||||||
|
useClass: WebVaultPremiumUpgradePromptService,
|
||||||
|
deps: [DialogService, Router],
|
||||||
|
}),
|
||||||
];
|
];
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
|
|||||||
@@ -1,7 +1,15 @@
|
|||||||
// FIXME: Update this file to be type safe and remove this and next line
|
// FIXME: Update this file to be type safe and remove this and next line
|
||||||
// @ts-strict-ignore
|
// @ts-strict-ignore
|
||||||
import { CommonModule } from "@angular/common";
|
import { CommonModule } from "@angular/common";
|
||||||
import { Component, ElementRef, Inject, OnDestroy, OnInit, ViewChild } from "@angular/core";
|
import {
|
||||||
|
Component,
|
||||||
|
ElementRef,
|
||||||
|
forwardRef,
|
||||||
|
Inject,
|
||||||
|
OnDestroy,
|
||||||
|
OnInit,
|
||||||
|
ViewChild,
|
||||||
|
} from "@angular/core";
|
||||||
import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
|
import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
|
||||||
import { Router } from "@angular/router";
|
import { Router } from "@angular/router";
|
||||||
import { firstValueFrom, Subject, switchMap } from "rxjs";
|
import { firstValueFrom, Subject, switchMap } from "rxjs";
|
||||||
@@ -56,10 +64,10 @@ import {
|
|||||||
} from "@bitwarden/vault";
|
} from "@bitwarden/vault";
|
||||||
|
|
||||||
import { SharedModule } from "../../../shared/shared.module";
|
import { SharedModule } from "../../../shared/shared.module";
|
||||||
import { WebVaultPremiumUpgradePromptService } from "../../../vault/services/web-premium-upgrade-prompt.service";
|
|
||||||
import { RoutedVaultFilterService } from "../../individual-vault/vault-filter/services/routed-vault-filter.service";
|
import { RoutedVaultFilterService } from "../../individual-vault/vault-filter/services/routed-vault-filter.service";
|
||||||
import { RoutedVaultFilterModel } from "../../individual-vault/vault-filter/shared/models/routed-vault-filter.model";
|
import { RoutedVaultFilterModel } from "../../individual-vault/vault-filter/shared/models/routed-vault-filter.model";
|
||||||
import { WebCipherFormGenerationService } from "../../services/web-cipher-form-generation.service";
|
import { WebCipherFormGenerationService } from "../../services/web-cipher-form-generation.service";
|
||||||
|
import { WebVaultPremiumUpgradePromptService } from "../../services/web-premium-upgrade-prompt.service";
|
||||||
|
|
||||||
export type VaultItemDialogMode = "view" | "form";
|
export type VaultItemDialogMode = "view" | "form";
|
||||||
|
|
||||||
@@ -136,7 +144,10 @@ export type VaultItemDialogResult = UnionOfValues<typeof VaultItemDialogResult>;
|
|||||||
PremiumBadgeComponent,
|
PremiumBadgeComponent,
|
||||||
],
|
],
|
||||||
providers: [
|
providers: [
|
||||||
{ provide: PremiumUpgradePromptService, useClass: WebVaultPremiumUpgradePromptService },
|
{
|
||||||
|
provide: PremiumUpgradePromptService,
|
||||||
|
useClass: forwardRef(() => WebVaultPremiumUpgradePromptService),
|
||||||
|
},
|
||||||
{ provide: ViewPasswordHistoryService, useClass: VaultViewPasswordHistoryService },
|
{ provide: ViewPasswordHistoryService, useClass: VaultViewPasswordHistoryService },
|
||||||
{ provide: CipherFormGenerationService, useClass: WebCipherFormGenerationService },
|
{ provide: CipherFormGenerationService, useClass: WebCipherFormGenerationService },
|
||||||
RoutedVaultFilterService,
|
RoutedVaultFilterService,
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import { LogService } from "@bitwarden/common/platform/abstractions/log.service"
|
|||||||
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";
|
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";
|
||||||
import { CollectionId } from "@bitwarden/common/types/guid";
|
import { CollectionId } from "@bitwarden/common/types/guid";
|
||||||
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
|
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
|
||||||
import { PremiumUpgradePromptService } from "@bitwarden/common/vault/abstractions/premium-upgrade-prompt.service";
|
|
||||||
import { ViewPasswordHistoryService } from "@bitwarden/common/vault/abstractions/view-password-history.service";
|
import { ViewPasswordHistoryService } from "@bitwarden/common/vault/abstractions/view-password-history.service";
|
||||||
import { CipherType } from "@bitwarden/common/vault/enums/cipher-type";
|
import { CipherType } from "@bitwarden/common/vault/enums/cipher-type";
|
||||||
import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view";
|
import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view";
|
||||||
@@ -33,7 +32,6 @@ import {
|
|||||||
import { CipherViewComponent } from "@bitwarden/vault";
|
import { CipherViewComponent } from "@bitwarden/vault";
|
||||||
|
|
||||||
import { SharedModule } from "../../shared/shared.module";
|
import { SharedModule } from "../../shared/shared.module";
|
||||||
import { WebVaultPremiumUpgradePromptService } from "../../vault/services/web-premium-upgrade-prompt.service";
|
|
||||||
|
|
||||||
export interface ViewCipherDialogParams {
|
export interface ViewCipherDialogParams {
|
||||||
cipher: CipherView;
|
cipher: CipherView;
|
||||||
@@ -75,10 +73,7 @@ export interface ViewCipherDialogCloseResult {
|
|||||||
selector: "app-vault-view",
|
selector: "app-vault-view",
|
||||||
templateUrl: "view.component.html",
|
templateUrl: "view.component.html",
|
||||||
imports: [CipherViewComponent, CommonModule, AsyncActionsModule, DialogModule, SharedModule],
|
imports: [CipherViewComponent, CommonModule, AsyncActionsModule, DialogModule, SharedModule],
|
||||||
providers: [
|
providers: [{ provide: ViewPasswordHistoryService, useClass: VaultViewPasswordHistoryService }],
|
||||||
{ provide: ViewPasswordHistoryService, useClass: VaultViewPasswordHistoryService },
|
|
||||||
{ provide: PremiumUpgradePromptService, useClass: WebVaultPremiumUpgradePromptService },
|
|
||||||
],
|
|
||||||
})
|
})
|
||||||
export class ViewComponent implements OnInit {
|
export class ViewComponent implements OnInit {
|
||||||
cipher: CipherView;
|
cipher: CipherView;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Injectable } from "@angular/core";
|
import { Injectable, Optional } from "@angular/core";
|
||||||
import { Router } from "@angular/router";
|
import { Router } from "@angular/router";
|
||||||
import { Subject } from "rxjs";
|
import { Subject } from "rxjs";
|
||||||
|
|
||||||
@@ -16,7 +16,7 @@ export class WebVaultPremiumUpgradePromptService implements PremiumUpgradePrompt
|
|||||||
constructor(
|
constructor(
|
||||||
private dialogService: DialogService,
|
private dialogService: DialogService,
|
||||||
private router: Router,
|
private router: Router,
|
||||||
private dialog: DialogRef<VaultItemDialogResult>,
|
@Optional() private dialog?: DialogRef<VaultItemDialogResult>,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -53,7 +53,7 @@ export class WebVaultPremiumUpgradePromptService implements PremiumUpgradePrompt
|
|||||||
if (route) {
|
if (route) {
|
||||||
await this.router.navigate(route);
|
await this.router.navigate(route);
|
||||||
}
|
}
|
||||||
if (confirmed) {
|
if (confirmed && this.dialog) {
|
||||||
this.dialog.close(VaultItemDialogResult.PremiumUpgrade);
|
this.dialog.close(VaultItemDialogResult.PremiumUpgrade);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user