mirror of
https://github.com/bitwarden/clients.git
synced 2026-02-09 10:23:47 +08:00
* Use typescript-strict-plugin to iteratively turn on strict * Add strict testing to pipeline Can be executed locally through either `npm run test:types` for full type checking including spec files, or `npx tsc-strict` for only tsconfig.json included files. * turn on strict for scripts directory * Use plugin for all tsconfigs in monorepo vscode is capable of executing tsc with plugins, but uses the most relevant tsconfig to do so. If the plugin is not a part of that config, it is skipped and developers get no feedback of strict compile time issues. These updates remedy that at the cost of slightly more complex removal of the plugin when the time comes. * remove plugin from configs that extend one that already has it * Update workspace settings to honor strict plugin * Apply strict-plugin to native message test runner * Update vscode workspace to use root tsc version * `./node_modules/.bin/update-strict-comments` 🤖 This is a one-time operation. All future files should adhere to strict type checking. * Add fixme to `ts-strict-ignore` comments * `update-strict-comments` 🤖 repeated for new merge files
144 lines
4.1 KiB
TypeScript
144 lines
4.1 KiB
TypeScript
// FIXME: Update this file to be type safe and remove this and next line
|
|
// @ts-strict-ignore
|
|
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";
|
|
|
|
import { SelfHostedEnvConfigDialogComponent } from "@bitwarden/auth/angular";
|
|
import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
|
|
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
|
|
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 }))),
|
|
]),
|
|
],
|
|
})
|
|
export class EnvironmentSelectorComponent implements OnInit, OnDestroy {
|
|
@Output() onOpenSelfHostedSettings = new EventEmitter<void>();
|
|
@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<RegionConfig | undefined> =
|
|
this.environmentService.environment$.pipe(
|
|
map((e) => e.getRegion()),
|
|
map((r) => this.availableRegions.find((ar) => ar.key === r)),
|
|
);
|
|
|
|
private destroy$ = new Subject<void>();
|
|
|
|
constructor(
|
|
protected environmentService: EnvironmentService,
|
|
private route: ActivatedRoute,
|
|
private dialogService: DialogService,
|
|
private configService: ConfigService,
|
|
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.
|
|
*
|
|
* If the `UnauthenticatedExtensionUIRefresh` feature flag is enabled,
|
|
* the self-hosted settings dialog is opened directly. Otherwise, the
|
|
* `onOpenSelfHostedSettings` event is emitted.
|
|
*/
|
|
if (option === Region.SelfHosted) {
|
|
if (await this.configService.getFeatureFlag(FeatureFlag.UnauthenticatedExtensionUIRefresh)) {
|
|
if (await SelfHostedEnvConfigDialogComponent.open(this.dialogService)) {
|
|
this.toastService.showToast({
|
|
variant: "success",
|
|
title: null,
|
|
message: this.i18nService.t("environmentSaved"),
|
|
});
|
|
}
|
|
} else {
|
|
this.onOpenSelfHostedSettings.emit();
|
|
}
|
|
return;
|
|
}
|
|
|
|
await this.environmentService.setEnvironment(option);
|
|
}
|
|
|
|
close() {
|
|
this.isOpen = false;
|
|
}
|
|
}
|