diff --git a/packages/editor-ui/src/composables/useToast.ts b/packages/editor-ui/src/composables/useToast.ts index f0c1b200c0..3b5256ba5c 100644 --- a/packages/editor-ui/src/composables/useToast.ts +++ b/packages/editor-ui/src/composables/useToast.ts @@ -19,17 +19,14 @@ export function useToast() { const externalHooks = useExternalHooks(); const i18n = useI18n(); - function showMessage( - messageData: Omit & { message?: string }, - track = true, - ) { + function showMessage(messageData: NotificationOptions, track = true) { messageData = { ...messageDefaults, ...messageData }; - messageData.message = messageData.message - ? sanitizeHtml(messageData.message) - : messageData.message; + messageData.message = + typeof messageData.message === 'string' + ? sanitizeHtml(messageData.message) + : messageData.message; - // @TODO Check if still working - const notification = Notification(messageData as NotificationOptions); + const notification = Notification(messageData); if (messageData.duration === 0) { stickyNotificationQueue.push(notification); @@ -49,7 +46,7 @@ export function useToast() { function showToast(config: { title: string; - message: string; + message: NotificationOptions['message']; onClick?: () => void; onClose?: () => void; duration?: number; diff --git a/packages/editor-ui/src/plugins/i18n/locales/en.json b/packages/editor-ui/src/plugins/i18n/locales/en.json index e96dfea509..7e2c183dd7 100644 --- a/packages/editor-ui/src/plugins/i18n/locales/en.json +++ b/packages/editor-ui/src/plugins/i18n/locales/en.json @@ -1884,6 +1884,7 @@ "workflowHistory.action.restore.modal.button.cancel": "Cancel", "workflowHistory.action.restore.success.title": "Successfully restored workflow version", "workflowHistory.action.clone.success.title": "Successfully cloned workflow version", + "workflowHistory.action.clone.success.message": "Open cloned workflow in a new tab", "workflows.heading": "Workflows", "workflows.add": "Add Workflow", "workflows.menu.my": "My workflows", diff --git a/packages/editor-ui/src/stores/workflowHistory.store.ts b/packages/editor-ui/src/stores/workflowHistory.store.ts index 7a488ae3ca..5fd10b7fd3 100644 --- a/packages/editor-ui/src/stores/workflowHistory.store.ts +++ b/packages/editor-ui/src/stores/workflowHistory.store.ts @@ -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 => + ): Promise => 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 => { 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 ( diff --git a/packages/editor-ui/src/views/WorkflowHistory.vue b/packages/editor-ui/src/views/WorkflowHistory.vue index 0a0a98cb37..ee1a05df2e 100644 --- a/packages/editor-ui/src/views/WorkflowHistory.vue +++ b/packages/editor-ui/src/views/WorkflowHistory.vue @@ -1,5 +1,5 @@