[PM-2054] Updated Password Generator History to use Component Library on Web (#5414)

* [PM-2054] Updated Password Generator History to use Component Library

* [PM-2054] Corrected paddings

* [PM-2054] Added missing type to buttons

* [PM-2054] Removed unused imports and run prettier

* [PM-2054] Swap list by bit-table
This commit is contained in:
aj-rosado 2023-05-15 12:01:28 +01:00 committed by GitHub
parent e40c9902eb
commit 44fd063dc1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 53 additions and 68 deletions

View File

@ -1,7 +1,7 @@
import { Component, ViewChild, ViewContainerRef } from "@angular/core"; import { Component } from "@angular/core";
import { ActivatedRoute } from "@angular/router"; import { ActivatedRoute } from "@angular/router";
import { ModalService } from "@bitwarden/angular/services/modal.service"; import { DialogServiceAbstraction } from "@bitwarden/angular/services/dialog";
import { GeneratorComponent as BaseGeneratorComponent } from "@bitwarden/angular/tools/generator/components/generator.component"; import { GeneratorComponent as BaseGeneratorComponent } from "@bitwarden/angular/tools/generator/components/generator.component";
import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
import { LogService } from "@bitwarden/common/abstractions/log.service"; import { LogService } from "@bitwarden/common/abstractions/log.service";
@ -17,9 +17,6 @@ import { PasswordGeneratorHistoryComponent } from "./password-generator-history.
templateUrl: "generator.component.html", templateUrl: "generator.component.html",
}) })
export class GeneratorComponent extends BaseGeneratorComponent { export class GeneratorComponent extends BaseGeneratorComponent {
@ViewChild("historyTemplate", { read: ViewContainerRef, static: true })
historyModalRef: ViewContainerRef;
constructor( constructor(
passwordGenerationService: PasswordGenerationServiceAbstraction, passwordGenerationService: PasswordGenerationServiceAbstraction,
usernameGenerationService: UsernameGenerationServiceAbstraction, usernameGenerationService: UsernameGenerationServiceAbstraction,
@ -28,7 +25,7 @@ export class GeneratorComponent extends BaseGeneratorComponent {
i18nService: I18nService, i18nService: I18nService,
logService: LogService, logService: LogService,
route: ActivatedRoute, route: ActivatedRoute,
private modalService: ModalService private dialogService: DialogServiceAbstraction
) { ) {
super( super(
passwordGenerationService, passwordGenerationService,
@ -47,7 +44,7 @@ export class GeneratorComponent extends BaseGeneratorComponent {
} }
async history() { async history() {
await this.modalService.openViewRef(PasswordGeneratorHistoryComponent, this.historyModalRef); this.dialogService.open(PasswordGeneratorHistoryComponent);
} }
lengthChanged() { lengthChanged() {

View File

@ -1,59 +1,47 @@
<div class="modal fade" role="dialog" aria-modal="true" aria-labelledby="passHistoryTitle"> <bit-dialog>
<div class="modal-dialog modal-dialog-scrollable" role="document"> <span bitDialogTitle>
<div class="modal-content"> {{ "passwordHistory" | i18n }}
<div class="modal-header"> </span>
<h1 class="modal-title" id="passHistoryTitle">{{ "passwordHistory" | i18n }}</h1> <span bitDialogContent>
<button <bit-table *ngIf="history.length">
type="button" <ng-template body>
class="close" <tr bitRow *ngFor="let h of history">
data-dismiss="modal" <td bitCell>
appA11yTitle="{{ 'close' | i18n }}"
>
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body" *ngIf="history.length">
<ul class="list-group list-group-flush">
<li class="list-group-item d-flex" *ngFor="let h of history">
<div class="tw-min-w-0">
<bit-color-password <bit-color-password
[password]="h.password" [password]="h.password"
class="tw-block tw-font-mono" class="tw-block tw-font-mono"
appSelectCopy appSelectCopy
></bit-color-password> ></bit-color-password>
<small class="text-muted">{{ h.date | date : "medium" }}</small> <small bitTypography="body2" class="tw-text-muted">
</div> {{ h.date | date : "medium" }}
<div class="ml-auto"> </small>
</td>
<td bitCell class="tw-w-0">
<button <button
type="button" type="button"
class="btn btn-link" bitIconButton="bwi-clone"
appA11yTitle="{{ 'copyPassword' | i18n }}"
(click)="copy(h.password)" (click)="copy(h.password)"
> [appA11yTitle]="'copyPassword' | i18n"
<i class="bwi bwi-lg bwi-clone" aria-hidden="true"></i> ></button>
</button> </td>
</div> </tr>
</li> </ng-template>
</ul> </bit-table>
</div> <div *ngIf="!history.length">
<div class="modal-body" *ngIf="!history.length">
{{ "noPasswordsInList" | i18n }} {{ "noPasswordsInList" | i18n }}
</div> </div>
<div class="modal-footer"> </span>
<button type="button" class="btn btn-outline-secondary" data-dismiss="modal"> <ng-container bitDialogFooter>
<button type="button" bitButton buttonType="secondary" bitDialogClose>
{{ "close" | i18n }} {{ "close" | i18n }}
</button> </button>
<div class="ml-auto">
<button <button
type="button" type="button"
(click)="clear()" class="tw-ml-auto"
class="btn btn-outline-danger" bitIconButton="bwi-trash"
appA11yTitle="{{ 'clear' | i18n }}" buttonType="danger"
> title="{{ 'clear' | i18n }}"
<i class="bwi bwi-trash bwi-lg bwi-fw" aria-hidden="true"></i> [bitAction]="clear"
</button> ></button>
</div> </ng-container>
</div> </bit-dialog>
</div>
</div>
</div>

View File

@ -22,10 +22,10 @@ export class PasswordGeneratorHistoryComponent implements OnInit {
this.history = await this.passwordGenerationService.getHistory(); this.history = await this.passwordGenerationService.getHistory();
} }
clear() { clear = async () => {
this.history = []; this.history = [];
this.passwordGenerationService.clear(); await this.passwordGenerationService.clear();
} };
copy(password: string) { copy(password: string) {
const copyOptions = this.win != null ? { window: this.win } : null; const copyOptions = this.win != null ? { window: this.win } : null;