feat(editor): Workflow history [WIP] - Add cloned workflow link to success toast message (no-changelog) (#7405)

This commit is contained in:
Csaba Tuncsik
2023-10-19 14:02:59 +02:00
committed by GitHub
parent 55c6a1b0d3
commit 82129694c6
5 changed files with 109 additions and 57 deletions

View File

@@ -1,7 +1,7 @@
import { computed } from 'vue';
import { defineStore } from 'pinia';
import { saveAs } from 'file-saver';
import type { IWorkflowDataUpdate } from '@/Interface';
import type { IWorkflowDataUpdate, IWorkflowDb } from '@/Interface';
import type {
WorkflowHistory,
WorkflowVersion,
@@ -12,6 +12,7 @@ import * as whApi from '@/api/workflowHistory';
import { useRootStore } from '@/stores/n8nRoot.store';
import { useSettingsStore } from '@/stores/settings.store';
import { useWorkflowsStore } from '@/stores/workflows.store';
import { getNewWorkflow } from '@/api/workflows';
export const useWorkflowHistoryStore = defineStore('workflowHistory', () => {
const rootStore = useRootStore();
@@ -34,7 +35,7 @@ export const useWorkflowHistoryStore = defineStore('workflowHistory', () => {
const getWorkflowVersion = async (
workflowId: string,
versionId: string,
): Promise<WorkflowVersion | null> =>
): Promise<WorkflowVersion> =>
whApi.getWorkflowVersion(rootStore.getRestApiContext, workflowId, versionId);
const downloadVersion = async (
@@ -46,34 +47,34 @@ export const useWorkflowHistoryStore = defineStore('workflowHistory', () => {
workflowsStore.fetchWorkflow(workflowId),
getWorkflowVersion(workflowId, workflowVersionId),
]);
if (workflow && workflowVersion) {
const { connections, nodes } = workflowVersion;
const blob = new Blob([JSON.stringify({ ...workflow, nodes, connections }, null, 2)], {
type: 'application/json;charset=utf-8',
});
saveAs(blob, `${workflow.name}(${data.formattedCreatedAt}).json`);
}
const { connections, nodes } = workflowVersion;
const blob = new Blob([JSON.stringify({ ...workflow, nodes, connections }, null, 2)], {
type: 'application/json;charset=utf-8',
});
saveAs(blob, `${workflow.name}(${data.formattedCreatedAt}).json`);
};
const cloneIntoNewWorkflow = async (
workflowId: string,
workflowVersionId: string,
data: { formattedCreatedAt: string },
) => {
): Promise<IWorkflowDb> => {
const [workflow, workflowVersion] = await Promise.all([
workflowsStore.fetchWorkflow(workflowId),
getWorkflowVersion(workflowId, workflowVersionId),
]);
if (workflow && workflowVersion) {
const { connections, nodes } = workflowVersion;
const { name } = workflow;
const newWorkflowData: IWorkflowDataUpdate = {
nodes,
connections,
name: `${name} (${data.formattedCreatedAt})`,
};
await workflowsStore.createNewWorkflow(newWorkflowData);
}
const { connections, nodes } = workflowVersion;
const { name } = workflow;
const newWorkflow = await getNewWorkflow(
rootStore.getRestApiContext,
`${name} (${data.formattedCreatedAt})`,
);
const newWorkflowData: IWorkflowDataUpdate = {
nodes,
connections,
name: newWorkflow.name,
};
return workflowsStore.createNewWorkflow(newWorkflowData);
};
const restoreWorkflow = async (