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

feat: Add workflow data reset action #4618

Merged
merged 3 commits into from
Nov 17, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions packages/editor-ui/src/stores/workflows.ee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import {useSettingsStore} from "@/stores/settings";
import {defineStore} from "pinia";
import {useWorkflowsStore} from "@/stores/workflows";

// @TODO Move to workflows store as part of workflows store refactoring
//
export const useWorkflowsEEStore = defineStore(STORES.WORKFLOWS_EE, {
state() { return {}; },
actions: {
Expand Down
96 changes: 71 additions & 25 deletions packages/editor-ui/src/stores/workflows.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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: [],
Expand Down Expand Up @@ -199,6 +231,8 @@ export const useWorkflowsStore = defineStore(STORES.WORKFLOWS, {
},

async getNewWorkflowData(name?: string): Promise<INewWorkflowData> {
const workflowsEEStore = useWorkflowsEEStore();

let workflowData = {
name: '',
onboardingFlowEnabled: false,
Expand All @@ -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;
},
Expand Down
27 changes: 17 additions & 10 deletions packages/editor-ui/src/views/NodeView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,6 @@ export default mixins(
this.workflowsStore.setWorkflowPinData(data.pinData || {});
this.workflowsStore.setWorkflowHash(data.hash);

// @TODO
this.workflowsStore.addWorkflow({
id: data.id,
name: data.name,
Expand All @@ -853,16 +852,23 @@ export default mixins(
updatedAt: data.updatedAt,
nodes: data.nodes,
connections: data.connections,
});
this.workflowsEEStore.setWorkflowOwnedBy({
workflowId: data.id,
ownedBy: data.ownedBy,
});
this.workflowsEEStore.setWorkflowSharedWith({
workflowId: data.id,
sharedWith: data.sharedWith,
hash: '',
});

if (data.ownedBy) {
this.workflowsEEStore.setWorkflowOwnedBy({
workflowId: data.id,
ownedBy: data.ownedBy,
});
}

if (data.sharedWith) {
this.workflowsEEStore.setWorkflowSharedWith({
workflowId: data.id,
sharedWith: data.sharedWith,
});
}

if (data.usedCredentials) {
this.credentialsStore.addCredentials(data.usedCredentials);
}
Expand Down Expand Up @@ -3084,6 +3090,8 @@ export default mixins(
return Promise.resolve(data);
},
resetWorkspace() {
this.workflowsStore.resetWorkflow();

// Reset nodes
this.deleteEveryEndpoint();

Expand All @@ -3104,7 +3112,6 @@ export default mixins(
this.workflowsStore.resetAllNodesIssues();
// vm.$forceUpdate();

this.workflowsStore.$patch({ workflow: {} });
this.workflowsStore.setActive(false);
this.workflowsStore.setWorkflowId(PLACEHOLDER_EMPTY_WORKFLOW_ID);
this.workflowsStore.setWorkflowName({ newName: '', setStateDirty: false });
Expand Down