Skip to content

Commit

Permalink
feat(console): warning if backdrop click or escape key is pressed whe…
Browse files Browse the repository at this point in the history
…n new action form is dirty (#5989)

* fix: add action control esc and backdrop click

* fix: set values for new action and update action

* feat: add translations for supported languages

* feat: add some comments

* fix: add suggested changes by @peintnermax
  • Loading branch information
doncicuto committed Jun 13, 2023
1 parent e39d1b7 commit 33a8ab4
Show file tree
Hide file tree
Showing 11 changed files with 151 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export class ActionTableComponent implements OnInit {
const dialogRef = this.dialog.open(AddActionDialogComponent, {
data: {},
width: '500px',
disableClose: true,
});

dialogRef.afterClosed().subscribe((req: CreateActionRequest) => {
Expand All @@ -120,6 +121,7 @@ export class ActionTableComponent implements OnInit {
action: action,
},
width: '500px',
disableClose: true,
});

dialogRef.afterClosed().subscribe((req: UpdateActionRequest) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,29 @@
<span *ngIf="id" class="action-dialog-title" mat-dialog-title>{{ 'FLOWS.DIALOG.UPDATE.TITLE' | translate }}</span>

<div mat-dialog-content>
<cnsl-form-field class="form-field">
<cnsl-label>{{ 'FLOWS.NAME' | translate }}</cnsl-label>
<input cnslInput [(ngModel)]="name" />
</cnsl-form-field>
<form [formGroup]="form">
<cnsl-form-field class="form-field">
<cnsl-label>{{ 'FLOWS.NAME' | translate }}</cnsl-label>
<input cnslInput formControlName="name" />
</cnsl-form-field>

<ngx-codemirror
*ngIf="opened$ | async"
[(ngModel)]="script"
[options]="{
lineNumbers: true,
theme: 'material',
mode: 'javascript'
}"
></ngx-codemirror>
<ngx-codemirror
*ngIf="opened$ | async"
formControlName="script"
[options]="{
lineNumbers: true,
theme: 'material',
mode: 'javascript'
}"
></ngx-codemirror>

<cnsl-form-field class="form-field">
<cnsl-label>{{ 'FLOWS.TIMEOUTINSEC' | translate }}</cnsl-label>
<input type="number" cnslInput [(ngModel)]="durationInSec" />
</cnsl-form-field>
<cnsl-form-field class="form-field">
<cnsl-label>{{ 'FLOWS.TIMEOUTINSEC' | translate }}</cnsl-label>
<input type="number" cnslInput formControlName="durationInSec" />
</cnsl-form-field>

<mat-checkbox [(ngModel)]="allowedToFail">{{ 'FLOWS.ALLOWEDTOFAIL' | translate }}</mat-checkbox>
<mat-checkbox formControlName="allowedToFail">{{ 'FLOWS.ALLOWEDTOFAIL' | translate }}</mat-checkbox>
</form>
</div>
<div mat-dialog-actions class="action">
<button *ngIf="id" mat-stroked-button color="warn" (click)="deleteAndCloseDialog()">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Component, Inject } from '@angular/core';
import { Component, Inject, OnInit } from '@angular/core';
import { FormControl, FormGroup } from '@angular/forms';
import {
MatLegacyDialog as MatDialog,
MatLegacyDialogRef as MatDialogRef,
MAT_LEGACY_DIALOG_DATA as MAT_DIALOG_DATA,
} from '@angular/material/legacy-dialog';

import { Duration } from 'google-protobuf/google/protobuf/duration_pb';
import { mapTo } from 'rxjs';
import { WarnDialogComponent } from 'src/app/modules/warn-dialog/warn-dialog.component';
Expand All @@ -17,35 +19,76 @@ import { ToastService } from 'src/app/services/toast.service';
templateUrl: './add-action-dialog.component.html',
styleUrls: ['./add-action-dialog.component.scss'],
})
export class AddActionDialogComponent {
public name: string = '';
public script: string = '';
public durationInSec: number = 10;
public allowedToFail: boolean = false;

export class AddActionDialogComponent implements OnInit {
public id: string = '';

public opened$ = this.dialogRef.afterOpened().pipe(mapTo(true));

public form: FormGroup = new FormGroup({
name: new FormControl<string>('', []),
script: new FormControl<string>('', []),
durationInSec: new FormControl<number>(10, []),
allowedToFail: new FormControl<boolean>(false, []),
});
constructor(
private toast: ToastService,
private mgmtService: ManagementService,
private dialog: MatDialog,
private unsavedChangesDialog: MatDialog,
public dialogRef: MatDialogRef<AddActionDialogComponent>,
@Inject(MAT_DIALOG_DATA) public data: any,
) {
if (data && data.action) {
const action: Action.AsObject = data.action;
this.name = action.name;
this.script = action.script;
if (action.timeout?.seconds) {
this.durationInSec = action.timeout?.seconds;
}
this.allowedToFail = action.allowedToFail;
this.form.setValue({
name: action.name,
script: action.script,
durationInSec: action.timeout?.seconds ?? 10,
allowedToFail: action.allowedToFail,
});
this.id = action.id;
}
}

ngOnInit(): void {
// prevent unsaved changes get lost if backdrop is clicked
this.dialogRef.backdropClick().subscribe(() => {
if (this.form.dirty) {
this.showUnsavedDialog();
} else {
this.dialogRef.close(false);
}
});

// prevent unsaved changes get lost if escape key is pressed
this.dialogRef.keydownEvents().subscribe((event) => {
if (event.key === 'Escape') {
if (this.form.dirty) {
this.showUnsavedDialog();
} else {
this.dialogRef.close(false);
}
}
});
}

private showUnsavedDialog(): void {
const unsavedChangesDialogRef = this.unsavedChangesDialog.open(WarnDialogComponent, {
data: {
confirmKey: 'ACTIONS.UNSAVED.DIALOG.DISCARD',
cancelKey: 'ACTIONS.UNSAVED.DIALOG.CANCEL',
titleKey: 'ACTIONS.UNSAVEDCHANGES',
descriptionKey: 'ACTIONS.UNSAVED.DIALOG.DESCRIPTION',
},
width: '400px',
});

unsavedChangesDialogRef.afterClosed().subscribe((resp) => {
if (resp) {
this.dialogRef.close(false);
}
});
}

public closeDialog(): void {
this.dialogRef.close(false);
}
Expand All @@ -54,27 +97,27 @@ export class AddActionDialogComponent {
if (this.id) {
const req = new UpdateActionRequest();
req.setId(this.id);
req.setName(this.name);
req.setScript(this.script);
req.setName(this.form.value.name);
req.setScript(this.form.value.script);

const duration = new Duration();
duration.setNanos(0);
duration.setSeconds(this.durationInSec);
duration.setSeconds(this.form.value.durationInSec);

req.setAllowedToFail(this.allowedToFail);
req.setAllowedToFail(this.form.value.allowedToFail);

req.setTimeout(duration);
this.dialogRef.close(req);
} else {
const req = new CreateActionRequest();
req.setName(this.name);
req.setScript(this.script);
req.setName(this.form.value.name);
req.setScript(this.form.value.script);

const duration = new Duration();
duration.setNanos(0);
duration.setSeconds(this.durationInSec);
duration.setSeconds(this.form.value.durationInSec);

req.setAllowedToFail(this.allowedToFail);
req.setAllowedToFail(this.form.value.allowedToFail);

req.setTimeout(duration);
this.dialogRef.close(req);
Expand Down
9 changes: 8 additions & 1 deletion console/src/assets/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,14 @@
"NEXT": "Weiter",
"MORE": "mehr",
"STEP": "Schritt",
"COMINGSOON": "Coming soon",
"UNSAVEDCHANGES": "Nicht gespeicherte Änderungen",
"UNSAVED": {
"DIALOG": {
"DESCRIPTION": "Möchten Sie diese neue Aktion wirklich verwerfen? Ihre Aktion geht verloren",
"CANCEL": "Abbrechen",
"DISCARD": "Verwerfen"
}
},
"TABLE": {
"SHOWUSER": "Zeige Benutzer {{value}}"
}
Expand Down
9 changes: 8 additions & 1 deletion console/src/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,14 @@
"MORE": "more",
"STEP": "Step",
"SETUP": "Setup",
"COMINGSOON": "Coming soon",
"UNSAVEDCHANGES": "Unsaved changes",
"UNSAVED": {
"DIALOG": {
"DESCRIPTION": "Are you sure you want to discard this new action? Your action will be lost",
"CANCEL": "Cancel",
"DISCARD": "Discard"
}
},
"TABLE": {
"SHOWUSER": "Show user {{value}}"
}
Expand Down
9 changes: 8 additions & 1 deletion console/src/assets/i18n/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,14 @@
"MORE": "más",
"STEP": "Paso",
"SETUP": "Configurar",
"COMINGSOON": "Próximamente",
"UNSAVEDCHANGES": "Cambios no guardados",
"UNSAVED": {
"DIALOG": {
"DESCRIPTION": "¿Estás seguro de que quieres descartar esta nueva acción? Tu acción se perderá",
"CANCEL": "Cancelar",
"DISCARD": "Descartar"
}
},
"TABLE": {
"SHOWUSER": "Mostrar usuario {{value}}"
}
Expand Down
9 changes: 8 additions & 1 deletion console/src/assets/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,14 @@
"NEXT": "Suivant",
"MORE": "plus",
"STEP": "Étape",
"COMINGSOON": "Coming soon",
"UNSAVEDCHANGES": "Modifications non enregistrées",
"UNSAVED": {
"DIALOG": {
"DESCRIPTION": "Voulez-vous vraiment annuler cette nouvelle action ? Votre action sera perdue",
"CANCEL": "Annuler",
"DISCARD": "Jeter"
}
},
"TABLE": {
"SHOWUSER": "Afficher l'utilisateur{{value}}"
}
Expand Down
8 changes: 7 additions & 1 deletion console/src/assets/i18n/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,13 @@
"NEXT": "Avanti",
"MORE": "azioni",
"STEP": "Passo",
"COMINGSOON": "Coming soon",
"UNSAVED": {
"DIALOG": {
"DESCRIPTION": "Sei sicuro di voler eliminare questa nuova azione? La tua azione andrà persa",
"CANCEL": "Cancella",
"DISCARD": "Continua comunque"
}
},
"TABLE": {
"SHOWUSER": "Mostra utente {{value}}"
}
Expand Down
9 changes: 8 additions & 1 deletion console/src/assets/i18n/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,14 @@
"MORE": "さらに",
"STEP": "ステップ",
"SETUP": "セットアップ",
"COMINGSOON": "近日公開",
"UNSAVEDCHANGES": "未保存の変更",
"UNSAVED": {
"DIALOG": {
"DESCRIPTION": "この新しいアクションを破棄してもよろしいですか?あなたのアクションは失われます",
"CANCEL": "キャンセル",
"DISCARD": "破棄"
}
},
"TABLE": {
"SHOWUSER": "ユーザー {{value}} を表示する"
}
Expand Down
9 changes: 8 additions & 1 deletion console/src/assets/i18n/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,14 @@
"NEXT": "Następny",
"MORE": "więcej",
"STEP": "Krok",
"COMINGSOON": "Coming soon",
"UNSAVEDCHANGES": "Niezapisane zmiany",
"UNSAVED": {
"DIALOG": {
"DESCRIPTION": "Czy na pewno chcesz odrzucić to nowe działanie? Twoje działanie zostanie utracone",
"CANCEL": "Anuluj",
"DISCARD": "Wyrzucać"
}
},
"TABLE": {
"SHOWUSER": "Pokaż użytkownika {{value}}"
}
Expand Down
11 changes: 9 additions & 2 deletions console/src/assets/i18n/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,15 @@
"PREVIOUS": "上一页",
"NEXT": "下一页",
"MORE": "更多",
"STEP": "Step",
"COMINGSOON": "Coming soon",
"STEP": "",
"UNSAVEDCHANGES": "未保存的更改",
"UNSAVED": {
"DIALOG": {
"DESCRIPTION": "您确定要放弃此新操作吗?你的行动将会失败",
"CANCEL": "取消",
"DISCARD": "丢弃"
}
},
"TABLE": {
"SHOWUSER": "Show user {{value}}"
}
Expand Down

1 comment on commit 33a8ab4

@vercel
Copy link

@vercel vercel bot commented on 33a8ab4 Jun 13, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

docs – ./

docs-zitadel.vercel.app
docs-git-main-zitadel.vercel.app
zitadel-docs.vercel.app

Please sign in to comment.