-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PM-11903] - add file send component (#11132)
* wip - send file details * wip - file send * send file details * fix click on send list container * remove popup code * remove popup code * finalize send file details * address PR feedback. add base form to send form * revert changes to send list items container * revert changes to send list items container --------- Co-authored-by: Daniel James Smith <2670567+djsmith85@users.noreply.github.com>
- Loading branch information
1 parent
2b85392
commit 00f2317
Showing
9 changed files
with
152 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...tools/send/send-ui/src/send-form/components/send-details/send-file-details.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<bit-section [formGroup]="sendFileDetailsForm"> | ||
<div *ngIf="config.mode === 'edit'"> | ||
<div class="tw-text-muted">{{ "file" | i18n }}</div> | ||
<div>{{ originalSendView.file.fileName }}</div> | ||
<div class="tw-text-muted">{{ originalSendView.file.sizeName }}</div> | ||
</div> | ||
<bit-form-field *ngIf="config.mode !== 'edit'"> | ||
<bit-label for="file">{{ "fileToShare" | i18n }}</bit-label> | ||
<button bitButton type="button" buttonType="primary" (click)="fileSelector.click()"> | ||
{{ "chooseFile" | i18n }} | ||
</button> | ||
<span | ||
class="tw-flex tw-items-center tw-pl-3" | ||
[ngClass]="fileName ? 'tw-text-main' : 'tw-text-muted'" | ||
> | ||
{{ fileName || ("noFileChosen" | i18n) }}</span | ||
> | ||
<input | ||
bitInput | ||
#fileSelector | ||
type="file" | ||
formControlName="file" | ||
hidden | ||
(change)="onFileSelected($event)" | ||
/> | ||
<bit-hint> | ||
{{ "maxFileSize" | i18n }} | ||
</bit-hint> | ||
</bit-form-field> | ||
</bit-section> |
92 changes: 92 additions & 0 deletions
92
libs/tools/send/send-ui/src/send-form/components/send-details/send-file-details.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
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 { JslibModule } from "@bitwarden/angular/jslib.module"; | ||
import { SendType } from "@bitwarden/common/tools/send/enums/send-type"; | ||
import { SendFileView } from "@bitwarden/common/tools/send/models/view/send-file.view"; | ||
import { SendView } from "@bitwarden/common/tools/send/models/view/send.view"; | ||
import { ButtonModule, FormFieldModule, SectionComponent } from "@bitwarden/components"; | ||
|
||
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", | ||
standalone: true, | ||
imports: [ | ||
ButtonModule, | ||
CommonModule, | ||
JslibModule, | ||
ReactiveFormsModule, | ||
FormFieldModule, | ||
SectionComponent, | ||
FormsModule, | ||
], | ||
}) | ||
export class SendFileDetailsComponent implements OnInit { | ||
@Input() config: SendFormConfig; | ||
@Input() originalSendView?: SendView; | ||
@Input() sendDetailsForm: BaseSendDetailsForm; | ||
|
||
baseSendFileDetailsForm: BaseSendFileDetailsForm; | ||
sendFileDetailsForm: SendFileDetailsForm; | ||
|
||
FileSendType = SendType.File; | ||
fileName = ""; | ||
|
||
constructor( | ||
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) => { | ||
this.sendFormContainer.patchSend((send) => { | ||
return Object.assign(send, { | ||
file: value.file, | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
onFileSelected = (event: Event): void => { | ||
const file = (event.target as HTMLInputElement).files?.[0]; | ||
if (!file) { | ||
return; | ||
} | ||
this.fileName = file.name; | ||
this.sendFormContainer.onFileSelected(file); | ||
}; | ||
|
||
ngOnInit() { | ||
if (this.originalSendView) { | ||
this.sendFileDetailsForm.patchValue({ | ||
file: this.originalSendView.file, | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters