From 83587ca0226479c2dc2cd73a014f0a0b2098d5c5 Mon Sep 17 00:00:00 2001 From: jaasen-livefront Date: Thu, 12 Sep 2024 13:50:58 -0700 Subject: [PATCH] fix send text details form --- .../src/utils/extension-refresh-swap.ts | 1 + .../src/tools/send/models/view/send.view.ts | 1 + .../base-send-details.component.ts | 10 +-- .../send-details/send-details.component.html | 1 + .../send-details/send-details.component.ts | 7 +- .../send-text-details.component.html | 20 ++--- .../send-text-details.component.ts | 80 ++++++++++++++++++- .../src/send-form/send-form-container.ts | 2 + 8 files changed, 98 insertions(+), 24 deletions(-) diff --git a/libs/angular/src/utils/extension-refresh-swap.ts b/libs/angular/src/utils/extension-refresh-swap.ts index 6512be032d2..1f5433feab8 100644 --- a/libs/angular/src/utils/extension-refresh-swap.ts +++ b/libs/angular/src/utils/extension-refresh-swap.ts @@ -23,6 +23,7 @@ export function extensionRefreshSwap( defaultComponent, refreshedComponent, async () => { + return true; const configService = inject(ConfigService); return configService.getFeatureFlag(FeatureFlag.ExtensionRefresh); }, diff --git a/libs/common/src/tools/send/models/view/send.view.ts b/libs/common/src/tools/send/models/view/send.view.ts index 451a15d4142..07e579d4e85 100644 --- a/libs/common/src/tools/send/models/view/send.view.ts +++ b/libs/common/src/tools/send/models/view/send.view.ts @@ -26,6 +26,7 @@ export class SendView implements View { password: string = null; disabled = false; hideEmail = false; + hideText = false; constructor(s?: Send) { if (!s) { diff --git a/libs/tools/send/send-ui/src/send-form/components/send-details/base-send-details.component.ts b/libs/tools/send/send-ui/src/send-form/components/send-details/base-send-details.component.ts index 52ea4c90f3d..4751775b7fe 100644 --- a/libs/tools/send/send-ui/src/send-form/components/send-details/base-send-details.component.ts +++ b/libs/tools/send/send-ui/src/send-form/components/send-details/base-send-details.component.ts @@ -9,10 +9,10 @@ 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 interface BaseSendDetailsForm { +export type BaseSendDetailsForm = FormGroup<{ name: FormControl; selectedDeletionDatePreset: FormControl; -} +}>; // Value = hours export enum DatePreset { @@ -36,9 +36,9 @@ export interface DatePresetSelectOption { }) export class BaseSendDetailsComponent implements OnInit { @Input() config: SendFormConfig; - @Input() originalSendView: SendView; + @Input() originalSendView?: SendView; - sendDetailsForm: FormGroup; + sendDetailsForm: BaseSendDetailsForm; customDeletionDateOption: DatePresetSelectOption | null = null; datePresetOptions: DatePresetSelectOption[] = []; @@ -52,7 +52,7 @@ export class BaseSendDetailsComponent implements OnInit { this.sendDetailsForm = this.formBuilder.group({ name: new FormControl("", Validators.required), selectedDeletionDatePreset: new FormControl(DatePreset.SevenDays || "", Validators.required), - }) as FormGroup; + }); this.sendDetailsForm.valueChanges.pipe(takeUntilDestroyed()).subscribe((value) => { this.sendFormContainer.patchSend((send) => { diff --git a/libs/tools/send/send-ui/src/send-form/components/send-details/send-details.component.html b/libs/tools/send/send-ui/src/send-form/components/send-details/send-details.component.html index 27b6833bc6e..e1f3f4f0d9f 100644 --- a/libs/tools/send/send-ui/src/send-form/components/send-details/send-details.component.html +++ b/libs/tools/send/send-ui/src/send-form/components/send-details/send-details.component.html @@ -13,6 +13,7 @@ *ngIf="config.sendType === TextSendType" [config]="config" [originalSendView]="originalSendView" + [sendDetailsForm]="sendDetailsForm" > diff --git a/libs/tools/send/send-ui/src/send-form/components/send-details/send-details.component.ts b/libs/tools/send/send-ui/src/send-form/components/send-details/send-details.component.ts index 4abb7e2e867..9fec6ff9b2b 100644 --- a/libs/tools/send/send-ui/src/send-form/components/send-details/send-details.component.ts +++ b/libs/tools/send/send-ui/src/send-form/components/send-details/send-details.component.ts @@ -1,11 +1,10 @@ import { CommonModule, DatePipe } from "@angular/common"; -import { Component, Input, OnInit } from "@angular/core"; +import { Component, OnInit } from "@angular/core"; import { FormBuilder, ReactiveFormsModule } from "@angular/forms"; import { JslibModule } from "@bitwarden/angular/jslib.module"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { SendType } from "@bitwarden/common/tools/send/enums/send-type"; -import { SendView } from "@bitwarden/common/tools/send/models/view/send.view"; import { SectionComponent, SectionHeaderComponent, @@ -17,7 +16,6 @@ import { SelectModule, } from "@bitwarden/components"; -import { SendFormConfig } from "../../abstractions/send-form-config.service"; import { SendFormContainer } from "../../send-form-container"; import { BaseSendDetailsComponent } from "./base-send-details.component"; @@ -43,9 +41,6 @@ import { SendTextDetailsComponent } from "./send-text-details.component"; ], }) export class SendDetailsComponent extends BaseSendDetailsComponent implements OnInit { - @Input() config: SendFormConfig; - @Input() originalSendView: SendView; - FileSendType = SendType.File; TextSendType = SendType.Text; diff --git a/libs/tools/send/send-ui/src/send-form/components/send-details/send-text-details.component.html b/libs/tools/send/send-ui/src/send-form/components/send-details/send-text-details.component.html index a774eb398b3..f3e8d73feff 100644 --- a/libs/tools/send/send-ui/src/send-form/components/send-details/send-text-details.component.html +++ b/libs/tools/send/send-ui/src/send-form/components/send-details/send-text-details.component.html @@ -1,9 +1,11 @@ - - {{ "sendTypeTextToShare" | i18n }} - - {{ "sendTextDesc" | i18n }} - - - - {{ "hideTextByDefault" | i18n }} - + + + {{ "sendTypeTextToShare" | i18n }} + + {{ "sendTextDesc" | i18n }} + + + + {{ "hideTextByDefault" | i18n }} + + diff --git a/libs/tools/send/send-ui/src/send-form/components/send-details/send-text-details.component.ts b/libs/tools/send/send-ui/src/send-form/components/send-details/send-text-details.component.ts index a843b99655f..acc27482786 100644 --- a/libs/tools/send/send-ui/src/send-form/components/send-details/send-text-details.component.ts +++ b/libs/tools/send/send-ui/src/send-form/components/send-details/send-text-details.component.ts @@ -1,15 +1,87 @@ -import { Component, Input } from "@angular/core"; +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, +} from "@angular/forms"; +import { JslibModule } from "@bitwarden/angular/jslib.module"; import { SendView } from "@bitwarden/common/tools/send/models/view/send.view"; +import { CheckboxModule, 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 BaseSendTextDetailsForm = FormGroup<{ + text: FormControl; + hidden: FormControl; +}>; + +export type SendTextDetailsForm = BaseSendTextDetailsForm & BaseSendDetailsForm; @Component({ selector: "tools-send-text-details", - template: "send-text-details.component.html", + templateUrl: "./send-text-details.component.html", standalone: true, + imports: [ + CheckboxModule, + CommonModule, + JslibModule, + ReactiveFormsModule, + FormFieldModule, + SectionComponent, + ], }) -export class SendTextDetailsComponent { +export class SendTextDetailsComponent implements OnInit { @Input() config: SendFormConfig; - @Input() originalSendView: SendView; + @Input() originalSendView?: SendView; + @Input() sendDetailsForm: BaseSendDetailsForm; + + baseSendTextDetailsForm: BaseSendTextDetailsForm; + sendTextDetailsForm: SendTextDetailsForm; + + constructor( + private formBuilder: FormBuilder, + protected sendFormContainer: SendFormContainer, + ) { + // Subscribe to form value changes and update the parent SendView accordingly + this.sendTextDetailsForm.valueChanges.pipe(takeUntilDestroyed()).subscribe((value) => { + this.sendFormContainer.patchSend((send) => { + // Update the send object with the form values + return Object.assign(send, { + text: { + text: value.text, + hidden: value.hidden, + }, + }); + }); + }); + } + + ngOnInit() { + // Define the nested form group for `text` + this.baseSendTextDetailsForm = this.formBuilder.group({ + text: new FormControl("", Validators.required), + hidden: new FormControl(false), + }); + + this.sendTextDetailsForm = Object.assign(this.baseSendTextDetailsForm, this.sendDetailsForm); + + // Register this form with the parent form + this.sendFormContainer.registerChildForm("sendTextDetailsForm", this.sendTextDetailsForm); + + // If editing or cloning an existing SendView, populate the form + if (this.originalSendView) { + this.baseSendTextDetailsForm.patchValue({ + text: this.originalSendView.text?.text || "", + hidden: this.originalSendView.text?.hidden || false, + }); + } + } } diff --git a/libs/tools/send/send-ui/src/send-form/send-form-container.ts b/libs/tools/send/send-ui/src/send-form/send-form-container.ts index 7ddd6c91177..f3af1ecd816 100644 --- a/libs/tools/send/send-ui/src/send-form/send-form-container.ts +++ b/libs/tools/send/send-ui/src/send-form/send-form-container.ts @@ -2,12 +2,14 @@ import { SendView } from "@bitwarden/common/tools/send/models/view/send.view"; import { SendFormConfig } from "./abstractions/send-form-config.service"; import { SendDetailsComponent } from "./components/send-details/send-details.component"; +import { SendTextDetailsForm } from "./components/send-details/send-text-details.component"; /** * The complete form for a send. Includes all the sub-forms from their respective section components. * TODO: Add additional form sections as they are implemented. */ export type SendForm = { sendDetailsForm?: SendDetailsComponent["sendDetailsForm"]; + sendTextDetailsForm?: SendTextDetailsForm; }; /**