diff --git a/src/designer/elsa-workflows-designer/src/components.d.ts b/src/designer/elsa-workflows-designer/src/components.d.ts index f78902614..d8cb6e370 100644 --- a/src/designer/elsa-workflows-designer/src/components.d.ts +++ b/src/designer/elsa-workflows-designer/src/components.d.ts @@ -20,6 +20,7 @@ import { PagerData } from "./components/shared/pager/pager"; import { PanelPosition, PanelStateChangedArgs } from "./components/designer/panel/models"; import { WorkflowUpdatedArgs } from "./components/designer/workflow-editor/workflow-editor"; import { ActivityDriverRegistry } from "./services"; +import { Flowchart } from "./components/activities/flowchart/models"; import { WorkflowPropsUpdatedArgs } from "./components/designer/workflow-properties-editor/workflow-properties-editor"; import { PublishClickedArgs } from "./components/toolbar/workflow-publish-button/workflow-publish-button"; export namespace Components { @@ -170,6 +171,7 @@ export namespace Components { "importWorkflow": (workflow: WorkflowDefinition, workflowInstance?: WorkflowInstance) => Promise; "importWorkflowMetadata": (workflow: WorkflowDefinition) => Promise; "monacoLibPath": string; + "newWorkflow": () => Promise; "registerActivityDrivers": (register: (registry: ActivityDriverRegistry) => void) => Promise; } interface ElsaWorkflowInstanceBrowser { diff --git a/src/designer/elsa-workflows-designer/src/components/designer/workflow-editor/workflow-editor.tsx b/src/designer/elsa-workflows-designer/src/components/designer/workflow-editor/workflow-editor.tsx index d41570112..cc8aa360d 100644 --- a/src/designer/elsa-workflows-designer/src/components/designer/workflow-editor/workflow-editor.tsx +++ b/src/designer/elsa-workflows-designer/src/components/designer/workflow-editor/workflow-editor.tsx @@ -24,6 +24,7 @@ import {ActivityDriverRegistry, EventBus} from '../../../services'; import {WorkflowPropsUpdatedArgs} from "../workflow-properties-editor/workflow-properties-editor"; import {MonacoEditorSettings} from "../../../services/monaco-editor-settings"; import {PluginRegistry} from "../../../services/plugin-registry"; +import {Flowchart} from "../../activities/flowchart/models"; export interface WorkflowUpdatedArgs { workflow: WorkflowDefinition; @@ -138,6 +139,31 @@ export class WorkflowEditor { this.workflowDefinition = workflow; } + @Method() + public async newWorkflow() { + const flowchart = { + typeName: 'Elsa.Flowchart', + activities: [], + connections: [], + id: uuid(), + metadata: {}, + applicationProperties: {}, + variables: [] + } as Flowchart; + + const workflowDefinition: WorkflowDefinition = { + root: flowchart, + id: uuid(), + definitionId: uuid(), + version: 1, + isLatest: true, + isPublished: false, + materializerName: 'Json' + } + + await this.importWorkflow(workflowDefinition); + } + public render() { const tunnelState: WorkflowDesignerState = { workflow: this.workflowDefinition, diff --git a/src/designer/elsa-workflows-designer/src/components/shell/studio/studio.tsx b/src/designer/elsa-workflows-designer/src/components/shell/studio/studio.tsx index e2f546cfa..0005bbac7 100644 --- a/src/designer/elsa-workflows-designer/src/components/shell/studio/studio.tsx +++ b/src/designer/elsa-workflows-designer/src/components/shell/studio/studio.tsx @@ -13,6 +13,7 @@ import {WorkflowUpdatedArgs} from '../../designer/workflow-editor/workflow-edito import {PublishClickedArgs} from "../../toolbar/workflow-publish-button/workflow-publish-button"; import {MonacoEditorSettings} from "../../../services/monaco-editor-settings"; import {downloadFromBlob, getVersionOptionsString} from "../../../utils"; +import {uuid} from "@antv/x6/lib/util/string/uuid"; @Component({ tag: 'elsa-studio' @@ -106,13 +107,7 @@ export class Studio { if (!workflowEditorElement) return; - const request: SaveWorkflowDefinitionRequest = { - definitionId: "", - publish: false - }; - - const updatedWorkflow = await this.elsaClient.workflowDefinitions.post(request); - await this.workflowEditorElement.importWorkflowMetadata(updatedWorkflow); + await this.workflowEditorElement.newWorkflow(); } @Listen('exportClicked')