fix(editor): Fix new, unsaved workflow sharing (#16740)

This commit is contained in:
Csaba Tuncsik
2025-06-27 16:20:01 +02:00
committed by GitHub
parent c5ec056eb5
commit 5fe68f38df
5 changed files with 159 additions and 24 deletions

View File

@@ -1,7 +1,7 @@
<script setup lang="ts">
import { computed, watch, onMounted, ref } from 'vue';
import { useRouter, useRoute } from 'vue-router';
import { createEventBus } from '@n8n/utils/event-bus';
import Modal from './Modal.vue';
import {
EnterpriseEditionFeature,
@@ -12,7 +12,6 @@ import {
import { getResourcePermissions } from '@n8n/permissions';
import { useMessage } from '@/composables/useMessage';
import { useToast } from '@/composables/useToast';
import { nodeViewEventBus } from '@/event-bus';
import { useSettingsStore } from '@/stores/settings.store';
import { useUIStore } from '@/stores/ui.store';
import { useUsersStore } from '@/stores/users.store';
@@ -28,6 +27,7 @@ import { useRolesStore } from '@/stores/roles.store';
import { usePageRedirectionHelper } from '@/composables/usePageRedirectionHelper';
import { useI18n } from '@n8n/i18n';
import { telemetry } from '@/plugins/telemetry';
import { useWorkflowSaving } from '@/composables/useWorkflowSaving';
const props = defineProps<{
data: {
@@ -49,6 +49,9 @@ const toast = useToast();
const message = useMessage();
const pageRedirectionHelper = usePageRedirectionHelper();
const i18n = useI18n();
const router = useRouter();
const route = useRoute();
const workflowSaving = useWorkflowSaving({ router });
const workflow = ref(
data.id === PLACEHOLDER_EMPTY_WORKFLOW_ID
@@ -141,15 +144,16 @@ const onSave = async () => {
loading.value = true;
const saveWorkflowPromise = async () => {
return await new Promise<string>((resolve) => {
if (workflow.value.id === PLACEHOLDER_EMPTY_WORKFLOW_ID) {
nodeViewEventBus.emit('saveWorkflow', () => {
resolve(workflow.value.id);
});
} else {
resolve(workflow.value.id);
if (workflow.value.id === PLACEHOLDER_EMPTY_WORKFLOW_ID) {
const parentFolderId = route.query.folderId as string | undefined;
const workflowId = await workflowSaving.saveAsNewWorkflow({ parentFolderId });
if (!workflowId) {
throw new Error(i18n.baseText('workflows.shareModal.onSave.error.title'));
}
});
return workflowId;
} else {
return workflow.value.id;
}
};
try {