mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-21 11:49:59 +00:00
feat(editor): Add option to create sub workflow from workflows list in Execute Workflow node (#11706)
This commit is contained in:
@@ -1,11 +1,17 @@
|
||||
<script setup lang="ts">
|
||||
import { useLoadingService } from '@/composables/useLoadingService';
|
||||
import { useI18n } from '@/composables/useI18n';
|
||||
import { VIEWS } from '@/constants';
|
||||
import {
|
||||
NEW_SAMPLE_WORKFLOW_CREATED_CHANNEL,
|
||||
SAMPLE_SUBWORKFLOW_WORKFLOW,
|
||||
SAMPLE_SUBWORKFLOW_WORKFLOW_ID,
|
||||
VIEWS,
|
||||
} from '@/constants';
|
||||
import { useTemplatesStore } from '@/stores/templates.store';
|
||||
import { useWorkflowsStore } from '@/stores/workflows.store';
|
||||
import { onMounted } from 'vue';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import type { IWorkflowDataCreate } from '@/Interface';
|
||||
|
||||
const loadingService = useLoadingService();
|
||||
const templateStore = useTemplatesStore();
|
||||
@@ -15,6 +21,11 @@ const route = useRoute();
|
||||
const i18n = useI18n();
|
||||
|
||||
const openWorkflowTemplate = async (templateId: string) => {
|
||||
if (templateId === SAMPLE_SUBWORKFLOW_WORKFLOW_ID) {
|
||||
await openSampleSubworkflow();
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
loadingService.startLoading();
|
||||
const template = await templateStore.getFixedWorkflowTemplate(templateId);
|
||||
@@ -52,6 +63,42 @@ const openWorkflowTemplate = async (templateId: string) => {
|
||||
}
|
||||
};
|
||||
|
||||
const openSampleSubworkflow = async () => {
|
||||
try {
|
||||
loadingService.startLoading();
|
||||
|
||||
const projectId = route.query?.projectId;
|
||||
|
||||
const sampleSubWorkflows = Number(route.query?.sampleSubWorkflows ?? 0);
|
||||
|
||||
const workflowName = `${SAMPLE_SUBWORKFLOW_WORKFLOW.name} ${sampleSubWorkflows + 1}`;
|
||||
|
||||
const workflow: IWorkflowDataCreate = {
|
||||
...SAMPLE_SUBWORKFLOW_WORKFLOW,
|
||||
name: workflowName,
|
||||
};
|
||||
|
||||
if (projectId) {
|
||||
workflow.projectId = projectId as string;
|
||||
}
|
||||
|
||||
const newWorkflow = await workflowsStore.createNewWorkflow(workflow);
|
||||
|
||||
const sampleSubworkflowChannel = new BroadcastChannel(NEW_SAMPLE_WORKFLOW_CREATED_CHANNEL);
|
||||
|
||||
sampleSubworkflowChannel.postMessage({ workflowId: newWorkflow.id });
|
||||
|
||||
await router.replace({
|
||||
name: VIEWS.WORKFLOW,
|
||||
params: { name: newWorkflow.id },
|
||||
});
|
||||
loadingService.stopLoading();
|
||||
} catch (e) {
|
||||
await router.replace({ name: VIEWS.NEW_WORKFLOW });
|
||||
loadingService.stopLoading();
|
||||
}
|
||||
};
|
||||
|
||||
onMounted(async () => {
|
||||
const templateId = route.params.id;
|
||||
if (!templateId || typeof templateId !== 'string') {
|
||||
|
||||
Reference in New Issue
Block a user