1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-23 11:43:46 +00:00
Files
browser/bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/dialog/service-account-delete-dialog.component.ts
Matt Gibson 9c1e2ebd67 Typescript-strict-plugin (#12235)
* 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
2024-12-09 20:58:50 +01:00

129 lines
3.9 KiB
TypeScript

// FIXME: Update this file to be type safe and remove this and next line
// @ts-strict-ignore
import { DialogRef, DIALOG_DATA } from "@angular/cdk/dialog";
import { Component, Inject } from "@angular/core";
import {
FormControl,
FormGroup,
ValidationErrors,
ValidatorFn,
AbstractControl,
} from "@angular/forms";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { DialogService, ToastService } from "@bitwarden/components";
import { ServiceAccountView } from "../../models/view/service-account.view";
import {
BulkOperationStatus,
BulkStatusDetails,
BulkStatusDialogComponent,
} from "../../shared/dialogs/bulk-status-dialog.component";
import { ServiceAccountService } from "../service-account.service";
export interface ServiceAccountDeleteOperation {
serviceAccounts: ServiceAccountView[];
}
@Component({
templateUrl: "./service-account-delete-dialog.component.html",
})
export class ServiceAccountDeleteDialogComponent {
formGroup = new FormGroup({
confirmDelete: new FormControl("", [this.matchConfirmationMessageValidator()]),
});
constructor(
public dialogRef: DialogRef,
@Inject(DIALOG_DATA) public data: ServiceAccountDeleteOperation,
private serviceAccountService: ServiceAccountService,
private i18nService: I18nService,
private platformUtilsService: PlatformUtilsService,
private dialogService: DialogService,
private toastService: ToastService,
) {}
get title() {
return this.data.serviceAccounts.length === 1
? this.i18nService.t("deleteMachineAccount")
: this.i18nService.t("deleteMachineAccounts");
}
get dialogContent() {
return this.data.serviceAccounts.length === 1
? this.i18nService.t("deleteMachineAccountDialogMessage", this.data.serviceAccounts[0].name)
: this.i18nService.t("deleteMachineAccountsDialogMessage");
}
get dialogConfirmationLabel() {
return this.i18nService.t("deleteProjectInputLabel", this.dialogConfirmationMessage);
}
submit = async () => {
this.formGroup.markAllAsTouched();
if (this.formGroup.invalid) {
return;
}
await this.delete();
this.dialogRef.close();
};
async delete() {
const bulkResponses = await this.serviceAccountService.delete(this.data.serviceAccounts);
const errors = bulkResponses.filter((response) => response.errorMessage);
if (errors.length > 0) {
this.openBulkStatusDialog(errors);
return;
}
const message =
this.data.serviceAccounts.length === 1
? "deleteMachineAccountToast"
: "deleteMachineAccountsToast";
this.toastService.showToast({
variant: "success",
title: null,
message: this.i18nService.t(message),
});
}
openBulkStatusDialog(bulkStatusResults: BulkOperationStatus[]) {
this.dialogService.open<unknown, BulkStatusDetails>(BulkStatusDialogComponent, {
data: {
title: "deleteMachineAccounts",
subTitle: "machineAccounts",
columnTitle: "machineAccountName",
message: "bulkDeleteProjectsErrorMessage",
details: bulkStatusResults,
},
});
}
private get dialogConfirmationMessage() {
return this.data.serviceAccounts?.length === 1
? this.i18nService.t("deleteProjectConfirmMessage", this.data.serviceAccounts[0].name)
: this.i18nService.t(
"deleteMachineAccountsConfirmMessage",
this.data.serviceAccounts?.length.toString(),
);
}
private matchConfirmationMessageValidator(): ValidatorFn {
return (control: AbstractControl): ValidationErrors | null => {
if (this.dialogConfirmationMessage.toLowerCase() == control.value.toLowerCase()) {
return null;
} else {
return {
confirmationDoesntMatchError: {
message: this.i18nService.t("smConfirmationRequired"),
},
};
}
};
}
}