Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PM-15999] - use new generator components in desktop app #12639

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<bit-dialog #dialog dialogSize="large" background="alt">
<span bitDialogTitle>{{ "generator" | i18n }}</span>
<ng-container bitDialogContent>
<vault-cipher-form-generator
[type]="data.type"
(valueGenerated)="onCredentialGenerated($event)"
/>
<bit-item>
<button
type="button"
bitLink
linkType="primary"
bit-item-content
aria-haspopup="true"
(click)="openHistoryDialog()"
>
{{ "generatorHistory" | i18n }}
<i slot="end" class="bwi bwi-angle-right" aria-hidden="true"></i>
</button>
</bit-item>
</ng-container>
<ng-container bitDialogFooter>
<div class="modal-footer">
<button
type="button"
class="primary"
(click)="applyCredentials()"
appA11yTitle="{{ 'select' | i18n }}"
bitDialogClose
>
<i class="bwi bwi-lg bwi-fw bwi-check" aria-hidden="true"></i>
</button>
<button type="button" data-dismiss="modal" (click)="clearCredentials()" bitDialogClose>
{{ "cancel" | i18n }}
</button>
</div>
</ng-container>
</bit-dialog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { DIALOG_DATA } from "@angular/cdk/dialog";
import { CommonModule } from "@angular/common";
import { Component, Inject } from "@angular/core";

Check warning on line 3 in apps/desktop/src/vault/app/vault/credential-generator-dialog.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/desktop/src/vault/app/vault/credential-generator-dialog.component.ts#L1-L3

Added lines #L1 - L3 were not covered by tests

import { JslibModule } from "@bitwarden/angular/jslib.module";
import {

Check warning on line 6 in apps/desktop/src/vault/app/vault/credential-generator-dialog.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/desktop/src/vault/app/vault/credential-generator-dialog.component.ts#L5-L6

Added lines #L5 - L6 were not covered by tests
ButtonModule,
DialogModule,
DialogService,
ItemModule,
LinkModule,
} from "@bitwarden/components";
import {

Check warning on line 13 in apps/desktop/src/vault/app/vault/credential-generator-dialog.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/desktop/src/vault/app/vault/credential-generator-dialog.component.ts#L13

Added line #L13 was not covered by tests
CredentialGeneratorHistoryDialogComponent,
GeneratorModule,
} from "@bitwarden/generator-components";
import { CipherFormGeneratorComponent } from "@bitwarden/vault";

Check warning on line 17 in apps/desktop/src/vault/app/vault/credential-generator-dialog.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/desktop/src/vault/app/vault/credential-generator-dialog.component.ts#L17

Added line #L17 was not covered by tests

type CredentialGeneratorParams = {
onCredentialGenerated: (value?: string) => void;
type: "password" | "username";
};

@Component({
standalone: true,
selector: "credential-generator-dialog",
templateUrl: "credential-generator-dialog.component.html",
imports: [
CipherFormGeneratorComponent,
CommonModule,
DialogModule,
ButtonModule,
JslibModule,
GeneratorModule,
ItemModule,
LinkModule,
],
})
export class CredentialGeneratorDialogComponent {

Check warning on line 39 in apps/desktop/src/vault/app/vault/credential-generator-dialog.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/desktop/src/vault/app/vault/credential-generator-dialog.component.ts#L39

Added line #L39 was not covered by tests
credentialValue?: string;

constructor(
@Inject(DIALOG_DATA) protected data: CredentialGeneratorParams,

Check warning on line 43 in apps/desktop/src/vault/app/vault/credential-generator-dialog.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/desktop/src/vault/app/vault/credential-generator-dialog.component.ts#L43

Added line #L43 was not covered by tests
private dialogService: DialogService,
) {}

applyCredentials = () => {
this.data.onCredentialGenerated(this.credentialValue);

Check warning on line 48 in apps/desktop/src/vault/app/vault/credential-generator-dialog.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/desktop/src/vault/app/vault/credential-generator-dialog.component.ts#L47-L48

Added lines #L47 - L48 were not covered by tests
};

clearCredentials = () => {
this.data.onCredentialGenerated();

Check warning on line 52 in apps/desktop/src/vault/app/vault/credential-generator-dialog.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/desktop/src/vault/app/vault/credential-generator-dialog.component.ts#L51-L52

Added lines #L51 - L52 were not covered by tests
};

onCredentialGenerated = (value: string) => {
this.credentialValue = value;

Check warning on line 56 in apps/desktop/src/vault/app/vault/credential-generator-dialog.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/desktop/src/vault/app/vault/credential-generator-dialog.component.ts#L55-L56

Added lines #L55 - L56 were not covered by tests
};

openHistoryDialog = () => {

Check warning on line 59 in apps/desktop/src/vault/app/vault/credential-generator-dialog.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/desktop/src/vault/app/vault/credential-generator-dialog.component.ts#L59

Added line #L59 was not covered by tests
// open history dialog
this.dialogService.open(CredentialGeneratorHistoryDialogComponent);

Check warning on line 61 in apps/desktop/src/vault/app/vault/credential-generator-dialog.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/desktop/src/vault/app/vault/credential-generator-dialog.component.ts#L61

Added line #L61 was not covered by tests
};

static open = (dialogService: DialogService, data: CredentialGeneratorParams) => {
dialogService.open(CredentialGeneratorDialogComponent, {

Check warning on line 65 in apps/desktop/src/vault/app/vault/credential-generator-dialog.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/desktop/src/vault/app/vault/credential-generator-dialog.component.ts#L64-L65

Added lines #L64 - L65 were not covered by tests
data,
});
};
}
28 changes: 25 additions & 3 deletions apps/desktop/src/vault/app/vault/vault.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
import { EventCollectionService } from "@bitwarden/common/abstractions/event/event-collection.service";
import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abstractions/account/billing-account-profile-state.service";
import { EventType } from "@bitwarden/common/enums";
import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";

Check warning on line 23 in apps/desktop/src/vault/app/vault/vault.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/desktop/src/vault/app/vault/vault.component.ts#L23

Added line #L23 was not covered by tests
import { BroadcasterService } from "@bitwarden/common/platform/abstractions/broadcaster.service";
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";

Check warning on line 25 in apps/desktop/src/vault/app/vault/vault.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/desktop/src/vault/app/vault/vault.component.ts#L25

Added line #L25 was not covered by tests
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
Expand All @@ -40,6 +42,7 @@
import { AddEditComponent } from "./add-edit.component";
import { AttachmentsComponent } from "./attachments.component";
import { CollectionsComponent } from "./collections.component";
import { CredentialGeneratorDialogComponent } from "./credential-generator-dialog.component";

Check warning on line 45 in apps/desktop/src/vault/app/vault/vault.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/desktop/src/vault/app/vault/vault.component.ts#L45

Added line #L45 was not covered by tests
import { FolderAddEditComponent } from "./folder-add-edit.component";
import { PasswordHistoryComponent } from "./password-history.component";
import { ShareComponent } from "./share.component";
Expand Down Expand Up @@ -107,6 +110,7 @@
private apiService: ApiService,
private dialogService: DialogService,
private billingAccountProfileStateService: BillingAccountProfileStateService,
private configService: ConfigService,

Check warning on line 113 in apps/desktop/src/vault/app/vault/vault.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/desktop/src/vault/app/vault/vault.component.ts#L113

Added line #L113 was not covered by tests
) {}

async ngOnInit() {
Expand Down Expand Up @@ -622,11 +626,29 @@
}

async openGenerator(comingFromAddEdit: boolean, passwordType = true) {
// FIXME: Will need to be extended to use the cipher-form-generator component introduced with https://github.com/bitwarden/clients/pull/11350
if (this.modal != null) {
this.modal.close();
const isGeneratorSwapEnabled = await this.configService.getFeatureFlag(

Check warning on line 629 in apps/desktop/src/vault/app/vault/vault.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/desktop/src/vault/app/vault/vault.component.ts#L629

Added line #L629 was not covered by tests
FeatureFlag.GeneratorToolsModernization,
);

if (isGeneratorSwapEnabled) {
CredentialGeneratorDialogComponent.open(this.dialogService, {

Check warning on line 634 in apps/desktop/src/vault/app/vault/vault.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/desktop/src/vault/app/vault/vault.component.ts#L634

Added line #L634 was not covered by tests
onCredentialGenerated: (value?: string) => {
if (this.addEditComponent != null) {
this.addEditComponent.markPasswordAsDirty();

Check warning on line 637 in apps/desktop/src/vault/app/vault/vault.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/desktop/src/vault/app/vault/vault.component.ts#L637

Added line #L637 was not covered by tests
if (passwordType) {
this.addEditComponent.cipher.login.password = value ?? "";
} else {
this.addEditComponent.cipher.login.username = value ?? "";
}
}
},
type: passwordType ? "password" : "username",
});
return;

Check warning on line 647 in apps/desktop/src/vault/app/vault/vault.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/desktop/src/vault/app/vault/vault.component.ts#L647

Added line #L647 was not covered by tests
}

// TODO: Legacy code below, remove once the new generator is fully implemented
// https://bitwarden.atlassian.net/browse/PM-7121
const cipher = this.addEditComponent?.cipher;
const loginType = cipher != null && cipher.type === CipherType.Login && cipher.login != null;

Expand Down
Loading