1+ "use client"
2+
3+ import React from "react"
4+ import { Panel } from "@xyflow/react"
5+ import { Flow } from "@code0-tech/sagittarius-graphql-types"
6+ import { useService , useStore } from "../../../utils"
7+ import { DFlowReactiveService } from "../DFlow.service"
8+ import { Button } from "../../button/Button"
9+
10+ export interface DFlowExportProps {
11+ flowId : Flow [ 'id' ]
12+ }
13+
14+ export const DFlowExport : React . FC < DFlowExportProps > = ( props ) => {
15+
16+ const { flowId} = props
17+
18+ const flowService = useService ( DFlowReactiveService )
19+ const flowStore = useStore ( DFlowReactiveService )
20+ const flow = React . useMemo ( ( ) => flowService . getById ( flowId ) , [ flowStore , flowId ] )
21+
22+ const handleExport = React . useCallback ( ( ) => {
23+ if ( ! flow ) return
24+
25+ // Hole JSON-Daten
26+ const data = flow . jsonInput ?.( )
27+ if ( ! data ) return
28+
29+ const json =
30+ typeof data === "string" ? data : JSON . stringify ( data , null , 2 )
31+
32+ // Blob + Download-Link
33+ const blob = new Blob ( [ json ] , { type : "application/json" } )
34+ const url = URL . createObjectURL ( blob )
35+
36+ const a = document . createElement ( "a" )
37+ a . href = url
38+ a . download = `flow-${ flow . name } .json`
39+ document . body . appendChild ( a )
40+ a . click ( )
41+ a . remove ( )
42+
43+ URL . revokeObjectURL ( url )
44+ } , [ flow ] )
45+
46+ return < Panel position = "top-right" >
47+ < Button paddingSize = { "xxs" } onClick = { handleExport } >
48+ Export flow
49+ </ Button >
50+ </ Panel >
51+ }
0 commit comments