From b07eabc6c677166f7f2bf06b513e3308592d87a5 Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Mon, 8 Mar 2021 13:39:01 +0100 Subject: [PATCH] Add visual indicator when workflow being saved in the background --- .../elsa-workflow-editor.tsx | 62 ++++++++++++++++--- .../elsa-workflow-publish-button.tsx | 2 +- 2 files changed, 56 insertions(+), 8 deletions(-) diff --git a/src/designer/elsa-workflows-studio/src/components/editors/workflow-editor/elsa-workflow-editor/elsa-workflow-editor.tsx b/src/designer/elsa-workflows-studio/src/components/editors/workflow-editor/elsa-workflow-editor/elsa-workflow-editor.tsx index 84a357a4d..aa5845b4b 100644 --- a/src/designer/elsa-workflows-studio/src/components/editors/workflow-editor/elsa-workflow-editor/elsa-workflow-editor.tsx +++ b/src/designer/elsa-workflows-studio/src/components/editors/workflow-editor/elsa-workflow-editor/elsa-workflow-editor.tsx @@ -28,6 +28,9 @@ export class ElsaWorkflowDefinitionEditor { @State() workflowDefinition: WorkflowDefinition; @State() workflowModel: WorkflowModel; @State() publishing: boolean; + @State() saving: boolean; + @State() saved: boolean; + @State() savingError: string; el: HTMLElement; designer: HTMLElsaDesignerTreeElement; @@ -148,9 +151,21 @@ export class ElsaWorkflowDefinitionEditor { })), }; - workflowDefinition = await client.workflowDefinitionsApi.save(request); - this.workflowDefinition = workflowDefinition; - this.workflowModel = this.mapWorkflowModel(workflowDefinition); + this.saving = true; + + try { + workflowDefinition = await client.workflowDefinitionsApi.save(request); + this.workflowDefinition = workflowDefinition; + this.workflowModel = this.mapWorkflowModel(workflowDefinition); + } catch (e) { + console.error(e); + this.savingError = e.message; + setTimeout(() => this.savingError = null, 2000); + } finally { + this.saving = false; + this.saved = true; + setTimeout(() => this.saved = false, 750); + } } mapWorkflowModel(workflowDefinition: WorkflowDefinition): WorkflowModel { @@ -203,7 +218,6 @@ export class ElsaWorkflowDefinitionEditor { {this.renderCanvas()} {this.renderActivityPicker()} {this.renderActivityEditor()} - ); @@ -214,8 +228,15 @@ export class ElsaWorkflowDefinitionEditor {
this.designer = el}/> {this.renderWorkflowSettingsButton()} - {this.renderWorkflowSettingsModal()} - {this.renderPublishButton()} + + +
+
+ {this.renderSavingIndicator()} + {this.renderSavingError()} + {this.renderPublishButton()} +
+
); } @@ -242,7 +263,34 @@ export class ElsaWorkflowDefinitionEditor { } renderWorkflowSettingsModal() { - return ; + return; + } + + renderSavingIndicator() { + + if (this.publishing) + return undefined; + + const message = this.saving ? `Saving...` : this.saved ? `Saved` : null; + + if (!message) + return undefined; + + return ( +
+ {message} +
+ ); + } + + renderSavingError() { + if (!this.savingError) + return undefined; + + return ( +
+ An error occurred: {this.savingError} +
); } renderPublishButton() { diff --git a/src/designer/elsa-workflows-studio/src/components/editors/workflow-editor/elsa-workflow-publish-button/elsa-workflow-publish-button.tsx b/src/designer/elsa-workflows-studio/src/components/editors/workflow-editor/elsa-workflow-publish-button/elsa-workflow-publish-button.tsx index 8c2a8be2e..91eb438b8 100644 --- a/src/designer/elsa-workflows-studio/src/components/editors/workflow-editor/elsa-workflow-publish-button/elsa-workflow-publish-button.tsx +++ b/src/designer/elsa-workflows-studio/src/components/editors/workflow-editor/elsa-workflow-publish-button/elsa-workflow-publish-button.tsx @@ -30,7 +30,7 @@ export class ElsaWorkflowPublishButton { render() { return ( - registerClickOutside(this, el, this.closeMenu)}> + registerClickOutside(this, el, this.closeMenu)}> {this.publishing ? this.renderPublishingButton() : this.renderPublishButton()}