5
5
6
6
import React , { useEffect , useState } from 'react' ;
7
7
import yaml from 'js-yaml' ;
8
+ import { isEmpty , toLower } from 'lodash' ;
8
9
import {
9
10
EuiCodeBlock ,
10
11
EuiFlexGroup ,
11
12
EuiFlexItem ,
12
- EuiCompressedRadioGroup ,
13
13
EuiText ,
14
14
EuiLink ,
15
15
EuiModal ,
@@ -20,6 +20,7 @@ import {
20
20
EuiSmallButtonEmpty ,
21
21
EuiCallOut ,
22
22
EuiSpacer ,
23
+ EuiSmallButtonGroup ,
23
24
} from '@elastic/eui' ;
24
25
import {
25
26
CREATE_WORKFLOW_LINK ,
@@ -38,21 +39,10 @@ interface ExportModalProps {
38
39
}
39
40
40
41
enum EXPORT_OPTION {
41
- JSON = 'json ' ,
42
- YAML = 'yaml ' ,
42
+ JSON = 'JSON ' ,
43
+ YAML = 'YAML ' ,
43
44
}
44
45
45
- const exportOptions = [
46
- {
47
- id : EXPORT_OPTION . JSON ,
48
- label : 'JSON' ,
49
- } ,
50
- {
51
- id : EXPORT_OPTION . YAML ,
52
- label : 'YAML' ,
53
- } ,
54
- ] ;
55
-
56
46
/**
57
47
* Modal containing all of the export options
58
48
*/
@@ -75,6 +65,18 @@ export function ExportModal(props: ExportModalProps) {
75
65
}
76
66
} , [ props . workflow , selectedOption ] ) ;
77
67
68
+ // client-side file to be downloaded if the user so chooses. Generate a file
69
+ // and its corresponding URL.
70
+ const [ formattedConfigHref , setFormattedConfigHref ] = useState < string > ( '' ) ;
71
+ useEffect ( ( ) => {
72
+ if ( ! isEmpty ( formattedConfig ) ) {
73
+ const formattedConfigFile = new Blob ( [ formattedConfig ] , {
74
+ type : `text/${ toLower ( selectedOption ) } ` ,
75
+ } ) ;
76
+ setFormattedConfigHref ( URL . createObjectURL ( formattedConfigFile ) ) ;
77
+ }
78
+ } , [ formattedConfig ] ) ;
79
+
78
80
return (
79
81
< EuiModal
80
82
maxWidth = { false }
@@ -115,19 +117,45 @@ export function ExportModal(props: ExportModalProps) {
115
117
> { `Note: certain resource IDs in the template, such as model IDs, may be cluster-specific and not work out-of-the-box
116
118
in other environments. Ensure these values are updated before attempting to provision in other environments.` } </ EuiText >
117
119
</ EuiFlexItem >
118
- < EuiFlexItem grow = { false } >
119
- < EuiCompressedRadioGroup
120
- options = { exportOptions }
121
- idSelected = { selectedOption }
122
- onChange = { ( option ) => {
123
- setSelectedOption ( option as EXPORT_OPTION ) ;
124
- } }
125
- />
120
+ < EuiFlexItem >
121
+ < EuiFlexGroup direction = "row" justifyContent = "spaceBetween" >
122
+ < EuiFlexItem grow = { false } >
123
+ < EuiSmallButtonGroup
124
+ legend = "Choose how to view your workflow"
125
+ options = { [
126
+ {
127
+ id : EXPORT_OPTION . JSON ,
128
+ label : EXPORT_OPTION . JSON ,
129
+ } ,
130
+ {
131
+ id : EXPORT_OPTION . YAML ,
132
+ label : EXPORT_OPTION . YAML ,
133
+ } ,
134
+ ] }
135
+ idSelected = { selectedOption }
136
+ onChange = { ( id ) => setSelectedOption ( id as EXPORT_OPTION ) }
137
+ data-testid = "exportDataToggleButtonGroup"
138
+ />
139
+ </ EuiFlexItem >
140
+ < EuiFlexItem grow = { false } >
141
+ < EuiSmallButtonEmpty
142
+ iconType = "download"
143
+ iconSide = "right"
144
+ href = { formattedConfigHref }
145
+ download = { `${ props . workflow ?. name } .${ toLower (
146
+ selectedOption
147
+ ) } `}
148
+ onClick = { ( ) => { } }
149
+ >
150
+ { `Download ${ selectedOption } file` }
151
+ </ EuiSmallButtonEmpty >
152
+ </ EuiFlexItem >
153
+ </ EuiFlexGroup >
126
154
</ EuiFlexItem >
127
155
{ props . workflow !== undefined && (
128
156
< EuiFlexItem grow = { false } >
129
157
< EuiCodeBlock
130
- language = { selectedOption }
158
+ language = { toLower ( selectedOption ) }
131
159
fontSize = "m"
132
160
isCopyable = { true }
133
161
>
0 commit comments