feat: Add workflow data reset action (#4618)

* feat: add workflow data reset action

* fix: remove console.log

* chore: fix linting issues
This commit is contained in:
Alex Grozav
2022-11-17 15:19:40 +02:00
committed by GitHub
parent f7a9ef9116
commit 0daa36c197
3 changed files with 88 additions and 37 deletions

View File

@@ -1,4 +1,11 @@
import { DEFAULT_NEW_WORKFLOW_NAME, DUPLICATE_POSTFFIX, MAX_WORKFLOW_NAME_LENGTH, PLACEHOLDER_EMPTY_WORKFLOW_ID, STORES } from "@/constants";
import {
DEFAULT_NEW_WORKFLOW_NAME,
DUPLICATE_POSTFFIX,
EnterpriseEditionFeature,
MAX_WORKFLOW_NAME_LENGTH,
PLACEHOLDER_EMPTY_WORKFLOW_ID,
STORES,
} from "@/constants";
import {
IExecutionResponse,
IExecutionsCurrentSummaryExtended,
@@ -13,34 +20,59 @@ import {
IWorkflowsMap,
WorkflowsState,
} from "@/Interface";
import { defineStore } from "pinia";
import { IConnection, IConnections, IDataObject, INode, INodeConnections, INodeCredentials, INodeCredentialsDetails, INodeExecutionData, INodeIssueData, IPinData, IRunData, ITaskData, IWorkflowSettings } from 'n8n-workflow';
import {defineStore} from "pinia";
import {
IConnection,
IConnections,
IDataObject,
INode,
INodeConnections,
INodeCredentials,
INodeCredentialsDetails,
INodeExecutionData,
INodeIssueData,
IPinData,
IRunData,
ITaskData,
IWorkflowSettings,
} from 'n8n-workflow';
import Vue from "vue";
import { useRootStore } from "./n8nRootStore";
import { getActiveWorkflows, getCurrentExecutions, getFinishedExecutions, getNewWorkflow, getWorkflows } from "@/api/workflows";
import { useUIStore } from "./ui";
import { getPairedItemsMapping } from "@/pairedItemUtils";
import { dataPinningEventBus } from "@/event-bus/data-pinning-event-bus";
import { isJsonKeyObject } from "@/utils";
import { stringSizeInBytes } from "@/components/helpers";
import { useNDVStore } from "./ndv";
import { useNodeTypesStore } from "./nodeTypes";
import {useRootStore} from "./n8nRootStore";
import {
getActiveWorkflows,
getCurrentExecutions,
getFinishedExecutions,
getNewWorkflow,
getWorkflows,
} from "@/api/workflows";
import {useUIStore} from "./ui";
import {getPairedItemsMapping} from "@/pairedItemUtils";
import {dataPinningEventBus} from "@/event-bus/data-pinning-event-bus";
import {isJsonKeyObject} from "@/utils";
import {stringSizeInBytes} from "@/components/helpers";
import {useNDVStore} from "./ndv";
import {useNodeTypesStore} from "./nodeTypes";
import {useWorkflowsEEStore} from "@/stores/workflows.ee";
import {useUsersStore} from "@/stores/users";
import {useSettingsStore} from "@/stores/settings";
const createEmptyWorkflow = (): IWorkflowDb => ({
id: PLACEHOLDER_EMPTY_WORKFLOW_ID,
name: '',
active: false,
createdAt: -1,
updatedAt: -1,
connections: {},
nodes: [],
settings: {},
tags: [],
pinData: {},
hash: '',
});
export const useWorkflowsStore = defineStore(STORES.WORKFLOWS, {
state: (): WorkflowsState => ({
workflow: {
id: PLACEHOLDER_EMPTY_WORKFLOW_ID,
name: '',
active: false,
createdAt: -1,
updatedAt: -1,
connections: {},
nodes: [],
settings: {},
tags: [],
pinData: {},
hash: '',
},
workflow: createEmptyWorkflow(),
activeWorkflows: [],
activeExecutions: [],
currentWorkflowExecutions: [],
@@ -199,6 +231,8 @@ export const useWorkflowsStore = defineStore(STORES.WORKFLOWS, {
},
async getNewWorkflowData(name?: string): Promise<INewWorkflowData> {
const workflowsEEStore = useWorkflowsEEStore();
let workflowData = {
name: '',
onboardingFlowEnabled: false,
@@ -213,9 +247,21 @@ export const useWorkflowsStore = defineStore(STORES.WORKFLOWS, {
}
this.setWorkflowName({ newName: workflowData.name, setStateDirty: false });
return workflowData;
},
resetWorkflow() {
const usersStore = useUsersStore();
const settingsStore = useSettingsStore();
this.workflow = createEmptyWorkflow();
if (settingsStore.isEnterpriseFeatureEnabled(EnterpriseEditionFeature.WorkflowSharing)) {
Vue.set(this.workflow, 'ownedBy', usersStore.currentUser);
}
},
setWorkflowId (id: string): void {
this.workflow.id = id === 'new' ? PLACEHOLDER_EMPTY_WORKFLOW_ID : id;
},