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

Merged
merged 9 commits into from
Jan 6, 2025
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,72 @@
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

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

export const openCredentialGeneratorDialog = (

Check warning on line 24 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#L24

Added line #L24 was not covered by tests
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need this in the component

static open(dialogService: DialogService, params: CredentialGeneratorParams) {}

and then you reference the static method in the vault component like so

CredentialGeneratorDialogComponent.open()

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gbubemismith Gotcha! I was looking at a slightly different implementation. Should be gtg now.

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

Check warning on line 28 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#L28

Added line #L28 was not covered by tests
data,
});
};

@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 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#L48

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

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

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#L52

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

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

Check warning on line 57 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#L56-L57

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

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

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#L60-L61

Added lines #L60 - L61 were not covered by tests
};

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

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
};

openHistoryDialog = () => {

Check warning on line 68 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#L68

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

Check warning on line 70 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#L70

Added line #L70 was not covered by tests
};
}
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 { openCredentialGeneratorDialog } 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) {
openCredentialGeneratorDialog(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