feat: Add prompt to overwrite changes when concurrent editing occurs (#4817)

* feat: Add prompt to overwrite changes when concurrent editing occurs

* chore: undo config schema update
This commit is contained in:
Alex Grozav 2022-12-05 14:34:14 +02:00 committed by GitHub
parent 46c75b9fd2
commit af6ac42aa3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 5 deletions

View file

@ -205,7 +205,7 @@ export interface IRestApi {
removeTestWebhook(workflowId: string): Promise<boolean>;
runWorkflow(runData: IStartRunData): Promise<IExecutionPushResponse>;
createNewWorkflow(sendData: IWorkflowDataUpdate): Promise<IWorkflowDb>;
updateWorkflow(id: string, data: IWorkflowDataUpdate): Promise<IWorkflowDb>;
updateWorkflow(id: string, data: IWorkflowDataUpdate, forceSave?: boolean): Promise<IWorkflowDb>;
deleteWorkflow(name: string): Promise<void>;
getWorkflow(id: string): Promise<IWorkflowDb>;
getWorkflows(filter?: object): Promise<IWorkflowShortResponse[]>;

View file

@ -105,8 +105,8 @@ export const restApi = Vue.extend({
},
// Updates an existing workflow
updateWorkflow: (id: string, data: IWorkflowDataUpdate): Promise<IWorkflowDb> => {
return self.restApi().makeRestApiRequest('PATCH', `/workflows/${id}`, data);
updateWorkflow: (id: string, data: IWorkflowDataUpdate, forceSave = false): Promise<IWorkflowDb> => {
return self.restApi().makeRestApiRequest('PATCH', `/workflows/${id}${forceSave ? '?forceSave=true' : ''}`, data);
},
// Deletes a workflow

View file

@ -703,7 +703,7 @@ export const workflowHelpers = mixins(
}
},
async saveCurrentWorkflow({id, name, tags}: {id?: string, name?: string, tags?: string[]} = {}, redirect = true): Promise<boolean> {
async saveCurrentWorkflow({id, name, tags}: {id?: string, name?: string, tags?: string[]} = {}, redirect = true, forceSave = false): Promise<boolean> {
const currentWorkflow = id || this.$route.params.name;
if (!currentWorkflow || ['new', PLACEHOLDER_EMPTY_WORKFLOW_ID].includes(currentWorkflow)) {
@ -726,7 +726,7 @@ export const workflowHelpers = mixins(
workflowDataRequest.hash = this.workflowsStore.workflowHash;
const workflowData = await this.restApi().updateWorkflow(currentWorkflow, workflowDataRequest);
const workflowData = await this.restApi().updateWorkflow(currentWorkflow, workflowDataRequest, forceSave);
this.workflowsStore.setWorkflowHash(workflowData.hash);
if (name) {
@ -747,6 +747,22 @@ export const workflowHelpers = mixins(
} catch (error) {
this.uiStore.removeActiveAction('workflowSaving');
if (error.errorCode === 400 && error.message.startsWith('Your most recent changes may be lost')) {
const overwrite = await this.confirmMessage(
this.$locale.baseText('workflows.concurrentChanges.confirmMessage.message'),
this.$locale.baseText('workflows.concurrentChanges.confirmMessage.title'),
null,
this.$locale.baseText('workflows.concurrentChanges.confirmMessage.confirmButtonText'),
this.$locale.baseText('workflows.concurrentChanges.confirmMessage.cancelButtonText'),
);
if (overwrite) {
return this.saveCurrentWorkflow({id, name, tags}, redirect, true);
}
return false;
}
this.$showMessage({
title: this.$locale.baseText('workflowHelpers.showMessage.title'),
message: error.message,

View file

@ -1399,6 +1399,10 @@
"workflows.shareModal.notAvailable": "Sharing workflows with others is currently available only on n8n cloud, our hosted offering.",
"workflows.shareModal.notAvailable.button": "Explore n8n cloud",
"workflows.roles.editor": "Editor",
"workflows.concurrentChanges.confirmMessage.title": "Workflow was edited by someone else",
"workflows.concurrentChanges.confirmMessage.message": "Another user made <strong>an edit</strong> to this workflow since you last saved it. Do you want to overwrite their changes?",
"workflows.concurrentChanges.confirmMessage.cancelButtonText": "Cancel",
"workflows.concurrentChanges.confirmMessage.confirmButtonText": "Overwrite then save",
"importCurlModal.title": "Import cURL command",
"importCurlModal.input.label": "cURL Command",
"importCurlModal.input.placeholder": "Paste the cURL command here",