Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(editor): Prevent saving workflow while another save is in progress #9048

Merged
merged 5 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions cypress/e2e/7-workflow-actions.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,23 @@ describe('Workflow Actions', () => {
cy.wait('@saveWorkflow');
cy.wrap(null).then(() => expect(interceptCalledCount).to.eq(1));
});

it('should not save workflow twice when save is in progress', () => {
// This happens when users click save button from workflow name input
// In this case blur on the input saves the workflow and then click on the button saves it again
WorkflowPage.actions.visit();
WorkflowPage.getters.workflowNameInput().invoke('val').then((oldName) => {
WorkflowPage.getters.workflowNameInputContainer().click();
WorkflowPage.getters.workflowNameInput().type('{selectall}');
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this some Cypress magic to select all the text?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tomi Yeah, there is a few of those handy options. You can see them here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice 👌

WorkflowPage.getters.workflowNameInput().type('Test');
WorkflowPage.getters.saveButton().click();
WorkflowPage.getters.workflowNameInput().should('have.value', 'Test');
cy.visit(WorkflowPages.url);
// There should be no workflow with the old name (duplicate save)
WorkflowPages.getters.workflowCards().contains(String(oldName)).should('not.exist');
});
});

it('should copy nodes', () => {
WorkflowPage.actions.addNodeToCanvas(SCHEDULE_TRIGGER_NODE_NAME);
WorkflowPage.actions.addNodeToCanvas(CODE_NODE_NAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,10 @@ export default defineComponent({
},
methods: {
async onSaveButtonClick() {
// If the workflow is saving, do not allow another save
if (this.isWorkflowSaving) {
return;
}
let currentId = undefined;
if (this.currentWorkflowId !== PLACEHOLDER_EMPTY_WORKFLOW_ID) {
currentId = this.currentWorkflowId;
Expand Down Expand Up @@ -497,11 +501,12 @@ export default defineComponent({
cb(true);
return;
}

this.uiStore.addActiveAction('workflowSaving');
const saved = await this.workflowHelpers.saveCurrentWorkflow({ name });
if (saved) {
this.isNameEditEnabled = false;
}
this.uiStore.removeActiveAction('workflowSaving');
Copy link
Contributor

Choose a reason for hiding this comment

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

Would probably be good to do this in a try ... finally to make sure we are never left in an inconsistent state

cb(saved);
},
async handleFileImport(): Promise<void> {
Expand Down