Skip to content

Use promise based dialog chains #23

Description

@clepski

Technical Improvement

Use promised based dialog chains instead of callbacks for confirmation dialogs.

Acceptance criteria

  • Dialog open should return a promise which completes when the dialog is closed
  • If the user confirms returns true, on cancel return false
  • Pass all config and texts necessary for the dialog in the show / open function call

Benefits

  • Better readability of the flow
  • Remove unnecessary local variables
  • We only need one confirm dialog, which receives all parameters on open

Example: confirm before close

 close() {
    this.confirmAction = 'cancel';
    this.confirmHeadline = 'Cancel without saving?';
    this.confirmDescription =
      'Are you sure you want to cancel? All changes will be lost.';
    this.confirmIcon = 'warning';
    this.confirmVariant = 'danger';
    this.confirmConfirmLabel = 'Yes, cancel';
    this.confirmCancelLabel = 'No, go back';
    this.confirmDialog.show();
  }

  private handleConfirm() {
    if (this.confirmAction === 'cancel') {
      this.closeWithoutConfirm();
    } else if (this.confirmAction === 'delete-subfunction') {
      // do other stuff
  }

Promise based approach

 close() {
    this.confirmDialog.show({
      variant: 'danger',
      ...
      texts: {
        headline: 'Cancel without saving?',
        ...
      }
    }).then(confirmed => {
      if (!confirmed) {
        return;
      }
      doStuff();
    });
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions