From 3af758de94b62d6be591e72c35f83282023dbdcb Mon Sep 17 00:00:00 2001 From: Yagnik Date: Thu, 27 Jun 2024 14:34:04 +0530 Subject: [PATCH] replace delete metric component with common delete component dialogue --- .../components/metrics/metrics.component.ts | 13 ++++-- .../delete-metrics.component.html | 31 -------------- .../delete-metrics.component.scss | 21 ---------- .../delete-metrics.component.spec.ts | 40 ------------------- .../delete-metrics.component.ts | 28 ------------- .../dashboard/profile/profile.module.ts | 2 - .../components/delete/delete.component.html | 2 +- .../components/delete/delete.component.ts | 11 +++-- 8 files changed, 15 insertions(+), 133 deletions(-) delete mode 100644 frontend/projects/upgrade/src/app/features/dashboard/profile/components/modals/delete-metrics/delete-metrics.component.html delete mode 100644 frontend/projects/upgrade/src/app/features/dashboard/profile/components/modals/delete-metrics/delete-metrics.component.scss delete mode 100644 frontend/projects/upgrade/src/app/features/dashboard/profile/components/modals/delete-metrics/delete-metrics.component.spec.ts delete mode 100644 frontend/projects/upgrade/src/app/features/dashboard/profile/components/modals/delete-metrics/delete-metrics.component.ts diff --git a/frontend/projects/upgrade/src/app/features/dashboard/profile/components/metrics/metrics.component.ts b/frontend/projects/upgrade/src/app/features/dashboard/profile/components/metrics/metrics.component.ts index 132bb4cc0f..82b7015960 100644 --- a/frontend/projects/upgrade/src/app/features/dashboard/profile/components/metrics/metrics.component.ts +++ b/frontend/projects/upgrade/src/app/features/dashboard/profile/components/metrics/metrics.component.ts @@ -9,17 +9,17 @@ import { } from '@angular/core'; import { UserPermission } from '../../../../../core/auth/store/auth.models'; import { BehaviorSubject, Subscription } from 'rxjs'; -import { MetricUnit } from '../../../../../core/analysis/store/analysis.models'; +import { METRICS_JOIN_TEXT, MetricUnit } from '../../../../../core/analysis/store/analysis.models'; import { NestedTreeControl } from '@angular/cdk/tree'; import { MatTreeNestedDataSource } from '@angular/material/tree'; import { MatDialog } from '@angular/material/dialog'; import { MatTableDataSource } from '@angular/material/table'; import { AnalysisService } from '../../../../../core/analysis/analysis.service'; import { AuthService } from '../../../../../core/auth/auth.service'; -import { DeleteMetricsComponent } from '../modals/delete-metrics/delete-metrics.component'; import { AddMetricsComponent } from '../modals/add-metrics/add-metrics.component'; import { METRIC_SEARCH_KEY } from '../../../../../../../../../../types/src/Experiment/enums'; import { IMetricUnit } from '../../../../../../../../../../types/src'; +import { DeleteComponent } from '../../../../../shared/components/delete/delete.component'; @Component({ selector: 'profile-metrics', @@ -108,9 +108,14 @@ export class MetricsComponent implements OnInit, OnDestroy, AfterViewInit { }; const key = this.analysisService.findParents(data, nodeToBeDeleted.id); this.selectedMetricIndex = null; - this.dialog.open(DeleteMetricsComponent, { + const dialogRef = this.dialog.open(DeleteComponent, { panelClass: 'delete-modal', - data: { key }, + }); + + dialogRef.afterClosed().subscribe((isDeleteButtonClicked) => { + if (isDeleteButtonClicked) { + this.analysisService.deleteMetric(key.join(METRICS_JOIN_TEXT)); + } }); } diff --git a/frontend/projects/upgrade/src/app/features/dashboard/profile/components/modals/delete-metrics/delete-metrics.component.html b/frontend/projects/upgrade/src/app/features/dashboard/profile/components/modals/delete-metrics/delete-metrics.component.html deleted file mode 100644 index 1ad9aa5e9d..0000000000 --- a/frontend/projects/upgrade/src/app/features/dashboard/profile/components/modals/delete-metrics/delete-metrics.component.html +++ /dev/null @@ -1,31 +0,0 @@ -
-

- {{ 'metric.delete-metric.message.text' | translate }} -

- - - -
-
- - -
diff --git a/frontend/projects/upgrade/src/app/features/dashboard/profile/components/modals/delete-metrics/delete-metrics.component.scss b/frontend/projects/upgrade/src/app/features/dashboard/profile/components/modals/delete-metrics/delete-metrics.component.scss deleted file mode 100644 index 9f569caaee..0000000000 --- a/frontend/projects/upgrade/src/app/features/dashboard/profile/components/modals/delete-metrics/delete-metrics.component.scss +++ /dev/null @@ -1,21 +0,0 @@ -.metric-delete-dialog { - .name { - width: 100%; - line-height: 18px; - margin-top: -10px; - padding-bottom: 20px; - - &-input { - line-height: 18px; - } - } - - &-actions { - justify-content: flex-end; - margin: 0; - - .delete-btn { - background-color: var(--red) !important; - } - } -} diff --git a/frontend/projects/upgrade/src/app/features/dashboard/profile/components/modals/delete-metrics/delete-metrics.component.spec.ts b/frontend/projects/upgrade/src/app/features/dashboard/profile/components/modals/delete-metrics/delete-metrics.component.spec.ts deleted file mode 100644 index 4d3b786045..0000000000 --- a/frontend/projects/upgrade/src/app/features/dashboard/profile/components/modals/delete-metrics/delete-metrics.component.spec.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; - -import { DeleteMetricsComponent } from './delete-metrics.component'; -import { TestingModule } from '../../../../../../../testing/testing.module'; -import { AnalysisService } from '../../../../../../core/analysis/analysis.service'; -import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; - -xdescribe('DeleteMetricsComponent', () => { - let component: DeleteMetricsComponent; - let fixture: ComponentFixture; - - const modalData = { - key: ['key1', 'key2'], - }; - - beforeEach(async(() => { - TestBed.configureTestingModule({ - declarations: [DeleteMetricsComponent], - imports: [TestingModule], - providers: [ - AnalysisService, - { provide: MatDialogRef, useValue: {} }, - { - provide: MAT_DIALOG_DATA, - useValue: modalData, - }, - ], - }).compileComponents(); - })); - - beforeEach(() => { - fixture = TestBed.createComponent(DeleteMetricsComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); - - it('should create', () => { - expect(component).toBeTruthy(); - }); -}); diff --git a/frontend/projects/upgrade/src/app/features/dashboard/profile/components/modals/delete-metrics/delete-metrics.component.ts b/frontend/projects/upgrade/src/app/features/dashboard/profile/components/modals/delete-metrics/delete-metrics.component.ts deleted file mode 100644 index 567f7e64c2..0000000000 --- a/frontend/projects/upgrade/src/app/features/dashboard/profile/components/modals/delete-metrics/delete-metrics.component.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { Component, ChangeDetectionStrategy, Inject } from '@angular/core'; -import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; -import { AnalysisService } from '../../../../../../core/analysis/analysis.service'; -import { METRICS_JOIN_TEXT } from '../../../../../../core/analysis/store/analysis.models'; - -@Component({ - selector: 'app-delete-metrics', - templateUrl: './delete-metrics.component.html', - styleUrls: ['./delete-metrics.component.scss'], - changeDetection: ChangeDetectionStrategy.OnPush, -}) -export class DeleteMetricsComponent { - metricName: string; - constructor( - private analysisService: AnalysisService, - public dialogRef: MatDialogRef, - @Inject(MAT_DIALOG_DATA) public data: any - ) {} - - onCancelClick(): void { - this.dialogRef.close(); - } - - deleteMetric() { - this.analysisService.deleteMetric(this.data.key.join(METRICS_JOIN_TEXT)); - this.onCancelClick(); - } -} diff --git a/frontend/projects/upgrade/src/app/features/dashboard/profile/profile.module.ts b/frontend/projects/upgrade/src/app/features/dashboard/profile/profile.module.ts index 8ca0f431ff..0228a4fe28 100644 --- a/frontend/projects/upgrade/src/app/features/dashboard/profile/profile.module.ts +++ b/frontend/projects/upgrade/src/app/features/dashboard/profile/profile.module.ts @@ -8,7 +8,6 @@ import { NewUserComponent } from './components/modals/new-user/new-user.componen import { ProfileInfoComponent } from './components/profile-info/profile-info.component'; import { MetricsComponent } from './components/metrics/metrics.component'; import { AddMetricsComponent } from './components/modals/add-metrics/add-metrics.component'; -import { DeleteMetricsComponent } from './components/modals/delete-metrics/delete-metrics.component'; import { NgJsonEditorModule } from 'ang-jsoneditor'; @NgModule({ @@ -17,7 +16,6 @@ import { NgJsonEditorModule } from 'ang-jsoneditor'; NewUserComponent, ProfileInfoComponent, MetricsComponent, - DeleteMetricsComponent, AddMetricsComponent, ], imports: [CommonModule, ProfileRoutingModule, SharedModule, NgJsonEditorModule], diff --git a/frontend/projects/upgrade/src/app/shared/components/delete/delete.component.html b/frontend/projects/upgrade/src/app/shared/components/delete/delete.component.html index d16fcc022f..d356efeb25 100644 --- a/frontend/projects/upgrade/src/app/shared/components/delete/delete.component.html +++ b/frontend/projects/upgrade/src/app/shared/components/delete/delete.component.html @@ -1,5 +1,5 @@
-

+

{{ 'global.delete-confirmation.message.text' | translate }}

, @Inject(MAT_DIALOG_DATA) public data: any) {} onCancelClick(): void { - this.message = false; - this.dialogRef.close(this.message); + this.isDeleteButtonClicked = false; + this.dialogRef.close(this.isDeleteButtonClicked); } delete(): void { - this.message = true; - this.dialogRef.close(this.message); + this.isDeleteButtonClicked = true; + this.dialogRef.close(this.isDeleteButtonClicked); } }