From fd0492bccd63116b1581e60f93f09b441e174cdf Mon Sep 17 00:00:00 2001 From: Csaba Tuncsik Date: Wed, 11 Oct 2023 14:26:07 +0200 Subject: [PATCH 1/3] fix(editor): Add cloned workflow link to success toast message --- .../editor-ui/src/composables/useToast.ts | 17 ++-- .../src/plugins/i18n/locales/en.json | 1 + .../src/stores/workflowHistory.store.ts | 36 ++++----- .../editor-ui/src/views/WorkflowHistory.vue | 79 +++++++++++++------ 4 files changed, 79 insertions(+), 54 deletions(-) diff --git a/packages/editor-ui/src/composables/useToast.ts b/packages/editor-ui/src/composables/useToast.ts index f0c1b200c0992..3b5256ba5cec0 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 3d4739bd728a2..6924c37b1bccd 100644 --- a/packages/editor-ui/src/plugins/i18n/locales/en.json +++ b/packages/editor-ui/src/plugins/i18n/locales/en.json @@ -1873,6 +1873,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 7a488ae3caf13..614ede34c86ff 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, @@ -34,7 +34,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 +46,30 @@ 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 newWorkflowData: IWorkflowDataUpdate = { + nodes, + connections, + name: `${name} (${data.formattedCreatedAt})`, + }; + 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 0a0a98cb37697..ee1a05df2ec23 100644 --- a/packages/editor-ui/src/views/WorkflowHistory.vue +++ b/packages/editor-ui/src/views/WorkflowHistory.vue @@ -1,5 +1,5 @@