feat(editor): Workflow history [WIP]- Add restore and clone into new workflow actions (no-changelog) (#7359)
This commit is contained in:
@@ -36,6 +36,7 @@ import {
|
||||
SOURCE_CONTROL_PULL_MODAL_KEY,
|
||||
DEBUG_PAYWALL_MODAL_KEY,
|
||||
N8N_PRICING_PAGE_URL,
|
||||
WORKFLOW_HISTORY_VERSION_RESTORE,
|
||||
} from '@/constants';
|
||||
import type {
|
||||
CloudUpdateLinkSourceType,
|
||||
@@ -157,6 +158,9 @@ export const useUIStore = defineStore(STORES.UI, {
|
||||
[DEBUG_PAYWALL_MODAL_KEY]: {
|
||||
open: false,
|
||||
},
|
||||
[WORKFLOW_HISTORY_VERSION_RESTORE]: {
|
||||
open: false,
|
||||
},
|
||||
},
|
||||
modalStack: [],
|
||||
sidebarMenuCollapsed: true,
|
||||
|
||||
@@ -1,17 +1,22 @@
|
||||
import { computed } from 'vue';
|
||||
import { defineStore } from 'pinia';
|
||||
import * as whApi from '@/api/workflowHistory';
|
||||
import { useRootStore } from '@/stores/n8nRoot.store';
|
||||
import { useSettingsStore } from '@/stores/settings.store';
|
||||
import { saveAs } from 'file-saver';
|
||||
import type { IWorkflowDataUpdate } from '@/Interface';
|
||||
import type {
|
||||
WorkflowHistory,
|
||||
WorkflowVersion,
|
||||
WorkflowHistoryRequestParams,
|
||||
WorkflowVersionId,
|
||||
} from '@/types/workflowHistory';
|
||||
import * as whApi from '@/api/workflowHistory';
|
||||
import { useRootStore } from '@/stores/n8nRoot.store';
|
||||
import { useSettingsStore } from '@/stores/settings.store';
|
||||
import { useWorkflowsStore } from '@/stores/workflows.store';
|
||||
|
||||
export const useWorkflowHistoryStore = defineStore('workflowHistory', () => {
|
||||
const rootStore = useRootStore();
|
||||
const settingsStore = useSettingsStore();
|
||||
const workflowsStore = useWorkflowsStore();
|
||||
|
||||
const licensePruneTime = computed(() => settingsStore.settings.workflowHistory.licensePruneTime);
|
||||
const pruneTime = computed(() => settingsStore.settings.workflowHistory.pruneTime);
|
||||
@@ -40,9 +45,65 @@ export const useWorkflowHistoryStore = defineStore('workflowHistory', () => {
|
||||
return null;
|
||||
});
|
||||
|
||||
const downloadVersion = async (workflowId: string, workflowVersionId: WorkflowVersionId) => {
|
||||
const [workflow, workflowVersion] = await Promise.all([
|
||||
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}-${workflowVersionId}.json`);
|
||||
}
|
||||
};
|
||||
|
||||
const cloneIntoNewWorkflow = async (
|
||||
workflowId: string,
|
||||
workflowVersionId: string,
|
||||
data: { formattedCreatedAt: string },
|
||||
) => {
|
||||
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 restoreWorkflow = async (
|
||||
workflowId: string,
|
||||
workflowVersionId: string,
|
||||
shouldDeactivate: boolean,
|
||||
) => {
|
||||
const workflowVersion = await getWorkflowVersion(workflowId, workflowVersionId);
|
||||
if (workflowVersion?.nodes && workflowVersion?.connections) {
|
||||
const { connections, nodes } = workflowVersion;
|
||||
const updateData: IWorkflowDataUpdate = { connections, nodes };
|
||||
|
||||
if (shouldDeactivate) {
|
||||
updateData.active = false;
|
||||
}
|
||||
|
||||
await workflowsStore.updateWorkflow(workflowId, updateData, true);
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
getWorkflowHistory,
|
||||
getWorkflowVersion,
|
||||
downloadVersion,
|
||||
cloneIntoNewWorkflow,
|
||||
restoreWorkflow,
|
||||
evaluatedPruneTime,
|
||||
shouldUpgrade,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user