From e7c3b20cbc3831867be1f3ed35327e87d72172ef Mon Sep 17 00:00:00 2001 From: Lucho Date: Tue, 7 Jan 2025 13:19:14 -0300 Subject: [PATCH 1/3] PLAN-1908: Create treatment dialog --- .../create-scenarios.component.html | 2 +- .../create-scenarios.component.ts | 21 ++++++-- .../create-treatment-dialog.component.html | 21 ++++++++ .../create-treatment-dialog.component.scss | 19 ++++++++ .../create-treatment-dialog.component.spec.ts | 35 ++++++++++++++ .../create-treatment-dialog.component.ts | 48 +++++++++++++++++++ 6 files changed, 142 insertions(+), 4 deletions(-) create mode 100644 src/interface/src/app/plan/create-scenarios/create-treatment-dialog/create-treatment-dialog.component.html create mode 100644 src/interface/src/app/plan/create-scenarios/create-treatment-dialog/create-treatment-dialog.component.scss create mode 100644 src/interface/src/app/plan/create-scenarios/create-treatment-dialog/create-treatment-dialog.component.spec.ts create mode 100644 src/interface/src/app/plan/create-scenarios/create-treatment-dialog/create-treatment-dialog.component.ts diff --git a/src/interface/src/app/plan/create-scenarios/create-scenarios.component.html b/src/interface/src/app/plan/create-scenarios/create-scenarios.component.html index 6411de5a4..437979c57 100644 --- a/src/interface/src/app/plan/create-scenarios/create-scenarios.component.html +++ b/src/interface/src/app/plan/create-scenarios/create-scenarios.component.html @@ -113,7 +113,7 @@ icon="add" class="new-treatment" [disabled]="creatingTreatment" - (click)="createTreatment()"> + (click)="openTreatmentDialog()"> New Treatment Plan diff --git a/src/interface/src/app/plan/create-scenarios/create-scenarios.component.ts b/src/interface/src/app/plan/create-scenarios/create-scenarios.component.ts index 70c4f3235..9c07a1073 100644 --- a/src/interface/src/app/plan/create-scenarios/create-scenarios.component.ts +++ b/src/interface/src/app/plan/create-scenarios/create-scenarios.component.ts @@ -24,6 +24,8 @@ import { MetricsService } from '@services/metrics.service'; import { processScenarioResultsToChartData } from '../scenario-helpers'; import { TreatmentsService } from '@services/treatments.service'; import { canAddTreatmentPlan } from '../permissions'; +import { MatDialog } from '@angular/material/dialog'; +import { CreateTreatmentDialogComponent } from './create-treatment-dialog/create-treatment-dialog.component'; enum ScenarioTabs { CONFIG, @@ -84,7 +86,8 @@ export class CreateScenariosComponent implements OnInit { private featureService: FeatureService, private goalOverlayService: GoalOverlayService, private metricsService: MetricsService, - private treatmentsService: TreatmentsService + private treatmentsService: TreatmentsService, + private dialog: MatDialog ) {} createForms() { @@ -353,7 +356,19 @@ export class CreateScenariosComponent implements OnInit { return this.showTreatmentsTab && !!plan && canAddTreatmentPlan(plan); } - createTreatment() { + openTreatmentDialog() { + this.dialog + .open(CreateTreatmentDialogComponent) + .afterClosed() + .pipe(take(1)) + .subscribe((name) => { + if (name) { + this.createTreatment(name); + } + }); + } + + createTreatment(name: string) { this.creatingTreatment = true; const scenarioId = this.scenarioId; if (!scenarioId) { @@ -361,7 +376,7 @@ export class CreateScenariosComponent implements OnInit { } this.treatmentsService - .createTreatmentPlan(Number(scenarioId), 'New Treatment Plan') + .createTreatmentPlan(Number(scenarioId), name) .subscribe({ next: (result) => { this.goToTreatment(result.id); diff --git a/src/interface/src/app/plan/create-scenarios/create-treatment-dialog/create-treatment-dialog.component.html b/src/interface/src/app/plan/create-scenarios/create-treatment-dialog/create-treatment-dialog.component.html new file mode 100644 index 000000000..a6a9408db --- /dev/null +++ b/src/interface/src/app/plan/create-scenarios/create-treatment-dialog/create-treatment-dialog.component.html @@ -0,0 +1,21 @@ +

Name your treatment

+
+ + + Name + + + + Treatment name is required. + + + + + + +
\ No newline at end of file diff --git a/src/interface/src/app/plan/create-scenarios/create-treatment-dialog/create-treatment-dialog.component.scss b/src/interface/src/app/plan/create-scenarios/create-treatment-dialog/create-treatment-dialog.component.scss new file mode 100644 index 000000000..32c9feecb --- /dev/null +++ b/src/interface/src/app/plan/create-scenarios/create-treatment-dialog/create-treatment-dialog.component.scss @@ -0,0 +1,19 @@ +:host { + display: block; +} + +mat-form-field { + min-width: 480px; +} + +.name-field { + margin-top: 32px; +} + +.title { + margin: 24px 24px 0; +} + +mat-dialog-actions { + padding: 0 24px 16px; +} \ No newline at end of file diff --git a/src/interface/src/app/plan/create-scenarios/create-treatment-dialog/create-treatment-dialog.component.spec.ts b/src/interface/src/app/plan/create-scenarios/create-treatment-dialog/create-treatment-dialog.component.spec.ts new file mode 100644 index 000000000..ae16bc1d7 --- /dev/null +++ b/src/interface/src/app/plan/create-scenarios/create-treatment-dialog/create-treatment-dialog.component.spec.ts @@ -0,0 +1,35 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { CreateTreatmentDialogComponent } from './create-treatment-dialog.component'; +import { CommonModule } from '@angular/common'; +import { ReactiveFormsModule } from '@angular/forms'; +import { MatDialogRef } from '@angular/material/dialog'; +import { LegacyMaterialModule } from 'src/app/material/legacy-material.module'; +import { MockProvider } from 'ng-mocks'; +import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; + +describe('CreateTreatmentDialogComponent', () => { + let component: CreateTreatmentDialogComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [ + CreateTreatmentDialogComponent, + CommonModule, + ReactiveFormsModule, + LegacyMaterialModule, + BrowserAnimationsModule, + ], + providers: [MockProvider(MatDialogRef)], + }).compileComponents(); + + fixture = TestBed.createComponent(CreateTreatmentDialogComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/interface/src/app/plan/create-scenarios/create-treatment-dialog/create-treatment-dialog.component.ts b/src/interface/src/app/plan/create-scenarios/create-treatment-dialog/create-treatment-dialog.component.ts new file mode 100644 index 000000000..8e37c474e --- /dev/null +++ b/src/interface/src/app/plan/create-scenarios/create-treatment-dialog/create-treatment-dialog.component.ts @@ -0,0 +1,48 @@ +import { CommonModule } from '@angular/common'; +import { Component } from '@angular/core'; +import { + FormControl, + FormGroup, + ReactiveFormsModule, + Validators, +} from '@angular/forms'; +import { MatDialogModule, MatDialogRef } from '@angular/material/dialog'; +import { LegacyMaterialModule } from 'src/app/material/legacy-material.module'; + +@Component({ + selector: 'app-create-treatment-dialog', + standalone: true, + imports: [ + CommonModule, + ReactiveFormsModule, + MatDialogModule, + LegacyMaterialModule, + ], + templateUrl: './create-treatment-dialog.component.html', + styleUrl: './create-treatment-dialog.component.scss', +}) +export class CreateTreatmentDialogComponent { + submitting: boolean = false; + treatmentForm = new FormGroup({ + treatmentName: new FormControl('', [Validators.required]), + }); + + constructor( + private dialogRef: MatDialogRef + ) {} + + async submit() { + if (this.treatmentForm.valid) { + this.submitting = true; + const treatmentName = + this.treatmentForm.get('treatmentName')?.value || ''; + this.dialogRef.close(treatmentName); + this.submitting = false; + } + } + + cancel(): void { + this.submitting = false; + this.dialogRef.close(); + } +} From a72804d840c2f486146599de2a857926f3b398fd Mon Sep 17 00:00:00 2001 From: Lucho Date: Tue, 7 Jan 2025 13:24:16 -0300 Subject: [PATCH 2/3] PLAN-1908: Create treatment dialog --- .../create-treatment-dialog.component.html | 52 ++++++++++++------- 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/src/interface/src/app/plan/create-scenarios/create-treatment-dialog/create-treatment-dialog.component.html b/src/interface/src/app/plan/create-scenarios/create-treatment-dialog/create-treatment-dialog.component.html index a6a9408db..ba0a49866 100644 --- a/src/interface/src/app/plan/create-scenarios/create-treatment-dialog/create-treatment-dialog.component.html +++ b/src/interface/src/app/plan/create-scenarios/create-treatment-dialog/create-treatment-dialog.component.html @@ -1,21 +1,35 @@

Name your treatment

- - - Name - - - - Treatment name is required. - - - - - - -
\ No newline at end of file + + + Name + + + + Treatment name is required. + + + + + + + From a9b5694af3532487cd342cddfd20a375687b1c74 Mon Sep 17 00:00:00 2001 From: Lucho Date: Tue, 7 Jan 2025 14:04:59 -0300 Subject: [PATCH 3/3] PLAN-1908: Copy change from Jordan --- .../create-treatment-dialog.component.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/interface/src/app/plan/create-scenarios/create-treatment-dialog/create-treatment-dialog.component.html b/src/interface/src/app/plan/create-scenarios/create-treatment-dialog/create-treatment-dialog.component.html index ba0a49866..02b9705bc 100644 --- a/src/interface/src/app/plan/create-scenarios/create-treatment-dialog/create-treatment-dialog.component.html +++ b/src/interface/src/app/plan/create-scenarios/create-treatment-dialog/create-treatment-dialog.component.html @@ -1,4 +1,4 @@ -

Name your treatment

+

Name Your Treatment Plan