n8n/packages/editor-ui/src/store.ts
Mutasem Aldmour d8598b0126
Workflow canvas revamp (#2388)
* bring back overrides

* fix input output label positions

* simply update label positions

* refactor a bunch

* update min x to show items

* hide overlay on connection

* only delete target connection, add maximum to push nodes out

* rename const

* rename const

* set new insert position

* fix insert behavior

* update position handling

* show arrow along with label

* update connector

* set endpoint styles

* update pattern

* push nodes up / down in case of if node

* set position in switch

* only one action at a time

* add custom flow chart type

* select start node by default when opening new workflow

* add enter delay

* fix delete bug

* change connection type

* add offset for if/switch/merge

* fix gap

* fix drag issue

* implement new states

* update disabled state

* add selected state

* make selects faster

* update positioning

* truncate when selected

* remove offset for actions

* fix icon scaling

* refactor js plumb

* fix looping behavior at close distance

* lock version

* change background to dots

* update endpoints styling

* increase spacing

* udpate node z-index

* fix output label positions

* fix output label positions

* reset location

* add label offset

* update border radius

* fix height issue

* fix parallaxing issue

* fix zoomout issue

* add success z-index

* clean up js file

* add package lock

* fix z-index bug

* update dot grid

* update zoom level

* set values, increase grid size

* fix drop position

* prevent duplicate connections

* fix stub

* use localstorage overrides for colors

* add colors to system

* revert no longer needed changes

* revert no longer needed changes

* add canvas colors

* add canvas colors

* use variable for id

* force type

* refactor helpers

* add label constants

* refactor func

* refactor

* fix

* refactor

* clean up css

* refactor setzoom level

* refactor

* refactor

* refactor func

* remove scope

* remove localstorage caching

* clean up imports

* update zero case

* add delete connection

* update selected state

* add base type, remove straight line

* add stub offset back

* rename param

* add label offset

* update font size of items

* move up label

* fix error state while executing

* disrespect stubs

* check for errors

* refactor position

* clean up extra space

* make entire node connectable

* Revert "make entire node connectable"

e304f7c5b8

* always show border

* add border to zoom buttons

* update spacing

* update colors

* allow connecting to entire node

* fix pull conn active

* two line names

* apply select to all lines

* increase input margin

* override target pos

* reset conn after pull

* fix types

* update orientation

* fix up connectors snapping

* hide arrow on pull

* update overrides for connectors

* change text

* update pull colors

* set to 1 line when selected

* fix executions bug

* build

* refactor node component

* remove comment

* refactor more

* remove prop

* fix build issue

* fix input drag bug in executions

* reset offset

* update select background

* handle issue when endpoints are not set

* fix connection aborted issue

* add try catch to help show errors

* wrap bind with try/catch

* set default styles

* reset pos despite zoom

* add more checks

* clean up impl

* update icon

* handle unknown types

* hide items on init

* fix importing unknown types with credentials

* change opacity

* push up item label

* update color

* update label class and colors

* add to drop distance

* fix z-index to match node

* disable eslint

* fix lasso tool selection

* update background color

* update waiting state

* update tooltip positions

* update wait node border

* fix selection bug mostly

* if selected, move above other nodes

* add line through disabled nodes

* remove node color option

* move label above connection

* success color for line through

* update options index

* hide waiting icon when disabled

* fix gmail icon

* refactor icons

* clear execution data on disable/delete

* fix selected node

* fix executing behavior

* optional __meta

* set grid size

* remove default color

* remove node color

* add comments

* comments

* add comments

* remove empty space

* update comment

* refactor uuids

* fix type issue

* Revert "fix type issue"

9523b34f96

* Revert "fix type issue"

9523b34f96

* Revert "refactor uuids"

07f6848065

* fix build issues

* refactor

* update uuid

* child nodes

* skip nodes behind when pushing in loop

* shift output icon for switch node

* don't show output if waiting

* waiting on init

* build

* change to bezier

* revert connector change

* add bezier type

* fix snapping

* clean up impl

* refactor func

* make const

* rename type

* refactor to simplify

* Revert "refactor to simplify"

2db0ed504c

* enable flowchart mode

* clean up flowchart type

* refactor type

* merge types

* configure curviness

* set in localstorage

* fix straight line arrow bug

* show arrow when pulling

* refactor / simplify

* fix target gap in bezier

* refactor target gap

* add comments

* add comment

* fix dragging connections

* fix bug when moving connection

* update comment

* rename file

* update values

* update minor

* update straight line box

* clean up conn types

* clean up z-indexes

* move color filters to node icon

* update background color

* update to use grid size value

* fix endpoint offsets

* set yspan range lower

* remove overlays when moving conn

* prevent unwanted connections

* fix messed up connections

* remove console log

* clear execution issues on workflow run

* update corner radius

* fix drag/delete bug

* increase offset

* update disabled state

* address comments

* refactor

* refactor func

*  Add full license text to N8nCustomConnectorType.js

Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
2021-11-19 10:17:13 +01:00

883 lines
26 KiB
TypeScript

import Vue from 'vue';
import Vuex from 'vuex';
import { PLACEHOLDER_EMPTY_WORKFLOW_ID, DEFAULT_NODETYPE_VERSION } from '@/constants';
import {
IConnection,
IConnections,
IDataObject,
INodeConnections,
INodeIssueData,
INodeTypeDescription,
IRunData,
ITelemetrySettings,
ITaskData,
IWorkflowSettings,
} from 'n8n-workflow';
import {
IExecutionResponse,
IExecutionsCurrentSummaryExtended,
IRootState,
IMenuItem,
INodeUi,
INodeUpdatePropertiesInformation,
IPushDataExecutionFinished,
IPushDataNodeExecuteAfter,
IUpdateInformation,
IWorkflowDb,
XYPosition,
IRestApiContext,
} from './Interface';
import credentials from './modules/credentials';
import tags from './modules/tags';
import settings from './modules/settings';
import ui from './modules/ui';
import workflows from './modules/workflows';
import versions from './modules/versions';
Vue.use(Vuex);
const state: IRootState = {
activeExecutions: [],
activeWorkflows: [],
activeActions: [],
activeNode: null,
// @ts-ignore
baseUrl: process.env.VUE_APP_URL_BASE_API ? process.env.VUE_APP_URL_BASE_API : (window.BASE_PATH === '/%BASE_PATH%/' ? '/' : window.BASE_PATH),
endpointWebhook: 'webhook',
endpointWebhookTest: 'webhook-test',
executionId: null,
executingNode: '',
executionWaitingForWebhook: false,
pushConnectionActive: true,
saveDataErrorExecution: 'all',
saveDataSuccessExecution: 'all',
saveManualExecutions: false,
timezone: 'America/New_York',
stateIsDirty: false,
executionTimeout: -1,
maxExecutionTimeout: Number.MAX_SAFE_INTEGER,
versionCli: '0.0.0',
oauthCallbackUrls: {},
n8nMetadata: {},
workflowExecutionData: null,
lastSelectedNode: null,
lastSelectedNodeOutputIndex: null,
nodeIndex: [],
nodeTypes: [],
nodeViewOffsetPosition: [0, 0],
nodeViewMoveInProgress: false,
selectedNodes: [],
sessionId: Math.random().toString(36).substring(2, 15),
urlBaseWebhook: 'http://localhost:5678/',
workflow: {
id: PLACEHOLDER_EMPTY_WORKFLOW_ID,
name: '',
active: false,
createdAt: -1,
updatedAt: -1,
connections: {},
nodes: [],
settings: {},
tags: [],
},
sidebarMenuItems: [],
instanceId: '',
telemetry: null,
};
const modules = {
credentials,
tags,
settings,
workflows,
versions,
ui,
};
export const store = new Vuex.Store({
strict: process.env.NODE_ENV !== 'production',
modules,
state,
mutations: {
// Active Actions
addActiveAction (state, action: string) {
if (!state.activeActions.includes(action)) {
state.activeActions.push(action);
}
},
removeActiveAction (state, action: string) {
const actionIndex = state.activeActions.indexOf(action);
if (actionIndex !== -1) {
state.activeActions.splice(actionIndex, 1);
}
},
// Active Executions
addActiveExecution (state, newActiveExecution: IExecutionsCurrentSummaryExtended) {
// Check if the execution exists already
const activeExecution = state.activeExecutions.find(execution => {
return execution.id === newActiveExecution.id;
});
if (activeExecution !== undefined) {
// Exists already so no need to add it again
if (activeExecution.workflowName === undefined) {
activeExecution.workflowName = newActiveExecution.workflowName;
}
return;
}
state.activeExecutions.unshift(newActiveExecution);
},
finishActiveExecution (state, finishedActiveExecution: IPushDataExecutionFinished) {
// Find the execution to set to finished
const activeExecution = state.activeExecutions.find(execution => {
return execution.id === finishedActiveExecution.executionId;
});
if (activeExecution === undefined) {
// The execution could not be found
return;
}
if (finishedActiveExecution.executionId !== undefined) {
Vue.set(activeExecution, 'id', finishedActiveExecution.executionId);
}
Vue.set(activeExecution, 'finished', finishedActiveExecution.data.finished);
Vue.set(activeExecution, 'stoppedAt', finishedActiveExecution.data.stoppedAt);
},
setActiveExecutions (state, newActiveExecutions: IExecutionsCurrentSummaryExtended[]) {
Vue.set(state, 'activeExecutions', newActiveExecutions);
},
// Active Workflows
setActiveWorkflows (state, newActiveWorkflows: string[]) {
state.activeWorkflows = newActiveWorkflows;
},
setWorkflowActive (state, workflowId: string) {
state.stateIsDirty = false;
const index = state.activeWorkflows.indexOf(workflowId);
if (index === -1) {
state.activeWorkflows.push(workflowId);
}
},
setWorkflowInactive (state, workflowId: string) {
const index = state.activeWorkflows.indexOf(workflowId);
if (index !== -1) {
state.selectedNodes.splice(index, 1);
}
},
// Set state condition dirty or not
// ** Dirty: if current workflow state has been synchronized with database AKA has it been saved
setStateDirty (state, dirty : boolean) {
state.stateIsDirty = dirty;
},
// Selected Nodes
addSelectedNode (state, node: INodeUi) {
state.selectedNodes.push(node);
},
removeNodeFromSelection (state, node: INodeUi) {
let index;
for (index in state.selectedNodes) {
if (state.selectedNodes[index].name === node.name) {
state.selectedNodes.splice(parseInt(index, 10), 1);
break;
}
}
},
resetSelectedNodes (state) {
Vue.set(state, 'selectedNodes', []);
},
// Active
setActive (state, newActive: boolean) {
state.workflow.active = newActive;
},
// Connections
addConnection (state, data) {
if (data.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) {
state.stateIsDirty = true;
}
const sourceData: IConnection = data.connection[0];
const destinationData: IConnection = data.connection[1];
// Check if source node and type exist already and if not add them
if (!state.workflow.connections.hasOwnProperty(sourceData.node)) {
Vue.set(state.workflow.connections, sourceData.node, {});
}
if (!state.workflow.connections[sourceData.node].hasOwnProperty(sourceData.type)) {
Vue.set(state.workflow.connections[sourceData.node], sourceData.type, []);
}
if (state.workflow.connections[sourceData.node][sourceData.type].length < (sourceData.index + 1)) {
for (let i = state.workflow.connections[sourceData.node][sourceData.type].length; i <= sourceData.index; i++) {
state.workflow.connections[sourceData.node][sourceData.type].push([]);
}
}
// Check if the same connection exists already
const checkProperties = ['index', 'node', 'type'];
let propertyName: string;
let connectionExists = false;
connectionLoop:
for (const existingConnection of state.workflow.connections[sourceData.node][sourceData.type][sourceData.index]) {
for (propertyName of checkProperties) {
if ((existingConnection as any)[propertyName] !== (destinationData as any)[propertyName]) { // tslint:disable-line:no-any
continue connectionLoop;
}
}
connectionExists = true;
break;
}
// Add the new connection if it does not exist already
if (connectionExists === false) {
state.workflow.connections[sourceData.node][sourceData.type][sourceData.index].push(destinationData);
}
},
removeConnection (state, data) {
const sourceData = data.connection[0];
const destinationData = data.connection[1];
if (!state.workflow.connections.hasOwnProperty(sourceData.node)) {
return;
}
if (!state.workflow.connections[sourceData.node].hasOwnProperty(sourceData.type)) {
return;
}
if (state.workflow.connections[sourceData.node][sourceData.type].length < (sourceData.index + 1)) {
return;
}
state.stateIsDirty = true;
const connections = state.workflow.connections[sourceData.node][sourceData.type][sourceData.index];
for (const index in connections) {
if (connections[index].node === destinationData.node && connections[index].type === destinationData.type && connections[index].index === destinationData.index) {
// Found the connection to remove
connections.splice(parseInt(index, 10), 1);
}
}
},
removeAllConnections (state, data) {
if (data && data.setStateDirty === true) {
state.stateIsDirty = true;
}
state.workflow.connections = {};
},
removeAllNodeConnection (state, node: INodeUi) {
state.stateIsDirty = true;
// Remove all source connections
if (state.workflow.connections.hasOwnProperty(node.name)) {
delete state.workflow.connections[node.name];
}
// Remove all destination connections
const indexesToRemove = [];
let sourceNode: string, type: string, sourceIndex: string, connectionIndex: string, connectionData: IConnection;
for (sourceNode of Object.keys(state.workflow.connections)) {
for (type of Object.keys(state.workflow.connections[sourceNode])) {
for (sourceIndex of Object.keys(state.workflow.connections[sourceNode][type])) {
indexesToRemove.length = 0;
for (connectionIndex of Object.keys(state.workflow.connections[sourceNode][type][parseInt(sourceIndex, 10)])) {
connectionData = state.workflow.connections[sourceNode][type][parseInt(sourceIndex, 10)][parseInt(connectionIndex, 10)];
if (connectionData.node === node.name) {
indexesToRemove.push(connectionIndex);
}
}
indexesToRemove.forEach((index) => {
state.workflow.connections[sourceNode][type][parseInt(sourceIndex, 10)].splice(parseInt(index, 10), 1);
});
}
}
}
},
renameNodeSelectedAndExecution (state, nameData) {
state.stateIsDirty = true;
// If node has any WorkflowResultData rename also that one that the data
// does still get displayed also after node got renamed
if (state.workflowExecutionData !== null && state.workflowExecutionData.data.resultData.runData.hasOwnProperty(nameData.old)) {
state.workflowExecutionData.data.resultData.runData[nameData.new] = state.workflowExecutionData.data.resultData.runData[nameData.old];
delete state.workflowExecutionData.data.resultData.runData[nameData.old];
}
// In case the renamed node was last selected set it also there with the new name
if (state.lastSelectedNode === nameData.old) {
state.lastSelectedNode = nameData.new;
}
},
resetAllNodesIssues (state) {
state.workflow.nodes.forEach((node) => {
node.issues = undefined;
});
return true;
},
setNodeIssue (state, nodeIssueData: INodeIssueData) {
const node = state.workflow.nodes.find(node => {
return node.name === nodeIssueData.node;
});
if (!node) {
return false;
}
if (nodeIssueData.value === null) {
// Remove the value if one exists
if (node.issues === undefined || node.issues[nodeIssueData.type] === undefined) {
// No values for type exist so nothing has to get removed
return true;
}
// @ts-ignore
Vue.delete(node.issues, nodeIssueData.type);
} else {
if (node.issues === undefined) {
Vue.set(node, 'issues', {});
}
// Set/Overwrite the value
Vue.set(node.issues!, nodeIssueData.type, nodeIssueData.value);
}
return true;
},
// Id
setWorkflowId (state, id: string) {
state.workflow.id = id;
},
// Name
setWorkflowName (state, data) {
if (data.setStateDirty === true) {
state.stateIsDirty = true;
}
state.workflow.name = data.newName;
},
// replace invalid credentials in workflow
replaceInvalidWorkflowCredentials(state, {credentials, invalid, type }) {
state.workflow.nodes.forEach((node) => {
if (!node.credentials || !node.credentials[type]) {
return;
}
const nodeCredentials = node.credentials[type];
if (typeof nodeCredentials === 'string' && nodeCredentials === invalid.name) {
node.credentials[type] = credentials;
return;
}
if (nodeCredentials.id === null) {
if (nodeCredentials.name === invalid.name){
node.credentials[type] = credentials;
}
return;
}
if (nodeCredentials.id === invalid.id) {
node.credentials[type] = credentials;
}
});
},
// Nodes
addNode (state, nodeData: INodeUi) {
if (!nodeData.hasOwnProperty('name')) {
// All nodes have to have a name
// TODO: Check if there is an error or whatever that is supposed to be returned
return;
}
state.workflow.nodes.push(nodeData);
},
removeNode (state, node: INodeUi) {
for (let i = 0; i < state.workflow.nodes.length; i++) {
if (state.workflow.nodes[i].name === node.name) {
state.workflow.nodes.splice(i, 1);
state.stateIsDirty = true;
return;
}
}
},
removeAllNodes (state, data) {
if (data.setStateDirty === true) {
state.stateIsDirty = true;
}
state.workflow.nodes.splice(0, state.workflow.nodes.length);
},
updateNodeProperties (state, updateInformation: INodeUpdatePropertiesInformation) {
// Find the node that should be updated
const node = state.workflow.nodes.find(node => {
return node.name === updateInformation.name;
});
if (node) {
for (const key of Object.keys(updateInformation.properties)) {
state.stateIsDirty = true;
Vue.set(node, key, updateInformation.properties[key]);
}
}
},
setNodeValue (state, updateInformation: IUpdateInformation) {
// Find the node that should be updated
const node = state.workflow.nodes.find(node => {
return node.name === updateInformation.name;
});
if (node === undefined || node === null) {
throw new Error(`Node with the name "${updateInformation.name}" could not be found to set parameter.`);
}
state.stateIsDirty = true;
Vue.set(node, updateInformation.key, updateInformation.value);
},
setNodeParameters (state, updateInformation: IUpdateInformation) {
// Find the node that should be updated
const node = state.workflow.nodes.find(node => {
return node.name === updateInformation.name;
});
if (node === undefined || node === null) {
throw new Error(`Node with the name "${updateInformation.name}" could not be found to set parameter.`);
}
state.stateIsDirty = true;
Vue.set(node, 'parameters', updateInformation.value);
},
// Node-Index
addToNodeIndex (state, nodeName: string) {
state.nodeIndex.push(nodeName);
},
setNodeIndex (state, newData: { index: number, name: string | null}) {
state.nodeIndex[newData.index] = newData.name;
},
resetNodeIndex (state) {
Vue.set(state, 'nodeIndex', []);
},
// Node-View
setNodeViewMoveInProgress (state, value: boolean) {
state.nodeViewMoveInProgress = value;
},
setNodeViewOffsetPosition (state, data) {
state.nodeViewOffsetPosition = data.newOffset;
},
// Node-Types
setNodeTypes (state, nodeTypes: INodeTypeDescription[]) {
Vue.set(state, 'nodeTypes', nodeTypes);
},
// Active Execution
setExecutingNode (state, executingNode: string) {
state.executingNode = executingNode;
},
setExecutionWaitingForWebhook (state, newWaiting: boolean) {
state.executionWaitingForWebhook = newWaiting;
},
setActiveExecutionId (state, executionId: string | null) {
state.executionId = executionId;
},
// Push Connection
setPushConnectionActive (state, newActive: boolean) {
state.pushConnectionActive = newActive;
},
// Webhooks
setUrlBaseWebhook (state, urlBaseWebhook: string) {
Vue.set(state, 'urlBaseWebhook', urlBaseWebhook);
},
setEndpointWebhook (state, endpointWebhook: string) {
Vue.set(state, 'endpointWebhook', endpointWebhook);
},
setEndpointWebhookTest (state, endpointWebhookTest: string) {
Vue.set(state, 'endpointWebhookTest', endpointWebhookTest);
},
setSaveDataErrorExecution (state, newValue: string) {
Vue.set(state, 'saveDataErrorExecution', newValue);
},
setSaveDataSuccessExecution (state, newValue: string) {
Vue.set(state, 'saveDataSuccessExecution', newValue);
},
setSaveManualExecutions (state, saveManualExecutions: boolean) {
Vue.set(state, 'saveManualExecutions', saveManualExecutions);
},
setTimezone (state, timezone: string) {
Vue.set(state, 'timezone', timezone);
},
setExecutionTimeout (state, executionTimeout: number) {
Vue.set(state, 'executionTimeout', executionTimeout);
},
setMaxExecutionTimeout (state, maxExecutionTimeout: number) {
Vue.set(state, 'maxExecutionTimeout', maxExecutionTimeout);
},
setVersionCli(state, version: string) {
Vue.set(state, 'versionCli', version);
},
setInstanceId(state, instanceId: string) {
Vue.set(state, 'instanceId', instanceId);
},
setTelemetry(state, telemetry: ITelemetrySettings) {
Vue.set(state, 'telemetry', telemetry);
},
setOauthCallbackUrls(state, urls: IDataObject) {
Vue.set(state, 'oauthCallbackUrls', urls);
},
setN8nMetadata(state, metadata: IDataObject) {
Vue.set(state, 'n8nMetadata', metadata);
},
setActiveNode (state, nodeName: string) {
state.activeNode = nodeName;
},
setLastSelectedNode (state, nodeName: string) {
state.lastSelectedNode = nodeName;
},
setLastSelectedNodeOutputIndex (state, outputIndex: number | null) {
state.lastSelectedNodeOutputIndex = outputIndex;
},
setWorkflowExecutionData (state, workflowResultData: IExecutionResponse | null) {
state.workflowExecutionData = workflowResultData;
},
addNodeExecutionData (state, pushData: IPushDataNodeExecuteAfter): void {
if (state.workflowExecutionData === null) {
throw new Error('The "workflowExecutionData" is not initialized!');
}
if (state.workflowExecutionData.data.resultData.runData[pushData.nodeName] === undefined) {
Vue.set(state.workflowExecutionData.data.resultData.runData, pushData.nodeName, []);
}
state.workflowExecutionData.data.resultData.runData[pushData.nodeName].push(pushData.data);
},
clearNodeExecutionData (state, nodeName: string): void {
if (state.workflowExecutionData === null) {
return;
}
Vue.delete(state.workflowExecutionData.data.resultData.runData, nodeName);
},
setWorkflowSettings (state, workflowSettings: IWorkflowSettings) {
Vue.set(state.workflow, 'settings', workflowSettings);
},
setWorkflowTagIds (state, tags: string[]) {
Vue.set(state.workflow, 'tags', tags);
},
removeWorkflowTagId (state, tagId: string) {
const tags = state.workflow.tags as string[];
const updated = tags.filter((id: string) => id !== tagId);
Vue.set(state.workflow, 'tags', updated);
},
// Workflow
setWorkflow (state, workflow: IWorkflowDb) {
Vue.set(state, 'workflow', workflow);
if (!state.workflow.hasOwnProperty('active')) {
Vue.set(state.workflow, 'active', false);
}
if (!state.workflow.hasOwnProperty('connections')) {
Vue.set(state.workflow, 'connections', {});
}
if (!state.workflow.hasOwnProperty('createdAt')) {
Vue.set(state.workflow, 'createdAt', -1);
}
if (!state.workflow.hasOwnProperty('updatedAt')) {
Vue.set(state.workflow, 'updatedAt', -1);
}
if (!state.workflow.hasOwnProperty('id')) {
Vue.set(state.workflow, 'id', PLACEHOLDER_EMPTY_WORKFLOW_ID);
}
if (!state.workflow.hasOwnProperty('nodes')) {
Vue.set(state.workflow, 'nodes', []);
}
if (!state.workflow.hasOwnProperty('settings')) {
Vue.set(state.workflow, 'settings', {});
}
},
updateNodeTypes (state, nodeTypes: INodeTypeDescription[]) {
const oldNodesToKeep = state.nodeTypes.filter(node => !nodeTypes.find(n => n.name === node.name && n.version === node.version));
const newNodesState = [...oldNodesToKeep, ...nodeTypes];
Vue.set(state, 'nodeTypes', newNodesState);
state.nodeTypes = newNodesState;
},
addSidebarMenuItems (state, menuItems: IMenuItem[]) {
const updated = state.sidebarMenuItems.concat(menuItems);
Vue.set(state, 'sidebarMenuItems', updated);
},
},
getters: {
isActionActive: (state) => (action: string): boolean => {
return state.activeActions.includes(action);
},
isNewWorkflow: (state) => {
return state.workflow.id === PLACEHOLDER_EMPTY_WORKFLOW_ID;
},
currentWorkflowHasWebhookNode: (state: IRootState): boolean => {
return !!state.workflow.nodes.find((node: INodeUi) => !!node.webhookId);
},
getActiveExecutions: (state): IExecutionsCurrentSummaryExtended[] => {
return state.activeExecutions;
},
getBaseUrl: (state): string => {
return state.baseUrl;
},
getRestUrl: (state): string => {
let endpoint = 'rest';
if (process.env.VUE_APP_ENDPOINT_REST) {
endpoint = process.env.VUE_APP_ENDPOINT_REST;
}
return `${state.baseUrl}${endpoint}`;
},
getRestApiContext(state): IRestApiContext {
let endpoint = 'rest';
if (process.env.VUE_APP_ENDPOINT_REST) {
endpoint = process.env.VUE_APP_ENDPOINT_REST;
}
return {
baseUrl: `${state.baseUrl}${endpoint}`,
sessionId: state.sessionId,
};
},
getWebhookBaseUrl: (state): string => {
return state.urlBaseWebhook;
},
getWebhookUrl: (state): string => {
return `${state.urlBaseWebhook}${state.endpointWebhook}`;
},
getWebhookTestUrl: (state): string => {
return `${state.urlBaseWebhook}${state.endpointWebhookTest}`;
},
getStateIsDirty: (state) : boolean => {
return state.stateIsDirty;
},
instanceId: (state): string => {
return state.instanceId;
},
saveDataErrorExecution: (state): string => {
return state.saveDataErrorExecution;
},
saveDataSuccessExecution: (state): string => {
return state.saveDataSuccessExecution;
},
saveManualExecutions: (state): boolean => {
return state.saveManualExecutions;
},
timezone: (state): string => {
return state.timezone;
},
executionTimeout: (state): number => {
return state.executionTimeout;
},
maxExecutionTimeout: (state): number => {
return state.maxExecutionTimeout;
},
versionCli: (state): string => {
return state.versionCli;
},
telemetry: (state): ITelemetrySettings | null => {
return state.telemetry;
},
oauthCallbackUrls: (state): object => {
return state.oauthCallbackUrls;
},
n8nMetadata: (state): object => {
return state.n8nMetadata;
},
// Push Connection
pushConnectionActive: (state): boolean => {
return state.pushConnectionActive;
},
sessionId: (state): string => {
return state.sessionId;
},
// Active Workflows
getActiveWorkflows: (state): string[] => {
return state.activeWorkflows;
},
// Node-Index
getNodeIndex: (state) => (nodeName: string): number => {
return state.nodeIndex.indexOf(nodeName);
},
getNodeNameByIndex: (state) => (index: number): string | null => {
return state.nodeIndex[index];
},
getNodeViewOffsetPosition: (state): XYPosition => {
return state.nodeViewOffsetPosition;
},
isNodeViewMoveInProgress: (state): boolean => {
return state.nodeViewMoveInProgress;
},
// Selected Nodes
getSelectedNodes: (state): INodeUi[] => {
return state.selectedNodes;
},
isNodeSelected: (state) => (nodeName: string): boolean => {
let index;
for (index in state.selectedNodes) {
if (state.selectedNodes[index].name === nodeName) {
return true;
}
}
return false;
},
isActive: (state): boolean => {
return state.workflow.active;
},
allConnections: (state): IConnections => {
return state.workflow.connections;
},
outgoingConnectionsByNodeName: (state) => (nodeName: string): INodeConnections => {
if (state.workflow.connections.hasOwnProperty(nodeName)) {
return state.workflow.connections[nodeName];
}
return {};
},
allNodes: (state): INodeUi[] => {
return state.workflow.nodes;
},
nodesByName: (state: IRootState): {[name: string]: INodeUi} => {
return state.workflow.nodes.reduce((accu: {[name: string]: INodeUi}, node) => {
accu[node.name] = node;
return accu;
}, {});
},
getNodeByName: (state, getters) => (nodeName: string): INodeUi | null => {
return getters.nodesByName[nodeName] || null;
},
nodesIssuesExist: (state): boolean => {
for (const node of state.workflow.nodes) {
if (node.issues === undefined || Object.keys(node.issues).length === 0) {
continue;
}
return true;
}
return false;
},
allNodeTypes: (state): INodeTypeDescription[] => {
return state.nodeTypes;
},
nodeType: (state, getters) => (nodeType: string, typeVersion?: number): INodeTypeDescription | null => {
const foundType = state.nodeTypes.find(typeData => {
return typeData.name === nodeType && typeData.version === (typeVersion || typeData.defaultVersion || DEFAULT_NODETYPE_VERSION);
});
if (foundType === undefined) {
return null;
}
return foundType;
},
activeNode: (state, getters): INodeUi | null => {
return getters.getNodeByName(state.activeNode);
},
lastSelectedNode: (state, getters): INodeUi | null => {
return getters.getNodeByName(state.lastSelectedNode);
},
lastSelectedNodeOutputIndex: (state, getters): number | null => {
return state.lastSelectedNodeOutputIndex;
},
// Active Execution
executingNode: (state): string | null => {
return state.executingNode;
},
activeExecutionId: (state): string | null => {
return state.executionId;
},
executionWaitingForWebhook: (state): boolean => {
return state.executionWaitingForWebhook;
},
workflowName: (state): string => {
return state.workflow.name;
},
workflowId: (state): string => {
return state.workflow.id;
},
workflowSettings: (state): IWorkflowSettings => {
if (state.workflow.settings === undefined) {
return {};
}
return state.workflow.settings;
},
workflowTags: (state): string[] => {
return state.workflow.tags as string[];
},
// Workflow Result Data
getWorkflowExecution: (state): IExecutionResponse | null => {
return state.workflowExecutionData;
},
getWorkflowRunData: (state): IRunData | null => {
if (state.workflowExecutionData === null) {
return null;
}
return state.workflowExecutionData.data.resultData.runData;
},
getWorkflowResultDataByNodeName: (state, getters) => (nodeName: string): ITaskData[] | null => {
const workflowRunData = getters.getWorkflowRunData;
if (workflowRunData === null) {
return null;
}
if (!workflowRunData.hasOwnProperty(nodeName)) {
return null;
}
return workflowRunData[nodeName];
},
sidebarMenuItems: (state): IMenuItem[] => {
return state.sidebarMenuItems;
},
},
});