Skip to content
This repository has been archived by the owner on Oct 16, 2023. It is now read-only.

tweak: enhance delete confirm dialog #318

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<mat-form-field class="form-field--full-width">
<label for="">
{{message}}
</label>
<input type="text" matInput [formControl]="control">
<mat-hint *ngIf="control.touched && control.dirty && noMatch$ | async">
Name doesn't match
</mat-hint>
</mat-form-field>
<mat-dialog-actions class="actions">
<button data-cy="dialog-btn-cancel" class="btn btn-secondary btn-sm" matDialogClose>Cancel</button>
<button data-cy="dialog-btn-delete" class="btn btn-danger btn-sm" [disabled]="noMatch$ | async" (click)="confirmDelete()">Delete</button>
</mat-dialog-actions>

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.actions{
display: flex;
flex-direction: row;
justify-content: space-around;
}

.form-field--full-width{
width: 100%;
}
Comment on lines +1 to +9
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually these are a bit redundant as we can use bootstrap utility classes flex-row justify-content-around and w-100 for this purpose

Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { CommonModule } from '@angular/common';
import { Component, Inject, NgModule } from '@angular/core';
import { FormControl, ReactiveFormsModule } from '@angular/forms';
import { MAT_DIALOG_DATA, MatDialogModule, MatDialogRef, MatFormFieldModule, MatInputModule } from '@angular/material';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { Observable } from 'rxjs';
import { map, startWith } from 'rxjs/operators';

@Component({
selector: 'wt-confirm-delete-dialog',
templateUrl: './confirm-delete-dialog.component.html',
styleUrls: ['./confirm-delete-dialog.component.scss']
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh and I missed setting change detection to OnPush (I usually have it configured as the default strategy)

})
export class ConfirmDeleteDialogComponent {

public control: FormControl = new FormControl();
public message!: string;
public noMatch$: Observable<boolean> = this.control.valueChanges.pipe(startWith([undefined]), map(value => value !== this.data.runName));

constructor(@Inject(MAT_DIALOG_DATA) private data: {runName: string}, private dialogRef: MatDialogRef<ConfirmDeleteDialogComponent>) {
this.message = `Please confirm the deletion of the workflow '${data.runName}' typing its name below (operation is not recoverable):`
}

public confirmDelete(): void {
this.dialogRef.close(true);
}
}


@NgModule({
imports: [
CommonModule,
MatDialogModule,
NoopAnimationsModule,
ReactiveFormsModule,
MatInputModule,
MatFormFieldModule
],
declarations: [ConfirmDeleteDialogComponent],
exports: [ConfirmDeleteDialogComponent, MatDialogModule]
})
export class ConfirmDeleteDialogModule{

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ import {WorkflowService} from "src/app/modules/main/service/workflow.service";
import {AuthService} from "src/app/modules/main/service/auth.service";
import {NotificationService} from "src/app/modules/main/service/notification.service";
import { ActivatedRoute, Router, NavigationEnd, Params } from '@angular/router';
import {debounceTime, distinctUntilChanged, filter} from 'rxjs/operators';
import {debounceTime, distinctUntilChanged, filter, takeUntil} from 'rxjs/operators';
import {FormControl} from "@angular/forms";
import {FilteringParams} from "../../util/filtering-params";

import { Subject } from 'rxjs';
import { MatDialog } from '@angular/material/dialog';
import { ConfirmDeleteDialogComponent} from '../confirm-delete-dialog/confirm-delete-dialog.component';
declare let $: any;

@Component({
Expand All @@ -28,6 +30,8 @@ declare let $: any;
})
export class SidebarComponent implements OnInit, OnDestroy, OnChanges {

private destroy$ = new Subject<void>();

@Input()
workflows: Workflow[];

Expand Down Expand Up @@ -55,7 +59,8 @@ export class SidebarComponent implements OnInit, OnDestroy, OnChanges {
private authService: AuthService,
private workflowService: WorkflowService,
private router: Router,
private route: ActivatedRoute) {}
private route: ActivatedRoute,
private dialog: MatDialog) {}


ngOnInit() {
Expand Down Expand Up @@ -94,6 +99,7 @@ export class SidebarComponent implements OnInit, OnDestroy, OnChanges {
ngOnDestroy(): void {
// TODO: Decide if this line required or not. It breaks routing.
// this.router.navigate(['/']);
this.destroy$.next();
}

collapseSidebar(): void {
Expand Down Expand Up @@ -144,13 +150,24 @@ export class SidebarComponent implements OnInit, OnDestroy, OnChanges {
}

deleteWorkflow(workflow: Workflow): void {
const confirm = prompt(`Please confirm the deletion of the workflow '${workflow.data.runName}' typing its name below (operation is not recoverable):`);
if (confirm != workflow.data.runName) {
return;
}

this.workflowToDelete = workflow;
this.onDeleteWorkflow.next(workflow);
this.dialog.open(ConfirmDeleteDialogComponent, {
data: {
runName: workflow.data.runName
},
maxWidth: '90%',
width: '300px',
Comment on lines +158 to +159
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These could also be provided as default using the MAT_DIALOG_DEFAULT_OPTIONS DI token if needed & specified by the design system, allowing for less boilerplate.

hasBackdrop: true,
disableClose: true
}).afterClosed()
.pipe(takeUntil(this.destroy$)).subscribe(
confirmDelete => {
if(confirmDelete){
this.workflowToDelete = workflow;
this.onDeleteWorkflow.next(workflow);
}
}
);
}

}
2 changes: 2 additions & 0 deletions tower-web/src/app/modules/main/main.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import { TreeListComponent } from "./component/tree-list/TreeListComponent";
import { WorkflowStatusIconComponent } from "../../workflow-status-icon/workflow-status-icon.component";
import { TaskDetailsComponent } from "./component/task-details/task-details.component";
import {AppConfigService} from './service/app-config.service';
import { ConfirmDeleteDialogModule } from './component/confirm-delete-dialog/confirm-delete-dialog.component';

/*
* Main application routing strategy
Expand Down Expand Up @@ -118,6 +119,7 @@ const appInitializerFn = (appConfig: AppConfigService) => {
FormsModule,
ChartistModule,
ReactiveFormsModule,
ConfirmDeleteDialogModule
],
providers: [
AppConfigService,
Expand Down