SM-615: Add Error Messages for Unselected Bulk Actions in SM (#5006)

* SM-615: Add error message when doing bulk actions on projects and secrets but nothing is selected

* SM-615: Add alert for service account unselected bulk deletes
This commit is contained in:
Colton Hurst 2023-03-20 11:31:14 -04:00 committed by GitHub
parent 57b5d93ecb
commit 138a4923c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 6 deletions

View File

@ -2,6 +2,8 @@ import { SelectionModel } from "@angular/cdk/collections";
import { Component, EventEmitter, Input, OnDestroy, Output } from "@angular/core";
import { Subject, takeUntil } from "rxjs";
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service";
import { TableDataSource } from "@bitwarden/components";
import { ServiceAccountView } from "../models/view/service-account.view";
@ -38,7 +40,10 @@ export class ServiceAccountsListComponent implements OnDestroy {
selection = new SelectionModel<string>(true, []);
constructor() {
constructor(
private i18nService: I18nService,
private platformUtilsService: PlatformUtilsService
) {
this.selection.changed
.pipe(takeUntil(this.destroy$))
.subscribe((_) => this.onServiceAccountCheckedEvent.emit(this.selection.selected));
@ -70,6 +75,12 @@ export class ServiceAccountsListComponent implements OnDestroy {
this.deleteServiceAccountsEvent.emit(
this.serviceAccounts.filter((sa) => this.selection.isSelected(sa.id))
);
} else {
this.platformUtilsService.showToast(
"error",
this.i18nService.t("errorOccurred"),
this.i18nService.t("nothingSelected")
);
}
}
}

View File

@ -2,6 +2,8 @@ import { SelectionModel } from "@angular/cdk/collections";
import { Component, EventEmitter, Input, OnDestroy, Output } from "@angular/core";
import { Subject, takeUntil } from "rxjs";
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service";
import { TableDataSource } from "@bitwarden/components";
import { ProjectListView } from "../models/view/project-list.view";
@ -38,7 +40,10 @@ export class ProjectsListComponent implements OnDestroy {
selection = new SelectionModel<string>(true, []);
constructor() {
constructor(
private i18nService: I18nService,
private platformUtilsService: PlatformUtilsService
) {
this.selection.changed
.pipe(takeUntil(this.destroy$))
.subscribe((_) => this.onProjectCheckedEvent.emit(this.selection.selected));
@ -66,8 +71,16 @@ export class ProjectsListComponent implements OnDestroy {
}
bulkDeleteProjects() {
this.deleteProjectEvent.emit(
this.projects.filter((project) => this.selection.isSelected(project.id))
);
if (this.selection.selected.length >= 1) {
this.deleteProjectEvent.emit(
this.projects.filter((project) => this.selection.isSelected(project.id))
);
} else {
this.platformUtilsService.showToast(
"error",
this.i18nService.t("errorOccurred"),
this.i18nService.t("nothingSelected")
);
}
}
}

View File

@ -46,7 +46,10 @@ export class SecretsListComponent implements OnDestroy {
selection = new SelectionModel<string>(true, []);
constructor() {
constructor(
private i18nService: I18nService,
private platformUtilsService: PlatformUtilsService
) {
this.selection.changed
.pipe(takeUntil(this.destroy$))
.subscribe((_) => this.onSecretCheckedEvent.emit(this.selection.selected));
@ -74,12 +77,24 @@ export class SecretsListComponent implements OnDestroy {
this.deleteSecretsEvent.emit(
this.secrets.filter((secret) => this.selection.isSelected(secret.id))
);
} else {
this.platformUtilsService.showToast(
"error",
this.i18nService.t("errorOccurred"),
this.i18nService.t("nothingSelected")
);
}
}
bulkRestoreSecrets() {
if (this.selection.selected.length >= 1) {
this.restoreSecretsEvent.emit(this.selection.selected);
} else {
this.platformUtilsService.showToast(
"error",
this.i18nService.t("errorOccurred"),
this.i18nService.t("nothingSelected")
);
}
}