diff --git a/apps/browser/src/popup/app-routing.module.ts b/apps/browser/src/popup/app-routing.module.ts index f01809433e3..e2f4561e86c 100644 --- a/apps/browser/src/popup/app-routing.module.ts +++ b/apps/browser/src/popup/app-routing.module.ts @@ -2,11 +2,7 @@ import { Injectable, NgModule } from "@angular/core"; import { ActivatedRouteSnapshot, RouteReuseStrategy, RouterModule, Routes } from "@angular/router"; import { AuthenticationTimeoutComponent } from "@bitwarden/angular/auth/components/authentication-timeout.component"; -import { - EnvironmentSelectorComponent, - EnvironmentSelectorRouteData, - ExtensionDefaultOverlayPosition, -} from "@bitwarden/angular/auth/components/environment-selector.component"; +import { EnvironmentSelectorComponent } from "@bitwarden/angular/auth/environment-selector/environment-selector.component"; import { activeAuthGuard, authGuard, @@ -400,9 +396,6 @@ const routes: Routes = [ path: "", component: EnvironmentSelectorComponent, outlet: "environment-selector", - data: { - overlayPosition: ExtensionDefaultOverlayPosition, - } satisfies EnvironmentSelectorRouteData, }, ], }, @@ -425,9 +418,6 @@ const routes: Routes = [ path: "", component: EnvironmentSelectorComponent, outlet: "environment-selector", - data: { - overlayPosition: ExtensionDefaultOverlayPosition, - } satisfies EnvironmentSelectorRouteData, }, ], }, @@ -474,9 +464,6 @@ const routes: Routes = [ path: "", component: EnvironmentSelectorComponent, outlet: "environment-selector", - data: { - overlayPosition: ExtensionDefaultOverlayPosition, - } satisfies EnvironmentSelectorRouteData, }, ], }, diff --git a/apps/browser/src/popup/app.module.ts b/apps/browser/src/popup/app.module.ts index 5150c51d765..2aacd3d3632 100644 --- a/apps/browser/src/popup/app.module.ts +++ b/apps/browser/src/popup/app.module.ts @@ -9,7 +9,6 @@ import { FormsModule, ReactiveFormsModule } from "@angular/forms"; import { BrowserModule } from "@angular/platform-browser"; import { BrowserAnimationsModule } from "@angular/platform-browser/animations"; -import { EnvironmentSelectorComponent } from "@bitwarden/angular/auth/components/environment-selector.component"; import { JslibModule } from "@bitwarden/angular/jslib.module"; import { ColorPasswordCountPipe } from "@bitwarden/angular/pipes/color-password-count.pipe"; import { ColorPasswordPipe } from "@bitwarden/angular/pipes/color-password.pipe"; @@ -96,7 +95,6 @@ import "../platform/popup/locales"; TabsV2Component, UserVerificationComponent, RemovePasswordComponent, - EnvironmentSelectorComponent, ], exports: [], providers: [CurrencyPipe, DatePipe], diff --git a/apps/desktop/src/app/app-routing.module.ts b/apps/desktop/src/app/app-routing.module.ts index 30ae906c98d..db079cd60f9 100644 --- a/apps/desktop/src/app/app-routing.module.ts +++ b/apps/desktop/src/app/app-routing.module.ts @@ -2,10 +2,7 @@ import { NgModule } from "@angular/core"; import { RouterModule, Routes } from "@angular/router"; import { AuthenticationTimeoutComponent } from "@bitwarden/angular/auth/components/authentication-timeout.component"; -import { - DesktopDefaultOverlayPosition, - EnvironmentSelectorComponent, -} from "@bitwarden/angular/auth/components/environment-selector.component"; +import { EnvironmentSelectorComponent } from "@bitwarden/angular/auth/environment-selector/environment-selector.component"; import { authGuard, lockGuard, @@ -174,9 +171,6 @@ const routes: Routes = [ path: "", component: EnvironmentSelectorComponent, outlet: "environment-selector", - data: { - overlayPosition: DesktopDefaultOverlayPosition, - }, }, ], }, @@ -205,9 +199,6 @@ const routes: Routes = [ path: "", component: EnvironmentSelectorComponent, outlet: "environment-selector", - data: { - overlayPosition: DesktopDefaultOverlayPosition, - }, }, ], }, @@ -228,9 +219,6 @@ const routes: Routes = [ path: "", component: EnvironmentSelectorComponent, outlet: "environment-selector", - data: { - overlayPosition: DesktopDefaultOverlayPosition, - }, }, ], }, @@ -265,9 +253,6 @@ const routes: Routes = [ path: "", component: EnvironmentSelectorComponent, outlet: "environment-selector", - data: { - overlayPosition: DesktopDefaultOverlayPosition, - }, }, ], }, diff --git a/apps/desktop/src/auth/login/login.module.ts b/apps/desktop/src/auth/login/login.module.ts index 601c71e00b1..904d1b34373 100644 --- a/apps/desktop/src/auth/login/login.module.ts +++ b/apps/desktop/src/auth/login/login.module.ts @@ -1,13 +1,10 @@ import { NgModule } from "@angular/core"; import { RouterModule } from "@angular/router"; -import { EnvironmentSelectorComponent } from "@bitwarden/angular/auth/components/environment-selector.component"; - import { SharedModule } from "../../app/shared/shared.module"; @NgModule({ imports: [SharedModule, RouterModule], - declarations: [EnvironmentSelectorComponent], exports: [], }) export class LoginModule {} diff --git a/libs/angular/src/auth/components/environment-selector.component.html b/libs/angular/src/auth/components/environment-selector.component.html deleted file mode 100644 index 19f49f73dd2..00000000000 --- a/libs/angular/src/auth/components/environment-selector.component.html +++ /dev/null @@ -1,84 +0,0 @@ - - - {{ "accessing" | i18n }}: - - - - {{ data.selectedRegion.domain }} - - - {{ "selfHostedServer" | i18n }} - - - - - - - - - - - - - {{ region.domain }} - - - - - - {{ "selfHostedServer" | i18n }} - - - - - diff --git a/libs/angular/src/auth/components/environment-selector.component.ts b/libs/angular/src/auth/components/environment-selector.component.ts deleted file mode 100644 index 1831e513301..00000000000 --- a/libs/angular/src/auth/components/environment-selector.component.ts +++ /dev/null @@ -1,135 +0,0 @@ -import { animate, state, style, transition, trigger } from "@angular/animations"; -import { ConnectedPosition } from "@angular/cdk/overlay"; -import { Component, EventEmitter, Output, Input, OnInit, OnDestroy } from "@angular/core"; -import { ActivatedRoute } from "@angular/router"; -import { Observable, map, Subject, takeUntil } from "rxjs"; - -// This import has been flagged as unallowed for this class. It may be involved in a circular dependency loop. -// eslint-disable-next-line no-restricted-imports -import { SelfHostedEnvConfigDialogComponent } from "@bitwarden/auth/angular"; -import { - EnvironmentService, - Region, - RegionConfig, -} from "@bitwarden/common/platform/abstractions/environment.service"; -import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; -import { DialogService, ToastService } from "@bitwarden/components"; - -export const ExtensionDefaultOverlayPosition: ConnectedPosition[] = [ - { - originX: "start", - originY: "top", - overlayX: "start", - overlayY: "bottom", - }, -]; -export const DesktopDefaultOverlayPosition: ConnectedPosition[] = [ - { - originX: "start", - originY: "top", - overlayX: "start", - overlayY: "bottom", - }, -]; - -export interface EnvironmentSelectorRouteData { - overlayPosition?: ConnectedPosition[]; -} - -@Component({ - selector: "environment-selector", - templateUrl: "environment-selector.component.html", - animations: [ - trigger("transformPanel", [ - state( - "void", - style({ - opacity: 0, - }), - ), - transition( - "void => open", - animate( - "100ms linear", - style({ - opacity: 1, - }), - ), - ), - transition("* => void", animate("100ms linear", style({ opacity: 0 }))), - ]), - ], - standalone: false, -}) -export class EnvironmentSelectorComponent implements OnInit, OnDestroy { - @Output() onOpenSelfHostedSettings = new EventEmitter(); - @Input() overlayPosition: ConnectedPosition[] = [ - { - originX: "start", - originY: "bottom", - overlayX: "start", - overlayY: "top", - }, - ]; - - protected isOpen = false; - protected ServerEnvironmentType = Region; - protected availableRegions = this.environmentService.availableRegions(); - protected selectedRegion$: Observable = - this.environmentService.environment$.pipe( - map((e) => e.getRegion()), - map((r) => this.availableRegions.find((ar) => ar.key === r)), - ); - - private destroy$ = new Subject(); - - constructor( - protected environmentService: EnvironmentService, - private route: ActivatedRoute, - private dialogService: DialogService, - private toastService: ToastService, - private i18nService: I18nService, - ) {} - - ngOnInit() { - this.route.data.pipe(takeUntil(this.destroy$)).subscribe((data) => { - if (data && data["overlayPosition"]) { - this.overlayPosition = data["overlayPosition"]; - } - }); - } - - ngOnDestroy() { - this.destroy$.next(); - this.destroy$.complete(); - } - - async toggle(option: Region) { - this.isOpen = !this.isOpen; - if (option === null) { - return; - } - - /** - * Opens the self-hosted settings dialog when the self-hosted option is selected. - */ - if (option === Region.SelfHosted) { - const dialogResult = await SelfHostedEnvConfigDialogComponent.open(this.dialogService); - if (dialogResult) { - this.toastService.showToast({ - variant: "success", - title: "", - message: this.i18nService.t("environmentSaved"), - }); - } - // Don't proceed to setEnvironment when the self-hosted dialog is cancelled - return; - } - - await this.environmentService.setEnvironment(option); - } - - close() { - this.isOpen = false; - } -} diff --git a/libs/angular/src/auth/environment-selector/environment-selector.component.html b/libs/angular/src/auth/environment-selector/environment-selector.component.html new file mode 100644 index 00000000000..f6484ea1e5f --- /dev/null +++ b/libs/angular/src/auth/environment-selector/environment-selector.component.html @@ -0,0 +1,48 @@ + + + + + + {{ region.domain }} + + + + {{ "selfHostedServer" | i18n }} + + + + {{ "accessing" | i18n }}: + + {{ + data.selectedRegion?.domain || ("selfHostedServer" | i18n) + }} + + + + + diff --git a/libs/angular/src/auth/environment-selector/environment-selector.component.ts b/libs/angular/src/auth/environment-selector/environment-selector.component.ts new file mode 100644 index 00000000000..6fe3eaa92a0 --- /dev/null +++ b/libs/angular/src/auth/environment-selector/environment-selector.component.ts @@ -0,0 +1,75 @@ +import { CommonModule } from "@angular/common"; +import { Component, OnDestroy } from "@angular/core"; +import { Observable, map, Subject } from "rxjs"; + +// This import has been flagged as unallowed for this class. It may be involved in a circular dependency loop. +// eslint-disable-next-line no-restricted-imports +import { SelfHostedEnvConfigDialogComponent } from "@bitwarden/auth/angular"; +import { + EnvironmentService, + Region, + RegionConfig, +} from "@bitwarden/common/platform/abstractions/environment.service"; +import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; +import { + DialogService, + LinkModule, + MenuModule, + ToastService, + TypographyModule, +} from "@bitwarden/components"; +import { I18nPipe } from "@bitwarden/ui-common"; + +@Component({ + selector: "environment-selector", + templateUrl: "environment-selector.component.html", + standalone: true, + imports: [CommonModule, I18nPipe, MenuModule, LinkModule, TypographyModule], +}) +export class EnvironmentSelectorComponent implements OnDestroy { + protected ServerEnvironmentType = Region; + protected availableRegions = this.environmentService.availableRegions(); + protected selectedRegion$: Observable = + this.environmentService.environment$.pipe( + map((e) => e.getRegion()), + map((r) => this.availableRegions.find((ar) => ar.key === r)), + ); + + private destroy$ = new Subject(); + + constructor( + public environmentService: EnvironmentService, + private dialogService: DialogService, + private toastService: ToastService, + private i18nService: I18nService, + ) {} + + ngOnDestroy() { + this.destroy$.next(); + this.destroy$.complete(); + } + + async toggle(option: Region) { + if (option === null) { + return; + } + + /** + * Opens the self-hosted settings dialog when the self-hosted option is selected. + */ + if (option === Region.SelfHosted) { + const dialogResult = await SelfHostedEnvConfigDialogComponent.open(this.dialogService); + if (dialogResult) { + this.toastService.showToast({ + variant: "success", + title: "", + message: this.i18nService.t("environmentSaved"), + }); + } + // Don't proceed to setEnvironment when the self-hosted dialog is cancelled + return; + } + + await this.environmentService.setEnvironment(option); + } +}