From 17ab16d2480852ee75e391905a846142d8c154e3 Mon Sep 17 00:00:00 2001 From: Rupenieks Date: Wed, 9 Sep 2020 14:05:11 +0200 Subject: [PATCH] :zap: Deconstructed store mutation data parameters for better readability --- .../editor-ui/src/components/MainSidebar.vue | 2 +- .../src/components/mixins/moveNodeWorkflow.ts | 4 ++-- .../src/components/mixins/workflowHelpers.ts | 2 +- .../src/components/mixins/workflowSave.ts | 2 +- packages/editor-ui/src/store.ts | 22 +++++++++---------- packages/editor-ui/src/views/NodeView.vue | 11 +++++----- 6 files changed, 21 insertions(+), 22 deletions(-) diff --git a/packages/editor-ui/src/components/MainSidebar.vue b/packages/editor-ui/src/components/MainSidebar.vue index 92645942b2..df2e75bfb5 100644 --- a/packages/editor-ui/src/components/MainSidebar.vue +++ b/packages/editor-ui/src/components/MainSidebar.vue @@ -398,7 +398,7 @@ export default mixins( return; } - this.$store.commit('setWorkflowName', {newName: workflowName, setStateDirty: true}); + this.$store.commit('setWorkflowName', {name: workflowName, setStateDirty: true}); this.$showMessage({ title: 'Workflow renamed', diff --git a/packages/editor-ui/src/components/mixins/moveNodeWorkflow.ts b/packages/editor-ui/src/components/mixins/moveNodeWorkflow.ts index 9dcf86aeac..1408884371 100644 --- a/packages/editor-ui/src/components/mixins/moveNodeWorkflow.ts +++ b/packages/editor-ui/src/components/mixins/moveNodeWorkflow.ts @@ -31,7 +31,7 @@ export const moveNodeWorkflow = mixins(nodeIndex).extend({ const nodeViewOffsetPositionX = offsetPosition[0] + (e.pageX - this.moveLastPosition[0]); const nodeViewOffsetPositionY = offsetPosition[1] + (e.pageY - this.moveLastPosition[1]); - this.$store.commit('setNodeViewOffsetPosition', {newOffset: [nodeViewOffsetPositionX, nodeViewOffsetPositionY], setStateDirty: true}); + this.$store.commit('setNodeViewOffsetPosition', {offset: [nodeViewOffsetPositionX, nodeViewOffsetPositionY], setStateDirty: true}); // Update the last position this.moveLastPosition[0] = e.pageX; @@ -87,7 +87,7 @@ export const moveNodeWorkflow = mixins(nodeIndex).extend({ const offsetPosition = this.$store.getters.getNodeViewOffsetPosition; const nodeViewOffsetPositionX = offsetPosition[0] - e.deltaX; const nodeViewOffsetPositionY = offsetPosition[1] - e.deltaY; - this.$store.commit('setNodeViewOffsetPosition', {newOffset: [nodeViewOffsetPositionX, nodeViewOffsetPositionY], setStateDirty: true}); + this.$store.commit('setNodeViewOffsetPosition', {offset: [nodeViewOffsetPositionX, nodeViewOffsetPositionY], setStateDirty: true}); }, }, }); diff --git a/packages/editor-ui/src/components/mixins/workflowHelpers.ts b/packages/editor-ui/src/components/mixins/workflowHelpers.ts index d5354bf2d8..939d08ccf5 100644 --- a/packages/editor-ui/src/components/mixins/workflowHelpers.ts +++ b/packages/editor-ui/src/components/mixins/workflowHelpers.ts @@ -420,7 +420,7 @@ export const workflowHelpers = mixins( this.$store.commit('setActive', workflowData.active || false); this.$store.commit('setWorkflowId', workflowData.id); - this.$store.commit('setWorkflowName', {newName: workflowData.name, setStateDirty: false}); + this.$store.commit('setWorkflowName', {name: workflowData.name, setStateDirty: false}); this.$store.commit('setWorkflowSettings', workflowData.settings || {}); } else { // Workflow exists already so update it diff --git a/packages/editor-ui/src/components/mixins/workflowSave.ts b/packages/editor-ui/src/components/mixins/workflowSave.ts index c4d4001047..45526f2b7e 100644 --- a/packages/editor-ui/src/components/mixins/workflowSave.ts +++ b/packages/editor-ui/src/components/mixins/workflowSave.ts @@ -74,7 +74,7 @@ export const workflowSave = mixins( this.$store.commit('setActive', workflowData.active || false); this.$store.commit('setWorkflowId', workflowData.id); - this.$store.commit('setWorkflowName', {newName: workflowData.name, setStateDirty: false}); + this.$store.commit('setWorkflowName', {name: workflowData.name, setStateDirty: false}); this.$store.commit('setWorkflowSettings', workflowData.settings || {}); } else { // Workflow exists already so update it diff --git a/packages/editor-ui/src/store.ts b/packages/editor-ui/src/store.ts index 4960aa8acf..4a9e5c76c8 100644 --- a/packages/editor-ui/src/store.ts +++ b/packages/editor-ui/src/store.ts @@ -183,19 +183,19 @@ export const store = new Vuex.Store({ }, // Connections - addConnection (state, data) { - if (data.connection.length !== 2) { + addConnection (state, {connection, setStateDirty}) { + if (connection.length !== 2) { // All connections need two entries // TODO: Check if there is an error or whatever that is supposed to be returned return; } - if (data.setStateDirty === true) { + if (setStateDirty === true) { state.stateIsDirty = true; } - const sourceData: IConnection = data.connection[0]; - const destinationData: IConnection = data.connection[1]; + const sourceData: IConnection = connection[0]; + const destinationData: IConnection = connection[1]; // Check if source node and type exist already and if not add them if (!state.workflow.connections.hasOwnProperty(sourceData.node)) { @@ -388,11 +388,11 @@ export const store = new Vuex.Store({ }, // Name - setWorkflowName (state, data) { - if (data.setStateDirty === true) { + setWorkflowName (state, {name, setStateDirty}) { + if (setStateDirty === true) { state.stateIsDirty = true; } - state.workflow.name = data.newName; + state.workflow.name = name; }, // Nodes @@ -476,11 +476,11 @@ export const store = new Vuex.Store({ setNodeViewMoveInProgress (state, value: boolean) { state.nodeViewMoveInProgress = value; }, - setNodeViewOffsetPosition (state, data) { - if (data.setStateDirty === true) { + setNodeViewOffsetPosition (state, {offset, setStateDirty}) { + if (setStateDirty === true) { state.stateIsDirty = true; } - state.nodeViewOffsetPosition = data.newOffset; + state.nodeViewOffsetPosition = offset; }, // Node-Types diff --git a/packages/editor-ui/src/views/NodeView.vue b/packages/editor-ui/src/views/NodeView.vue index d0b4133b1e..edf0927c27 100644 --- a/packages/editor-ui/src/views/NodeView.vue +++ b/packages/editor-ui/src/views/NodeView.vue @@ -325,7 +325,7 @@ export default mixins( throw new Error(`Execution with id "${executionId}" could not be found!`); } - this.$store.commit('setWorkflowName', {newName: data.workflowData.name, setStateDirty: false}); + this.$store.commit('setWorkflowName', {name: data.workflowData.name, setStateDirty: false}); this.$store.commit('setWorkflowId', PLACEHOLDER_EMPTY_WORKFLOW_ID); this.$store.commit('setWorkflowExecutionData', data); @@ -349,7 +349,7 @@ export default mixins( this.$store.commit('setActive', data.active || false); this.$store.commit('setWorkflowId', workflowId); - this.$store.commit('setWorkflowName', {newName: data.name, setStateDirty: false}); + this.$store.commit('setWorkflowName', {name: data.name, setStateDirty: false}); this.$store.commit('setWorkflowSettings', data.settings || {}); await this.addNodes(data.nodes, data.connections); @@ -1388,10 +1388,9 @@ export default mixins( detachable: !this.isReadOnly, }); } else { - const connectionProperties = {connection, setStateDirty: false}; // When nodes get connected it gets saved automatically to the storage // so if we do not connect we have to save the connection manually - this.$store.commit('addConnection', connectionProperties); + this.$store.commit('addConnection', {connection, setStateDirty: false}); } }, __removeConnection (connection: [IConnection, IConnection], removeVisualConnection = false) { @@ -1876,7 +1875,7 @@ export default mixins( this.$store.commit('setActive', false); this.$store.commit('setWorkflowId', PLACEHOLDER_EMPTY_WORKFLOW_ID); - this.$store.commit('setWorkflowName', {newName: '', setStateDirty: false}); + this.$store.commit('setWorkflowName', {name: '', setStateDirty: false}); this.$store.commit('setWorkflowSettings', {}); this.$store.commit('setActiveExecutionId', null); @@ -1887,7 +1886,7 @@ export default mixins( this.$store.commit('resetNodeIndex'); this.$store.commit('resetSelectedNodes'); - this.$store.commit('setNodeViewOffsetPosition', {newOffset: [0, 0], setStateDirty: false}); + this.$store.commit('setNodeViewOffsetPosition', {offset: [0, 0], setStateDirty: false}); return Promise.resolve(); },