mirror of
https://github.com/bitwarden/browser
synced 2025-12-17 16:53:34 +00:00
[PM-1504] Migrate Dialogs to DialogService (#5013)
This PR introduces a generic `DialogService` which can be used by all the clients. This allows us to decouple dialogs from the `PlatformUtilsHelper`. The `DialogService` provides a new method, `openSimpleDialog` which is the new interface for that type of dialogs. This gives us 3 different implementations: - Web: DialogService modern dialogs - Browser: SweetAlert - Desktop: Native electron based
This commit is contained in:
65
libs/angular/src/services/dialog/dialog.service.ts
Normal file
65
libs/angular/src/services/dialog/dialog.service.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
import {
|
||||
DialogRef,
|
||||
DialogConfig,
|
||||
Dialog,
|
||||
DEFAULT_DIALOG_CONFIG,
|
||||
DIALOG_SCROLL_STRATEGY,
|
||||
} from "@angular/cdk/dialog";
|
||||
import { Overlay, OverlayContainer } from "@angular/cdk/overlay";
|
||||
import { ComponentType } from "@angular/cdk/portal";
|
||||
import { Inject, Injectable, Injector, Optional, SkipSelf, TemplateRef } from "@angular/core";
|
||||
|
||||
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
|
||||
|
||||
import { DialogServiceAbstraction } from "./dialog.service.abstraction";
|
||||
import { SimpleDialogOptions } from "./simple-dialog-options";
|
||||
import { Translation } from "./translation";
|
||||
|
||||
// This is a temporary base class for Dialogs. It is intended to be removed once the Component Library is adopted by each app.
|
||||
@Injectable()
|
||||
export abstract class DialogService extends Dialog implements DialogServiceAbstraction {
|
||||
constructor(
|
||||
/** Parent class constructor */
|
||||
_overlay: Overlay,
|
||||
_injector: Injector,
|
||||
@Optional() @Inject(DEFAULT_DIALOG_CONFIG) _defaultOptions: DialogConfig,
|
||||
@Optional() @SkipSelf() _parentDialog: Dialog,
|
||||
_overlayContainer: OverlayContainer,
|
||||
@Inject(DIALOG_SCROLL_STRATEGY) scrollStrategy: any,
|
||||
protected i18nService: I18nService
|
||||
) {
|
||||
super(_overlay, _injector, _defaultOptions, _parentDialog, _overlayContainer, scrollStrategy);
|
||||
}
|
||||
|
||||
async openSimpleDialog(options: SimpleDialogOptions): Promise<boolean> {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
|
||||
openSimpleDialogRef(simpleDialogOptions: SimpleDialogOptions): DialogRef {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
|
||||
override open<R = unknown, D = unknown, C = unknown>(
|
||||
componentOrTemplateRef: ComponentType<C> | TemplateRef<C>,
|
||||
config?: DialogConfig<D, DialogRef<R, C>>
|
||||
): DialogRef<R, C> {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
|
||||
protected translate(translation: string | Translation, defaultKey?: string): string {
|
||||
if (translation == null && defaultKey == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (translation == null) {
|
||||
return this.i18nService.t(defaultKey);
|
||||
}
|
||||
|
||||
// Translation interface use implies we must localize.
|
||||
if (typeof translation === "object") {
|
||||
return this.i18nService.t(translation.key, ...(translation.placeholders ?? []));
|
||||
}
|
||||
|
||||
return translation;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user