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-11904] - send options form #11142

Merged
merged 5 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions apps/browser/src/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,9 @@
"notes": {
"message": "Notes"
},
"privateNote": {
"message": "Private note"
},
"note": {
"message": "Note"
},
Expand Down Expand Up @@ -2267,6 +2270,23 @@
"excludedDomainsSavedSuccess": {
"message": "Excluded domain changes saved"
},
"limitSendViews": {
"message": "Limit views"
},
"limitSendViewsHint": {
"message": "No one can view this Send after the limit is reached.",
"description": "Displayed under the limit views field on Send"
},
"limitSendViewsCount": {
"message": "$ACCESSCOUNT$ views left",
"description": "Displayed under the limit views field on Send",
"placeholders": {
"accessCount": {
"content": "$1",
"example": "2"
}
}
},
"send": {
"message": "Send",
"description": "'Send' is a noun and the name of a feature called 'Bitwarden Send'. It should not be translated."
Expand Down Expand Up @@ -2409,6 +2429,10 @@
"message": "Optionally require a password for users to access this Send.",
"description": "'Send' is a noun and the name of a feature called 'Bitwarden Send'. It should not be translated."
},
"sendPasswordDescV2": {
"message": "Require this password to view the Send.",
"description": "'Send' is a noun and the name of a feature called 'Bitwarden Send'. It should not be translated."
},
djsmith85 marked this conversation as resolved.
Show resolved Hide resolved
"sendNotesDesc": {
"message": "Private notes about this Send.",
"description": "'Send' is a noun and the name of a feature called 'Bitwarden Send'. It should not be translated."
Expand Down Expand Up @@ -2514,6 +2538,9 @@
"hideEmail": {
"message": "Hide my email address from recipients."
},
"hideYourEmail": {
"message": "Hide your email address from viewers."
},
"sendOptionsPolicyInEffect": {
"message": "One or more organization policies are affecting your Send options."
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<bit-section [formGroup]="sendOptionsForm">
<bit-section-header>
<h2 class="tw-mt-4" bitTypography="h5">{{ "additionalOptions" | i18n }}</h2>
</bit-section-header>
<bit-card>
<bit-form-field>
<bit-label>{{ "limitSendViews" | i18n }}</bit-label>
<input bitInput type="number" formControlName="maxAccessCount" min="1" />
<bit-hint>{{ "limitSendViewsHint" | i18n }}</bit-hint>
<bit-hint *ngIf="shouldShowCount"
>&nbsp;{{ "limitSendViewsCount" | i18n: viewsLeft }}</bit-hint
>
</bit-form-field>
<bit-form-field>
<bit-label *ngIf="!hasPassword">{{ "password" | i18n }}</bit-label>
<bit-label *ngIf="hasPassword">{{ "newPassword" | i18n }}</bit-label>
<input bitInput type="password" formControlName="password" />
<button type="button" bitIconButton bitSuffix bitPasswordInputToggle></button>
<button type="button" bitIconButton="bwi-refresh" bitSuffix></button>
<bit-hint>{{ "sendPasswordDescV2" | i18n }}</bit-hint>
</bit-form-field>
<bit-form-control>
<input bitCheckbox type="checkbox" formControlName="hideEmail" />
<bit-label>{{ "hideYourEmail" | i18n }}</bit-label>
</bit-form-control>
<bit-form-field>
<bit-label>{{ "privateNote" | i18n }}</bit-label>
<textarea bitInput rows="4" formControlName="notes"></textarea>
</bit-form-field>
</bit-card>
</bit-section>
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import { CommonModule } from "@angular/common";
import { Component, Input, OnInit } from "@angular/core";
import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
import { FormBuilder, ReactiveFormsModule } from "@angular/forms";

Check warning on line 4 in libs/tools/send/send-ui/src/send-form/components/options/send-options.component.ts

View check run for this annotation

Codecov / codecov/patch

libs/tools/send/send-ui/src/send-form/components/options/send-options.component.ts#L1-L4

Added lines #L1 - L4 were not covered by tests

import { JslibModule } from "@bitwarden/angular/jslib.module";
import { SendView } from "@bitwarden/common/tools/send/models/view/send.view";
import {

Check warning on line 8 in libs/tools/send/send-ui/src/send-form/components/options/send-options.component.ts

View check run for this annotation

Codecov / codecov/patch

libs/tools/send/send-ui/src/send-form/components/options/send-options.component.ts#L6-L8

Added lines #L6 - L8 were not covered by tests
CardComponent,
CheckboxModule,
FormFieldModule,
IconButtonModule,
SectionComponent,
SectionHeaderComponent,
TypographyModule,
} from "@bitwarden/components";

import { SendFormConfig } from "../../abstractions/send-form-config.service";
import { SendFormContainer } from "../../send-form-container";

Check warning on line 19 in libs/tools/send/send-ui/src/send-form/components/options/send-options.component.ts

View check run for this annotation

Codecov / codecov/patch

libs/tools/send/send-ui/src/send-form/components/options/send-options.component.ts#L19

Added line #L19 was not covered by tests

@Component({
selector: "tools-send-options",
templateUrl: "./send-options.component.html",
standalone: true,
imports: [
SectionComponent,
SectionHeaderComponent,
TypographyModule,
JslibModule,
CardComponent,
FormFieldModule,
ReactiveFormsModule,
IconButtonModule,
CheckboxModule,
CommonModule,
],
})
export class SendOptionsComponent implements OnInit {

Check warning on line 38 in libs/tools/send/send-ui/src/send-form/components/options/send-options.component.ts

View check run for this annotation

Codecov / codecov/patch

libs/tools/send/send-ui/src/send-form/components/options/send-options.component.ts#L38

Added line #L38 was not covered by tests
@Input({ required: true })
config: SendFormConfig;
@Input()
originalSendView: SendView;
sendOptionsForm = this.formBuilder.group({

Check warning on line 43 in libs/tools/send/send-ui/src/send-form/components/options/send-options.component.ts

View check run for this annotation

Codecov / codecov/patch

libs/tools/send/send-ui/src/send-form/components/options/send-options.component.ts#L43

Added line #L43 was not covered by tests
maxAccessCount: [null as number],
accessCount: [null as number],
notes: [null as string],
password: [null as string],
hideEmail: [false as boolean],
});
get hasPassword(): boolean {
return (

Check warning on line 51 in libs/tools/send/send-ui/src/send-form/components/options/send-options.component.ts

View check run for this annotation

Codecov / codecov/patch

libs/tools/send/send-ui/src/send-form/components/options/send-options.component.ts#L51

Added line #L51 was not covered by tests
this.sendOptionsForm.value.password !== null && this.sendOptionsForm.value.password !== ""
);
}

get shouldShowCount(): boolean {
return this.config.mode === "edit" && this.sendOptionsForm.value.maxAccessCount !== null;
}

get viewsLeft(): number {
return this.sendOptionsForm.value.maxAccessCount
? this.sendOptionsForm.value.maxAccessCount - this.sendOptionsForm.value.accessCount
: 0;
}

constructor(
private sendFormContainer: SendFormContainer,
private formBuilder: FormBuilder,

Check warning on line 68 in libs/tools/send/send-ui/src/send-form/components/options/send-options.component.ts

View check run for this annotation

Codecov / codecov/patch

libs/tools/send/send-ui/src/send-form/components/options/send-options.component.ts#L67-L68

Added lines #L67 - L68 were not covered by tests
) {
this.sendFormContainer.registerChildForm("sendOptionsForm", this.sendOptionsForm);
this.sendOptionsForm.valueChanges.pipe(takeUntilDestroyed()).subscribe((value) => {
this.sendFormContainer.patchSend((send) => {
Object.assign(send, {

Check warning on line 73 in libs/tools/send/send-ui/src/send-form/components/options/send-options.component.ts

View check run for this annotation

Codecov / codecov/patch

libs/tools/send/send-ui/src/send-form/components/options/send-options.component.ts#L70-L73

Added lines #L70 - L73 were not covered by tests
maxAccessCount: value.maxAccessCount,
accessCount: value.accessCount,
password: value.password,
hideEmail: value.hideEmail,
notes: value.notes,
});
return send;

Check warning on line 80 in libs/tools/send/send-ui/src/send-form/components/options/send-options.component.ts

View check run for this annotation

Codecov / codecov/patch

libs/tools/send/send-ui/src/send-form/components/options/send-options.component.ts#L80

Added line #L80 was not covered by tests
});
});
}
ngOnInit() {
if (this.sendFormContainer.originalSendView) {
this.sendOptionsForm.patchValue({

Check warning on line 86 in libs/tools/send/send-ui/src/send-form/components/options/send-options.component.ts

View check run for this annotation

Codecov / codecov/patch

libs/tools/send/send-ui/src/send-form/components/options/send-options.component.ts#L86

Added line #L86 was not covered by tests
maxAccessCount: this.sendFormContainer.originalSendView.maxAccessCount,
accessCount: this.sendFormContainer.originalSendView.accessCount,
password: this.sendFormContainer.originalSendView.password,
hideEmail: this.sendFormContainer.originalSendView.hideEmail,
notes: this.sendFormContainer.originalSendView.notes,
});
}
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
import { DatePipe } from "@angular/common";
import { Component, Input, OnInit } from "@angular/core";
import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
import { FormBuilder, FormGroup, FormControl, Validators } from "@angular/forms";
import { FormBuilder, FormControl, Validators } from "@angular/forms";

Check warning on line 4 in libs/tools/send/send-ui/src/send-form/components/send-details/base-send-details.component.ts

View check run for this annotation

Codecov / codecov/patch

libs/tools/send/send-ui/src/send-form/components/send-details/base-send-details.component.ts#L4

Added line #L4 was not covered by tests

import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { SendView } from "@bitwarden/common/tools/send/models/view/send.view";

import { SendFormConfig } from "../../abstractions/send-form-config.service";
import { SendFormContainer } from "../../send-form-container";

export type BaseSendDetailsForm = FormGroup<{
name: FormControl<string>;
selectedDeletionDatePreset: FormControl<string | number>;
}>;

// Value = hours
export enum DatePreset {
OneHour = 1,
Expand All @@ -38,21 +33,20 @@
@Input() config: SendFormConfig;
@Input() originalSendView?: SendView;

sendDetailsForm: BaseSendDetailsForm;
customDeletionDateOption: DatePresetSelectOption | null = null;
datePresetOptions: DatePresetSelectOption[] = [];

sendDetailsForm = this.formBuilder.group({

Check warning on line 39 in libs/tools/send/send-ui/src/send-form/components/send-details/base-send-details.component.ts

View check run for this annotation

Codecov / codecov/patch

libs/tools/send/send-ui/src/send-form/components/send-details/base-send-details.component.ts#L39

Added line #L39 was not covered by tests
name: new FormControl("", Validators.required),
selectedDeletionDatePreset: new FormControl(DatePreset.SevenDays || "", Validators.required),
});

constructor(
protected sendFormContainer: SendFormContainer,
protected formBuilder: FormBuilder,
protected i18nService: I18nService,
protected datePipe: DatePipe,
) {
this.sendDetailsForm = this.formBuilder.group({
name: new FormControl("", Validators.required),
selectedDeletionDatePreset: new FormControl(DatePreset.SevenDays || "", Validators.required),
});

this.sendDetailsForm.valueChanges.pipe(takeUntilDestroyed()).subscribe((value) => {
this.sendFormContainer.patchSend((send) => {
return Object.assign(send, {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<bit-section [formGroup]="sendDetailsForm">
<bit-section-header>
<bit-section-header class="tw-mt-4">
<h2 bitTypography="h5">{{ "sendDetails" | i18n }}</h2>
</bit-section-header>

Expand All @@ -13,14 +13,12 @@ <h2 bitTypography="h5">{{ "sendDetails" | i18n }}</h2>
*ngIf="config.sendType === TextSendType"
[config]="config"
[originalSendView]="originalSendView"
[sendDetailsForm]="sendDetailsForm"
></tools-send-text-details>

<tools-send-file-details
*ngIf="config.sendType === FileSendType"
[config]="config"
[originalSendView]="originalSendView"
[sendDetailsForm]="sendDetailsForm"
></tools-send-file-details>

<bit-form-field>
Expand All @@ -39,4 +37,5 @@ <h2 bitTypography="h5">{{ "sendDetails" | i18n }}</h2>
<bit-hint>{{ "deletionDateDescV2" | i18n }}</bit-hint>
</bit-form-field>
</bit-card>
<tools-send-options [config]="config" [originalSendView]="originalSendView"></tools-send-options>
</bit-section>
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
} from "@bitwarden/components";

import { SendFormContainer } from "../../send-form-container";
import { SendOptionsComponent } from "../options/send-options.component";

Check warning on line 20 in libs/tools/send/send-ui/src/send-form/components/send-details/send-details.component.ts

View check run for this annotation

Codecov / codecov/patch

libs/tools/send/send-ui/src/send-form/components/send-details/send-details.component.ts#L20

Added line #L20 was not covered by tests

import { BaseSendDetailsComponent } from "./base-send-details.component";
import { SendFileDetailsComponent } from "./send-file-details.component";
Expand All @@ -36,6 +37,7 @@
ReactiveFormsModule,
SendTextDetailsComponent,
SendFileDetailsComponent,
SendOptionsComponent,
IconButtonModule,
CheckboxModule,
CommonModule,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
import { CommonModule } from "@angular/common";
import { Component, Input, OnInit } from "@angular/core";
import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
import {
FormBuilder,
FormControl,
FormGroup,
Validators,
ReactiveFormsModule,
FormsModule,
} from "@angular/forms";
import { FormBuilder, Validators, ReactiveFormsModule, FormsModule } from "@angular/forms";

Check warning on line 4 in libs/tools/send/send-ui/src/send-form/components/send-details/send-file-details.component.ts

View check run for this annotation

Codecov / codecov/patch

libs/tools/send/send-ui/src/send-form/components/send-details/send-file-details.component.ts#L4

Added line #L4 was not covered by tests

import { JslibModule } from "@bitwarden/angular/jslib.module";
import { SendType } from "@bitwarden/common/tools/send/enums/send-type";
Expand All @@ -19,14 +12,6 @@
import { SendFormConfig } from "../../abstractions/send-form-config.service";
import { SendFormContainer } from "../../send-form-container";

import { BaseSendDetailsForm } from "./base-send-details.component";

type BaseSendFileDetailsForm = FormGroup<{
file: FormControl<SendFileView | null>;
}>;

export type SendFileDetailsForm = BaseSendFileDetailsForm & BaseSendDetailsForm;

@Component({
selector: "tools-send-file-details",
templateUrl: "./send-file-details.component.html",
Expand All @@ -44,10 +29,10 @@
export class SendFileDetailsComponent implements OnInit {
@Input() config: SendFormConfig;
@Input() originalSendView?: SendView;
@Input() sendDetailsForm: BaseSendDetailsForm;

baseSendFileDetailsForm: BaseSendFileDetailsForm;
sendFileDetailsForm: SendFileDetailsForm;
sendFileDetailsForm = this.formBuilder.group({

Check warning on line 33 in libs/tools/send/send-ui/src/send-form/components/send-details/send-file-details.component.ts

View check run for this annotation

Codecov / codecov/patch

libs/tools/send/send-ui/src/send-form/components/send-details/send-file-details.component.ts#L33

Added line #L33 was not covered by tests
file: this.formBuilder.control<SendFileView | null>(null, Validators.required),
});

FileSendType = SendType.File;
fileName = "";
Expand All @@ -56,12 +41,6 @@
private formBuilder: FormBuilder,
protected sendFormContainer: SendFormContainer,
) {
this.baseSendFileDetailsForm = this.formBuilder.group({
file: this.formBuilder.control<SendFileView | null>(null, Validators.required),
});

this.sendFileDetailsForm = Object.assign(this.baseSendFileDetailsForm, this.sendDetailsForm);

this.sendFormContainer.registerChildForm("sendFileDetailsForm", this.sendFileDetailsForm);

this.sendFileDetailsForm.valueChanges.pipe(takeUntilDestroyed()).subscribe((value) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<bit-section [formGroup]="sendTextDetailsForm">
<bit-section [formGroup]="sendTextDetailsForm" disableMargin>
<bit-form-field>
<bit-label>{{ "sendTypeTextToShare" | i18n }}</bit-label>
<textarea bitInput id="text" rows="6" formControlName="text"></textarea>
Expand Down
Loading
Loading